#include<bits/stdc++.h>
using namespace std;
int n;
vector<int> st;
void update(int pos, int val, int node=1, int tl=0, int tr=n-1){
if (tl == tr){
st[node] = val;
return;
}
int tm = (tl+tr)/2;
if (pos <= tm) update(pos, val, node*2, tl, tm);
else update(pos, val, node*2+1, tm+1, tr);
st[node] = max(st[node*2], st[node*2+1]);
}
int query(int l, int r, int node=1, int tl=0, int tr=n-1){
if (l <= tl && tr <= r) return st[node];
int tm = (tl+tr)/2;
int res = 0;
if (l <= tm) res = max(res, query(l, r, node*2, tl, tm));
if (tm+1 <= r) res = max(res, query(l, r, node*2+1, tm+1, tr));
return res;
}
int main(){
int x;
cin >> n >> x;
vector<int> v(n);
for (int i=0; i<n; i++) cin >> v[i];
st.resize(4*n, 0);
vector<pair<int,int>> p(n);
for (int i=0; i<n; i++) p[i] = {v[i], -i};
sort(p.begin(), p.end());
for (int i=n-1; i>=0; i--){
int j = -p[i].second;
int bsf = query(j, n-1);
update(j, bsf+1);
}
int res = st[1];
if (x == 0){
cout << res << "\n";
return 0;
}
if (x == pow(10, 9)){
int tl = 0, tr = n-1, node = 1;
while (tl != tr){
int tm = (tl+tr)/2;
if (st[node*2+1] == res){
tl = tm+1;
node = node*2+1;
}
else {
tr = tm;
node = node*2;
}
}
if (tl == 0){
cout << res;
return 0;
}
for (int i=0; i<4*n; i++) st[i] = 0;
vector<pair<int,int>> q(tl);
for (int i=0; i<tl; i++) q[i] = {v[i], -i};
sort(q.begin(), q.end());
for (int i=tl-1; i>=0; i--){
int j = -p[i].second;
int bsf = query(j, n-1);
update(j, bsf+1);
}
int res2 = st[1];
cout << res+res2 << "\n";
return 0;
}
for (int i=0; i<n; i++){
for (int j=i; j<n; j++){
for (int k=-x; k<=x; k+=2*x){
if (k == 0) continue;
for (int l=0; l<n; l++){
if (i <= l && l <= j) p[l] = {v[l]+k, -l};
else p[l] = {v[l], -l};
}
sort(p.begin(), p.end());
for (int l=0; l<4*n; l++) st[l] = 0;
for (int l=n-1; l>=0; l--){
int m = -p[l].second;
int bsf = query(m, n-1);
update(m, bsf+1);
}
res = max(res, st[1]);
}
}
}
cout << res << "\n";
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
344 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
344 KB |
Output is correct |
12 |
Correct |
9 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
8 ms |
348 KB |
Output is correct |
15 |
Correct |
6 ms |
348 KB |
Output is correct |
16 |
Correct |
7 ms |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
344 KB |
Output is correct |
12 |
Correct |
9 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
8 ms |
348 KB |
Output is correct |
15 |
Correct |
6 ms |
348 KB |
Output is correct |
16 |
Correct |
7 ms |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
1 ms |
348 KB |
Output is correct |
19 |
Execution timed out |
2079 ms |
348 KB |
Time limit exceeded |
20 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
130 ms |
5828 KB |
Output is correct |
2 |
Correct |
121 ms |
5908 KB |
Output is correct |
3 |
Correct |
137 ms |
5716 KB |
Output is correct |
4 |
Correct |
117 ms |
5712 KB |
Output is correct |
5 |
Correct |
80 ms |
5712 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
2033 ms |
1624 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
66 ms |
3156 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
344 KB |
Output is correct |
12 |
Correct |
9 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
8 ms |
348 KB |
Output is correct |
15 |
Correct |
6 ms |
348 KB |
Output is correct |
16 |
Correct |
7 ms |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
1 ms |
348 KB |
Output is correct |
19 |
Execution timed out |
2079 ms |
348 KB |
Time limit exceeded |
20 |
Halted |
0 ms |
0 KB |
- |