Solution should be faster due to lesser amount of operations but gives TLE?

Revision en1, by wck_iipi, 2025-02-02 23:32:36

I was doing the following question: https://codeforces.me/contest/2044/problem/F

Upon doing this question, I used a method that gives the solution in O(nq) time (about 2 * 10^5 * 5 * 10^4 = 10^10 operations). Code is as follows:

https://codeforces.me/contest/2044/submission/304178376

Spoiler

However, the official solution is in O(n^2) time, which is about (4 * 10^10 operations). https://codeforces.me/blog/entry/137306

Spoiler

My solution, however gives TLE. Why is my solution giving TLE but official is not even though operations are lower?

Tags online judge, time limit exceeded, speed, array

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en1 English wck_iipi 2025-02-02 23:32:36 8411 Initial revision (published)