Strange problems about C++ map in 1771F

Правка en2, от sjc061031, 2022-12-12 11:01:23

My submission 184727292 in contest got Time Limit Exceeded on test 30.

When I submit this solution in C++14 184832244 , it passes in 592ms.

Then I change the map into vector 184832165 , and it passes in 296ms.

So it seems that the map runs too slow, and in test 30, $$$N=23355$$$, which means there are only $$$7e4$$$ operations of map, but strangely it costs more than $$$1s$$$.

Map should run in exactly $$$O(nlogn)$$$ , so what could possibly be the problem?

UPD: Thanks to beep_boop and Perpetually_Purple , a similar problem occurred in this blog.

The solution 184859925 is to read all the elements first then add them to the map.

I still have no idea why map behaves so strange in this case. :(

Теги map, c++, time limit exceeded

История

 
 
 
 
Правки
 
 
  Rev. Язык Кто Когда Δ Комментарий
en2 Английский sjc061031 2022-12-12 11:01:23 346 Tiny change: 'ry/99038). The soluti' -> 'ry/99038).\n\nThe soluti'
en1 Английский sjc061031 2022-12-12 04:50:16 537 Initial revision (published)