Блог пользователя YocyCraft

Автор YocyCraft, история, 23 месяца назад, По-английски

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?

  • Проголосовать: нравится
  • +15
  • Проголосовать: не нравится

»
23 месяца назад, # |
Rev. 3   Проголосовать: нравится +13 Проголосовать: не нравится

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.

»
23 месяца назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

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

»
23 месяца назад, # |
  Проголосовать: нравится +1 Проголосовать: не нравится

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.

  • »
    »
    23 месяца назад, # ^ |
      Проголосовать: нравится +3 Проголосовать: не нравится

    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.