#include <bits/stdc++.h>
#define pb push_back
#define X first
#define Y second
#define pii pair<int, int>
#define lb lower_bound
using namespace std;
int n, x;
vector<int> in, srt;
struct ft{
vector<int> fen;
ft(int N){
fen.assign(N+1, 0);
}
int qer(int a){
a++;
int ans = 0;
for(;a>0; a-=a&(-a))ans=max(ans, fen[a]);
return ans;
}
void upd(int a, int b){
a++;
for(;a<fen.size(); a+=a&(-a))fen[a]=max(b, fen[a]);
}
};
int main(){
cin >> n >> x;
for(int i = 0; i<n; i++){
int c; cin >> c;
in.pb(c); srt.pb(c);
}
sort(srt.begin(), srt.end());
ft yes(n), no(n);
for(auto i : in){
int id = lb(srt.begin(), srt.end(), i)-srt.begin();
int tmp = no.qer(id-1);
int nid = lb(srt.begin(), srt.end(), i+x)-srt.begin();
int tmp2 = no.qer(nid-1);
no.upd(id, tmp+1);
tmp = yes.qer(id-1);
tmp = max(tmp, tmp2);
yes.upd(id, tmp+1);
}
cout << yes.qer(n-1);
return 0;
}
Compilation message
glo.cpp: In member function 'void ft::upd(int, int)':
glo.cpp:25:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(;a<fen.size(); a+=a&(-a))fen[a]=max(b, fen[a]);
~^~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
384 KB |
Output is correct |
2 |
Correct |
2 ms |
384 KB |
Output is correct |
3 |
Correct |
2 ms |
256 KB |
Output is correct |
4 |
Correct |
2 ms |
384 KB |
Output is correct |
5 |
Correct |
2 ms |
256 KB |
Output is correct |
6 |
Correct |
2 ms |
384 KB |
Output is correct |
7 |
Correct |
2 ms |
384 KB |
Output is correct |
8 |
Correct |
2 ms |
256 KB |
Output is correct |
9 |
Correct |
2 ms |
384 KB |
Output is correct |
10 |
Correct |
2 ms |
384 KB |
Output is correct |
11 |
Correct |
2 ms |
404 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
384 KB |
Output is correct |
2 |
Correct |
2 ms |
384 KB |
Output is correct |
3 |
Correct |
2 ms |
256 KB |
Output is correct |
4 |
Correct |
2 ms |
384 KB |
Output is correct |
5 |
Correct |
2 ms |
256 KB |
Output is correct |
6 |
Correct |
2 ms |
384 KB |
Output is correct |
7 |
Correct |
2 ms |
384 KB |
Output is correct |
8 |
Correct |
2 ms |
256 KB |
Output is correct |
9 |
Correct |
2 ms |
384 KB |
Output is correct |
10 |
Correct |
2 ms |
384 KB |
Output is correct |
11 |
Correct |
2 ms |
404 KB |
Output is correct |
12 |
Correct |
2 ms |
256 KB |
Output is correct |
13 |
Correct |
2 ms |
256 KB |
Output is correct |
14 |
Correct |
2 ms |
256 KB |
Output is correct |
15 |
Correct |
2 ms |
256 KB |
Output is correct |
16 |
Correct |
2 ms |
256 KB |
Output is correct |
17 |
Correct |
2 ms |
256 KB |
Output is correct |
18 |
Correct |
2 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
384 KB |
Output is correct |
2 |
Correct |
2 ms |
384 KB |
Output is correct |
3 |
Correct |
2 ms |
256 KB |
Output is correct |
4 |
Correct |
2 ms |
384 KB |
Output is correct |
5 |
Correct |
2 ms |
256 KB |
Output is correct |
6 |
Correct |
2 ms |
384 KB |
Output is correct |
7 |
Correct |
2 ms |
384 KB |
Output is correct |
8 |
Correct |
2 ms |
256 KB |
Output is correct |
9 |
Correct |
2 ms |
384 KB |
Output is correct |
10 |
Correct |
2 ms |
384 KB |
Output is correct |
11 |
Correct |
2 ms |
404 KB |
Output is correct |
12 |
Correct |
2 ms |
256 KB |
Output is correct |
13 |
Correct |
2 ms |
256 KB |
Output is correct |
14 |
Correct |
2 ms |
256 KB |
Output is correct |
15 |
Correct |
2 ms |
256 KB |
Output is correct |
16 |
Correct |
2 ms |
256 KB |
Output is correct |
17 |
Correct |
2 ms |
256 KB |
Output is correct |
18 |
Correct |
2 ms |
384 KB |
Output is correct |
19 |
Correct |
3 ms |
384 KB |
Output is correct |
20 |
Correct |
3 ms |
384 KB |
Output is correct |
21 |
Correct |
3 ms |
384 KB |
Output is correct |
22 |
Correct |
3 ms |
384 KB |
Output is correct |
23 |
Correct |
3 ms |
384 KB |
Output is correct |
24 |
Correct |
2 ms |
384 KB |
Output is correct |
25 |
Correct |
2 ms |
384 KB |
Output is correct |
26 |
Correct |
2 ms |
512 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
175 ms |
3804 KB |
Output is correct |
2 |
Correct |
173 ms |
3680 KB |
Output is correct |
3 |
Correct |
178 ms |
3680 KB |
Output is correct |
4 |
Correct |
173 ms |
3628 KB |
Output is correct |
5 |
Correct |
102 ms |
3844 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
40 ms |
1072 KB |
Output is correct |
2 |
Correct |
41 ms |
1668 KB |
Output is correct |
3 |
Correct |
43 ms |
1652 KB |
Output is correct |
4 |
Correct |
25 ms |
1404 KB |
Output is correct |
5 |
Correct |
2 ms |
256 KB |
Output is correct |
6 |
Correct |
27 ms |
1532 KB |
Output is correct |
7 |
Correct |
37 ms |
1660 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
76 ms |
2156 KB |
Output is correct |
2 |
Correct |
77 ms |
2088 KB |
Output is correct |
3 |
Correct |
162 ms |
3824 KB |
Output is correct |
4 |
Correct |
107 ms |
3680 KB |
Output is correct |
5 |
Correct |
50 ms |
2028 KB |
Output is correct |
6 |
Correct |
94 ms |
3568 KB |
Output is correct |
7 |
Correct |
115 ms |
3560 KB |
Output is correct |
8 |
Correct |
70 ms |
2156 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
384 KB |
Output is correct |
2 |
Correct |
2 ms |
384 KB |
Output is correct |
3 |
Correct |
2 ms |
256 KB |
Output is correct |
4 |
Correct |
2 ms |
384 KB |
Output is correct |
5 |
Correct |
2 ms |
256 KB |
Output is correct |
6 |
Correct |
2 ms |
384 KB |
Output is correct |
7 |
Correct |
2 ms |
384 KB |
Output is correct |
8 |
Correct |
2 ms |
256 KB |
Output is correct |
9 |
Correct |
2 ms |
384 KB |
Output is correct |
10 |
Correct |
2 ms |
384 KB |
Output is correct |
11 |
Correct |
2 ms |
404 KB |
Output is correct |
12 |
Correct |
2 ms |
256 KB |
Output is correct |
13 |
Correct |
2 ms |
256 KB |
Output is correct |
14 |
Correct |
2 ms |
256 KB |
Output is correct |
15 |
Correct |
2 ms |
256 KB |
Output is correct |
16 |
Correct |
2 ms |
256 KB |
Output is correct |
17 |
Correct |
2 ms |
256 KB |
Output is correct |
18 |
Correct |
2 ms |
384 KB |
Output is correct |
19 |
Correct |
3 ms |
384 KB |
Output is correct |
20 |
Correct |
3 ms |
384 KB |
Output is correct |
21 |
Correct |
3 ms |
384 KB |
Output is correct |
22 |
Correct |
3 ms |
384 KB |
Output is correct |
23 |
Correct |
3 ms |
384 KB |
Output is correct |
24 |
Correct |
2 ms |
384 KB |
Output is correct |
25 |
Correct |
2 ms |
384 KB |
Output is correct |
26 |
Correct |
2 ms |
512 KB |
Output is correct |
27 |
Correct |
175 ms |
3804 KB |
Output is correct |
28 |
Correct |
173 ms |
3680 KB |
Output is correct |
29 |
Correct |
178 ms |
3680 KB |
Output is correct |
30 |
Correct |
173 ms |
3628 KB |
Output is correct |
31 |
Correct |
102 ms |
3844 KB |
Output is correct |
32 |
Correct |
40 ms |
1072 KB |
Output is correct |
33 |
Correct |
41 ms |
1668 KB |
Output is correct |
34 |
Correct |
43 ms |
1652 KB |
Output is correct |
35 |
Correct |
25 ms |
1404 KB |
Output is correct |
36 |
Correct |
2 ms |
256 KB |
Output is correct |
37 |
Correct |
27 ms |
1532 KB |
Output is correct |
38 |
Correct |
37 ms |
1660 KB |
Output is correct |
39 |
Correct |
76 ms |
2156 KB |
Output is correct |
40 |
Correct |
77 ms |
2088 KB |
Output is correct |
41 |
Correct |
162 ms |
3824 KB |
Output is correct |
42 |
Correct |
107 ms |
3680 KB |
Output is correct |
43 |
Correct |
50 ms |
2028 KB |
Output is correct |
44 |
Correct |
94 ms |
3568 KB |
Output is correct |
45 |
Correct |
115 ms |
3560 KB |
Output is correct |
46 |
Correct |
70 ms |
2156 KB |
Output is correct |
47 |
Correct |
86 ms |
3252 KB |
Output is correct |
48 |
Correct |
85 ms |
3124 KB |
Output is correct |
49 |
Correct |
175 ms |
5660 KB |
Output is correct |
50 |
Correct |
107 ms |
4976 KB |
Output is correct |
51 |
Correct |
85 ms |
3964 KB |
Output is correct |
52 |
Correct |
112 ms |
5052 KB |
Output is correct |
53 |
Correct |
100 ms |
4960 KB |
Output is correct |
54 |
Correct |
122 ms |
5728 KB |
Output is correct |
55 |
Correct |
155 ms |
5716 KB |
Output is correct |