#include "sequence.h"
#include "bits/stdc++.h"
using namespace std;
#ifndef EVAL
#include "grader.cpp"
#endif
#define ar array
typedef long long ll;
//~ #define int ll
const int INF = 1e9;
struct ST{
vector<int> min, max, p;
int N;
ST(){
N = 5e5 + 5;
min.resize(N << 2);
max.resize(N << 2);
p.resize(N << 2);
}
ST(int N): N(N) {
min.resize(N << 2);
max.resize(N << 2);
p.resize(N << 2);
}
void push(int x, int lx, int rx){
if(lx == rx) return;
min[x << 1] += p[x], max[x << 1] += p[x], p[x << 1] += p[x];
min[x << 1 | 1] += p[x], max[x << 1 | 1] += p[x], p[x << 1 | 1] += p[x];
p[x] = 0;
}
void add(int l, int r, int v, int lx, int rx, int x){
if(lx > r || rx < l) return;
if(lx >= l && rx <= r){
min[x] += v, max[x] += v, p[x] += v;
return;
}
int m = (lx + rx) >> 1;
push(x, lx, rx);
add(l, r, v, lx, m, x << 1), add(l, r, v, m + 1, rx, x << 1 | 1);
min[x] = ::min(min[x << 1], min[x << 1 | 1]);
max[x] = ::max(max[x << 1], max[x << 1 | 1]);
}
void add(int l, int r, int v){
add(l, r, v, 0, N, 1);
}
int Max(int l, int r, int lx, int rx, int x){
if(lx > r || rx < l) return -INF;
if(lx >= l && rx <= r) return max[x];
int m = (lx + rx) >> 1;
push(x, lx, rx);
return ::max(Max(l, r, lx, m, x << 1), Max(l, r, m + 1, rx, x << 1 | 1));
}
int Max(int l, int r){
return Max(l, r, 0, N, 1);
}
int Min(int l, int r, int lx, int rx, int x){
if(lx > r || rx < l) return INF;
if(lx >= l && rx <= r) return min[x];
int m = (lx + rx) >> 1;
push(x, lx, rx);
return ::min(Min(l, r, lx, m, x << 1), Min(l, r, m + 1, rx, x << 1 | 1));
}
int Min(int l, int r){
return Min(l, r, 0, N, 1);
}
};
int sequence(int n, vector<int> a){
a.insert(a.begin(), 0);
ST A(n), B(n);
vector<int> p(n);
iota(p.begin(), p.end(), 1);
sort(p.begin(), p.end(), [&](int i, int j){
if(a[i] != a[j]) return a[i] < a[j];
return i < j;
});
for(int i=1;i<=n;i++){
B.add(i, i, i);
A.add(i, i, -i);
}
int res = 0;
for(int i=0,j=0;i<n;){
vector<int> pos;
while(j < n && a[p[i]] == a[p[j]]){
pos.push_back(p[j]);
A.add(p[j], n, 2);
j++;
}
for(int k=0;k<(int)pos.size();k++){
int MxA = A.Max(pos[k], n), MxB = B.Max(pos[k], n);
int l = 0, r = k;
while(l < r){
int m = (l + r) >> 1;
if(A.Min(0, pos[m] - 1) <= MxA && B.Min(0, pos[m] - 1) <= MxB) r = m;
else l = m + 1;
}
res = max(res, k - l + 1);
}
while(i < j){
B.add(p[i], n, -2);
i++;
}
}
return res;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
3 ms |
468 KB |
Output is correct |
14 |
Correct |
4 ms |
468 KB |
Output is correct |
15 |
Correct |
6 ms |
468 KB |
Output is correct |
16 |
Correct |
4 ms |
512 KB |
Output is correct |
17 |
Correct |
6 ms |
508 KB |
Output is correct |
18 |
Correct |
3 ms |
508 KB |
Output is correct |
19 |
Correct |
3 ms |
468 KB |
Output is correct |
20 |
Correct |
4 ms |
468 KB |
Output is correct |
21 |
Correct |
5 ms |
468 KB |
Output is correct |
22 |
Correct |
4 ms |
468 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1326 ms |
53156 KB |
Output is correct |
3 |
Correct |
1354 ms |
53160 KB |
Output is correct |
4 |
Execution timed out |
2033 ms |
54080 KB |
Time limit exceeded |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Execution timed out |
2041 ms |
56276 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1291 ms |
53156 KB |
Output is correct |
2 |
Correct |
1410 ms |
53156 KB |
Output is correct |
3 |
Correct |
1769 ms |
53156 KB |
Output is correct |
4 |
Correct |
1386 ms |
53160 KB |
Output is correct |
5 |
Correct |
1378 ms |
53164 KB |
Output is correct |
6 |
Correct |
1327 ms |
53156 KB |
Output is correct |
7 |
Correct |
1290 ms |
53160 KB |
Output is correct |
8 |
Correct |
1301 ms |
53160 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
3 ms |
468 KB |
Output is correct |
14 |
Correct |
4 ms |
468 KB |
Output is correct |
15 |
Correct |
6 ms |
468 KB |
Output is correct |
16 |
Correct |
4 ms |
512 KB |
Output is correct |
17 |
Correct |
6 ms |
508 KB |
Output is correct |
18 |
Correct |
3 ms |
508 KB |
Output is correct |
19 |
Correct |
3 ms |
468 KB |
Output is correct |
20 |
Correct |
4 ms |
468 KB |
Output is correct |
21 |
Correct |
5 ms |
468 KB |
Output is correct |
22 |
Correct |
4 ms |
468 KB |
Output is correct |
23 |
Correct |
193 ms |
8768 KB |
Output is correct |
24 |
Correct |
223 ms |
8652 KB |
Output is correct |
25 |
Correct |
198 ms |
8760 KB |
Output is correct |
26 |
Correct |
284 ms |
8764 KB |
Output is correct |
27 |
Correct |
306 ms |
8764 KB |
Output is correct |
28 |
Correct |
308 ms |
8764 KB |
Output is correct |
29 |
Correct |
420 ms |
8772 KB |
Output is correct |
30 |
Correct |
410 ms |
8888 KB |
Output is correct |
31 |
Correct |
619 ms |
9536 KB |
Output is correct |
32 |
Correct |
148 ms |
8760 KB |
Output is correct |
33 |
Correct |
239 ms |
8868 KB |
Output is correct |
34 |
Correct |
212 ms |
8976 KB |
Output is correct |
35 |
Correct |
233 ms |
8760 KB |
Output is correct |
36 |
Correct |
223 ms |
8880 KB |
Output is correct |
37 |
Correct |
215 ms |
8888 KB |
Output is correct |
38 |
Correct |
222 ms |
8756 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
3 ms |
468 KB |
Output is correct |
14 |
Correct |
4 ms |
468 KB |
Output is correct |
15 |
Correct |
6 ms |
468 KB |
Output is correct |
16 |
Correct |
4 ms |
512 KB |
Output is correct |
17 |
Correct |
6 ms |
508 KB |
Output is correct |
18 |
Correct |
3 ms |
508 KB |
Output is correct |
19 |
Correct |
3 ms |
468 KB |
Output is correct |
20 |
Correct |
4 ms |
468 KB |
Output is correct |
21 |
Correct |
5 ms |
468 KB |
Output is correct |
22 |
Correct |
4 ms |
468 KB |
Output is correct |
23 |
Correct |
1326 ms |
53156 KB |
Output is correct |
24 |
Correct |
1354 ms |
53160 KB |
Output is correct |
25 |
Execution timed out |
2033 ms |
54080 KB |
Time limit exceeded |
26 |
Halted |
0 ms |
0 KB |
- |