Пожалуйста, прочтите новое правило об ограничении использования AI-инструментов. ×

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

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

Here is the problem: https://codeforces.me/contest/1980/problem/C and here is my submission: https://codeforces.me/contest/1980/submission/264001404 What did I do wrong?

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

»
4 месяца назад, # |
Rev. 3   Проголосовать: нравится 0 Проголосовать: не нравится
The time complexity of your code is O(t*(nlogn + m*logm*logm)) (since every map access cost around O(logn) complexity).
Particularly this part of your code causes the logarithmic factor to be quadratic.
So, when m tends to 2*10^5. your code performs around 5.6*10^6 operations per second and since, the time limit is 2s, your code just barely TLEs in this case.
  • »
    »
    4 месяца назад, # ^ |
      Проголосовать: нравится 0 Проголосовать: не нравится

    Isn't that highlighted part of code 3*log(m), why are we multiplying the logarithmic operations?

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

    5.6*10^7, actually. 5.6*10^6 should almost never TLE, but anything times 10^7 can TLE easily with constant factor.

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

You are using the map's read operation thrice in a loop which goes till M. Then you are using 2 map read operations in a loop which goes till N. Then you have another loop with NLogN complexity. So O(3NLogN + 3MLogM), for the N=M=2*10^5. You are doing close to 2.2 *10^7 operations, which might cause TLE.

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

I submitted your code but with only two different lines , defining endl to be ”\n" , and using the fastIO macro , and it passed Here's the submission 264177806

In general avoid using endl because it does flushing to the output stream which can cause TLE

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

This works in two simple ways.

  1. Using FastIO. 2.Removing unused maps.

Thank you guys for responding.