# | User | Rating |
---|---|---|
1 | tourist | 3985 |
2 | jiangly | 3814 |
3 | jqdai0815 | 3682 |
4 | Benq | 3529 |
5 | orzdevinwang | 3526 |
6 | ksun48 | 3517 |
7 | Radewoosh | 3410 |
8 | hos.lyric | 3399 |
9 | ecnerwala | 3392 |
9 | Um_nik | 3392 |
# | User | Contrib. |
---|---|---|
1 | cry | 169 |
2 | maomao90 | 162 |
2 | Um_nik | 162 |
4 | atcoder_official | 161 |
5 | djm03178 | 158 |
6 | -is-this-fft- | 157 |
7 | adamant | 155 |
8 | awoo | 154 |
8 | Dominater069 | 154 |
10 | luogu_official | 150 |
Name |
---|
when there are large input or output put these 2 lines at the start of your main : ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
they will fast input output , also use '\n' or "\n" instead of endl
cout.tie(0)
does nothing. Onlycin.tie(0)
is necessary.so after u do these two optimization , still TLE (time limit .... )
what u do that u take each value from a or b and count the mx subarray in a , b : so for 2*n values u iterate over a , b so your time complexity( search about it if u don't know it) is O ( n * n ) which is large enough to get TLE
but what if we preprocess the mxa[elemnt] >> max subarray that contains only elemnt , mxb[elemnt] so you won'y need the functions that takes n instruction to answer fn(a,ele) , fn(b,ele)
so know we need to think how to build mxa[ele] ... don't read this untill u try to find out how >> u can iterate over a one time with cnt = 0 : a[i]!=a[i-1] >> cnt=1 >> u start a new subarray a[i]==a[i-1] >> cnt++ mxa[a[i]] = max(mxa[a[i]] , cnt) >> u don't need to wait untill subarray is closed
https://mirror.codeforces.com/contest/1831/submission/262226998
thanks