in the educational Codeforces Round 53 , problem B (1073B) my solution gives TLE ,but I don't think it should. My submission is : http://codeforces.me/contest/1073/submission/44858358 can someone suggest the bugs in my code ,if any ?
| # | User | Rating |
|---|---|---|
| 1 | Benq | 3676 |
| 2 | Kevin114514 | 3659 |
| 3 | jiangly | 3640 |
| 4 | turmax | 3450 |
| 5 | tourist | 3382 |
| 6 | strapple | 3360 |
| 7 | Um_nik | 3354 |
| 8 | squareOf105 | 3348 |
| 9 | maroonrk | 3312 |
| 10 | idontwannadothis…e | 3191 |
| # | User | Contrib. |
|---|---|---|
| 1 | Qingyu | 155 |
| 2 | nik_exists | 151 |
| 3 | maspy | 149 |
| 4 | AmShZ | 145 |
| 5 | Um_nik | 143 |
| 6 | Errichto | 139 |
| 7 | BledDest | 136 |
| 8 | adamant | 134 |
| 9 | maroonrk | 132 |
| 10 | cry | 130 |
in the educational Codeforces Round 53 , problem B (1073B) my solution gives TLE ,but I don't think it should. My submission is : http://codeforces.me/contest/1073/submission/44858358 can someone suggest the bugs in my code ,if any ?
| Name |
|---|



Try adding this line in the beginning of the main function: ios_base::sync_with_stdio(false);
Yes , it worked . Thanks for the reminder . Usually I use fast io but on codeforces ,it didn't seem necessary . Still, I am astonished how slow cin ,cout actually is. Thank you again.
One way to speed up your program and get accepted even without using ios_base::sync_with_stdio(false); is to just do all input reading in one go.
With ios_base::sync_with_stdio(false); 748 ms
Without ios_base::sync_with_stdio(false); and reading all input in one go: 514 ms
With ios_base::sync_with_stdio(false); and reading all input in one go: 124 ms
I didnt realize it would be this slow. Thanks a lot .
first of all your code is not in O(n) but in expected O(n) wich may or maybe not be a huge difference since there could be hash collision test... (but i dont know)
and second why using a hashmap at all when you know that the input is a permutation? you can just use an array?
and another issue is reading the input just partly... this seems to be quite slow: https://codeforces.me/contest/1073/submission/44907426
I even used an array instead of hashmap. Still ,I was getting tle. Now I know where I slowed things down, I actually used a global array(size 2e5+5) for hashing . The memset must have slowed things down . Thanks for the vector illustration .