Getting TLE inserting elements in set

Revision en2, by Pieck, 2022-04-03 13:22:16

CLOSED

Can someone please explain me why this piece of code is taking around 25 secs to run, though the complexity is O(N^2log(N)) where N<=5000.

int n = 5000;
for(int i=0; i<n; i++) {
    set<int> s;
    for(int j=n; j>=1; j--) s.insert(j);
}
Tags set, time complexity

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en2 English Pieck 2022-04-03 13:22:16 14 Tiny change: should've been closed a while back, but anyways
en1 English Pieck 2021-10-02 13:02:19 302 Initial revision (published)