YocyCraft's blog

By YocyCraft, history, 16 months ago, In English

In 1718C - Tonya and Burenka-179 I implemented a solution with intended complexity (which was O(n*log(n)*PrimeFactorCount(n))), which need a multiset to update the possible answer between queries, and answer the max element of the multiset for each query. But since there's no multiset in java, I had to simulate a multiset by a TreeMap, which caused TLE (my submission:188008030)

I looked at other java solution for this problem and no one got AC. Is this problem unsolvable for java or there's better implementation for multiset?

  • Vote: I like it
  • +15
  • Vote: I do not like it

| Write comment?
»
16 months ago, # |
Rev. 3   Vote: I like it +13 Vote: I do not like it

Update: I rewrote my code and implemented the same algorithm using array, without HashMap and TreeMap. Now I've got AC and become the first who solved this problem in java. My new submission:188028411

Perhaps the constant factor of HashMap, TreeMap, ArrayList... in java is too large for auto-(un)boxing. It's better to avoid use generics for primitive types if possible.

»
16 months ago, # |
  Vote: I like it 0 Vote: I do not like it

Auto comment: topic has been updated by YocyCraft (previous revision, new revision, compare).

»
16 months ago, # |
  Vote: I like it +1 Vote: I do not like it

It's frustrating to come up with the correct idea, implement the solution with intended time complexity, and get TLE for large time constant factor caused by the design fault of the programming language. In such case I must optimize the algorithm further than intended,and focus on every details which may increase the time cost.

  • »
    »
    16 months ago, # ^ |
      Vote: I like it +3 Vote: I do not like it

    In this case it's not only because of the language. I've gotten TLE using C++ for using map instead of vector + sort + binary search a couple of times, including possibly in ICPC WF.