// 23 - 12 - 23
#include<bits/stdc++.h>
using namespace std;
#define read() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define day() time_t now = time(0);char* x = ctime(&now);cerr<<"Right Now Is : "<<x<<"\n"
#define int long long
#define ii pair<int,int>
#define X first
#define Y second
const long long MAX = (int)4e5 + 5;
const long long INF = (int)1e9;
const long long MOD = (int)1e9 + 7;
struct Fenwick{
int bit[MAX];
void update(int pos,int val){
for(;pos < MAX;pos += pos & -pos)bit[pos] = max(bit[pos],val);
}
int get(int pos){
int res = 0;
for(;pos > 0;pos -= pos & -pos)res = max(res,bit[pos]);
return res;
}
};
int n,val;
Fenwick ori,sub,siu;
int a[MAX];
int dp[MAX][3];
signed main(){
read();
cin >> n >> val;
vector<int> rt;
for(int i = 1;i <= n;i++){
cin >> a[i];
rt.push_back(a[i]);
rt.push_back(a[i] - val);
}
sort(rt.begin(),rt.end());
rt.erase(unique(rt.begin(),rt.end()),rt.end());
int res = 0;
for(int i = 1;i <= n;i++){
int x = lower_bound(rt.begin(),rt.end(),a[i]) - rt.begin() + 1;
int y = lower_bound(rt.begin(),rt.end(),a[i] - val) - rt.begin() + 1;
dp[i][0] = ori.get(x - 1) + 1;
// do nothing
dp[i][1] = sub.get(y - 1) + 1;
// decrease i by x
dp[i][2] = max(sub.get(x - 1),siu.get(x - 1)) + 1;
siu.update(x,dp[i][2]);
ori.update(x,dp[i][0]);
sub.update(y,dp[i][1]);
res = max({res,dp[i][0],dp[i][1],dp[i][2]});
//cout << dp[i][0] << " " << dp[i][1] << " " << dp[i][2] << "\n";
}
cout << res;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
600 KB |
Output is correct |
2 |
Correct |
0 ms |
604 KB |
Output is correct |
3 |
Correct |
0 ms |
604 KB |
Output is correct |
4 |
Correct |
0 ms |
604 KB |
Output is correct |
5 |
Correct |
0 ms |
604 KB |
Output is correct |
6 |
Correct |
0 ms |
460 KB |
Output is correct |
7 |
Correct |
0 ms |
604 KB |
Output is correct |
8 |
Correct |
1 ms |
464 KB |
Output is correct |
9 |
Correct |
0 ms |
604 KB |
Output is correct |
10 |
Correct |
1 ms |
604 KB |
Output is correct |
11 |
Correct |
1 ms |
604 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
600 KB |
Output is correct |
2 |
Correct |
0 ms |
604 KB |
Output is correct |
3 |
Correct |
0 ms |
604 KB |
Output is correct |
4 |
Correct |
0 ms |
604 KB |
Output is correct |
5 |
Correct |
0 ms |
604 KB |
Output is correct |
6 |
Correct |
0 ms |
460 KB |
Output is correct |
7 |
Correct |
0 ms |
604 KB |
Output is correct |
8 |
Correct |
1 ms |
464 KB |
Output is correct |
9 |
Correct |
0 ms |
604 KB |
Output is correct |
10 |
Correct |
1 ms |
604 KB |
Output is correct |
11 |
Correct |
1 ms |
604 KB |
Output is correct |
12 |
Correct |
1 ms |
604 KB |
Output is correct |
13 |
Correct |
1 ms |
604 KB |
Output is correct |
14 |
Correct |
0 ms |
604 KB |
Output is correct |
15 |
Correct |
0 ms |
604 KB |
Output is correct |
16 |
Correct |
1 ms |
604 KB |
Output is correct |
17 |
Correct |
0 ms |
604 KB |
Output is correct |
18 |
Correct |
0 ms |
604 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
600 KB |
Output is correct |
2 |
Correct |
0 ms |
604 KB |
Output is correct |
3 |
Correct |
0 ms |
604 KB |
Output is correct |
4 |
Correct |
0 ms |
604 KB |
Output is correct |
5 |
Correct |
0 ms |
604 KB |
Output is correct |
6 |
Correct |
0 ms |
460 KB |
Output is correct |
7 |
Correct |
0 ms |
604 KB |
Output is correct |
8 |
Correct |
1 ms |
464 KB |
Output is correct |
9 |
Correct |
0 ms |
604 KB |
Output is correct |
10 |
Correct |
1 ms |
604 KB |
Output is correct |
11 |
Correct |
1 ms |
604 KB |
Output is correct |
12 |
Correct |
1 ms |
604 KB |
Output is correct |
13 |
Correct |
1 ms |
604 KB |
Output is correct |
14 |
Correct |
0 ms |
604 KB |
Output is correct |
15 |
Correct |
0 ms |
604 KB |
Output is correct |
16 |
Correct |
1 ms |
604 KB |
Output is correct |
17 |
Correct |
0 ms |
604 KB |
Output is correct |
18 |
Correct |
0 ms |
604 KB |
Output is correct |
19 |
Correct |
2 ms |
604 KB |
Output is correct |
20 |
Correct |
1 ms |
604 KB |
Output is correct |
21 |
Correct |
1 ms |
604 KB |
Output is correct |
22 |
Correct |
1 ms |
684 KB |
Output is correct |
23 |
Correct |
1 ms |
604 KB |
Output is correct |
24 |
Correct |
1 ms |
604 KB |
Output is correct |
25 |
Correct |
1 ms |
464 KB |
Output is correct |
26 |
Correct |
1 ms |
604 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
116 ms |
16472 KB |
Output is correct |
2 |
Correct |
123 ms |
16688 KB |
Output is correct |
3 |
Correct |
117 ms |
16576 KB |
Output is correct |
4 |
Correct |
124 ms |
16688 KB |
Output is correct |
5 |
Correct |
53 ms |
13504 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
35 ms |
5624 KB |
Output is correct |
2 |
Correct |
36 ms |
5836 KB |
Output is correct |
3 |
Correct |
33 ms |
5840 KB |
Output is correct |
4 |
Correct |
14 ms |
4308 KB |
Output is correct |
5 |
Correct |
0 ms |
600 KB |
Output is correct |
6 |
Correct |
13 ms |
4276 KB |
Output is correct |
7 |
Correct |
24 ms |
5400 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
79 ms |
8644 KB |
Output is correct |
2 |
Correct |
61 ms |
8644 KB |
Output is correct |
3 |
Correct |
131 ms |
16436 KB |
Output is correct |
4 |
Correct |
66 ms |
13500 KB |
Output is correct |
5 |
Correct |
33 ms |
8140 KB |
Output is correct |
6 |
Correct |
69 ms |
15092 KB |
Output is correct |
7 |
Correct |
78 ms |
15820 KB |
Output is correct |
8 |
Correct |
47 ms |
8660 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
600 KB |
Output is correct |
2 |
Correct |
0 ms |
604 KB |
Output is correct |
3 |
Correct |
0 ms |
604 KB |
Output is correct |
4 |
Correct |
0 ms |
604 KB |
Output is correct |
5 |
Correct |
0 ms |
604 KB |
Output is correct |
6 |
Correct |
0 ms |
460 KB |
Output is correct |
7 |
Correct |
0 ms |
604 KB |
Output is correct |
8 |
Correct |
1 ms |
464 KB |
Output is correct |
9 |
Correct |
0 ms |
604 KB |
Output is correct |
10 |
Correct |
1 ms |
604 KB |
Output is correct |
11 |
Correct |
1 ms |
604 KB |
Output is correct |
12 |
Correct |
1 ms |
604 KB |
Output is correct |
13 |
Correct |
1 ms |
604 KB |
Output is correct |
14 |
Correct |
0 ms |
604 KB |
Output is correct |
15 |
Correct |
0 ms |
604 KB |
Output is correct |
16 |
Correct |
1 ms |
604 KB |
Output is correct |
17 |
Correct |
0 ms |
604 KB |
Output is correct |
18 |
Correct |
0 ms |
604 KB |
Output is correct |
19 |
Correct |
2 ms |
604 KB |
Output is correct |
20 |
Correct |
1 ms |
604 KB |
Output is correct |
21 |
Correct |
1 ms |
604 KB |
Output is correct |
22 |
Correct |
1 ms |
684 KB |
Output is correct |
23 |
Correct |
1 ms |
604 KB |
Output is correct |
24 |
Correct |
1 ms |
604 KB |
Output is correct |
25 |
Correct |
1 ms |
464 KB |
Output is correct |
26 |
Correct |
1 ms |
604 KB |
Output is correct |
27 |
Correct |
116 ms |
16472 KB |
Output is correct |
28 |
Correct |
123 ms |
16688 KB |
Output is correct |
29 |
Correct |
117 ms |
16576 KB |
Output is correct |
30 |
Correct |
124 ms |
16688 KB |
Output is correct |
31 |
Correct |
53 ms |
13504 KB |
Output is correct |
32 |
Correct |
35 ms |
5624 KB |
Output is correct |
33 |
Correct |
36 ms |
5836 KB |
Output is correct |
34 |
Correct |
33 ms |
5840 KB |
Output is correct |
35 |
Correct |
14 ms |
4308 KB |
Output is correct |
36 |
Correct |
0 ms |
600 KB |
Output is correct |
37 |
Correct |
13 ms |
4276 KB |
Output is correct |
38 |
Correct |
24 ms |
5400 KB |
Output is correct |
39 |
Correct |
79 ms |
8644 KB |
Output is correct |
40 |
Correct |
61 ms |
8644 KB |
Output is correct |
41 |
Correct |
131 ms |
16436 KB |
Output is correct |
42 |
Correct |
66 ms |
13500 KB |
Output is correct |
43 |
Correct |
33 ms |
8140 KB |
Output is correct |
44 |
Correct |
69 ms |
15092 KB |
Output is correct |
45 |
Correct |
78 ms |
15820 KB |
Output is correct |
46 |
Correct |
47 ms |
8660 KB |
Output is correct |
47 |
Correct |
57 ms |
10868 KB |
Output is correct |
48 |
Correct |
62 ms |
10948 KB |
Output is correct |
49 |
Correct |
144 ms |
21224 KB |
Output is correct |
50 |
Correct |
58 ms |
15696 KB |
Output is correct |
51 |
Correct |
49 ms |
10944 KB |
Output is correct |
52 |
Correct |
64 ms |
15864 KB |
Output is correct |
53 |
Correct |
67 ms |
15888 KB |
Output is correct |
54 |
Correct |
66 ms |
16576 KB |
Output is correct |
55 |
Correct |
104 ms |
19788 KB |
Output is correct |