#include <bits/stdc++.h>
using namespace std;
pair<int,int> segment[524288];
void update(int a, int b, int val, int time) {
a += 262144; b += 262144;
while (a <= b) {
if (a % 2 == 1) {segment[a++] = make_pair(val, time);}
if (b % 2 == 0) {segment[b--] = make_pair(val, time);}
a /= 2; b /= 2;
}
}
int fetch(int a) {
int pow2 = 131072;
int node = 1;
pair<int,int> ans = segment[node];
while (pow2 > 0) {
node *= 2;
if (a >= pow2) {
a -= pow2;
node++;
}
if (ans.second < segment[node].second) {
ans.first = segment[node].first; ans.second = segment[node].second;
}
pow2 /= 2;
}
return ans.first;
}
bool comp(int a, int b) {
return fetch(a) < fetch(b);
}
int main() {
for (int i=0;i<524288;i++) {
segment[i] = make_pair(0, -2);
}
int n, x; cin >> n >> x;
vector<int> arr(n);
for (int i=0;i<n;i++) {
cin >> arr[i];
segment[i + 262144] = make_pair(arr[i], -1);
}
vector<int> lisnormal;
vector<int> dum;
int pos1, pos2;
for (int i=0;i<n;i++) {
pos1 = lower_bound(lisnormal.begin(), lisnormal.end(), arr[i] + x) - lisnormal.begin();
segment[524287] = make_pair(arr[i] + x, i);
pos2 = lower_bound(dum.begin() ,dum.end(), 524287, comp) - dum.begin();
update(pos2, max(pos2, pos1), arr[i] + x, i);
while (dum.size() <= max(pos2, pos1)) {
dum.push_back(dum.size());
}
pos1 = lower_bound(lisnormal.begin(), lisnormal.end(), arr[i]) - lisnormal.begin();
if (pos1 == lisnormal.size()) {
lisnormal.push_back(arr[i]);
} else {
lisnormal[pos1] = arr[i];
}
//for (int j: lisnormal) {
// cout << j << ' ';
//} cout << '\n';
//for (int j: dum) {
// cout << fetch(j) << ' ';
//} cout << '\n' << '\n' << '\n';
}
cout << dum.size();
}
Compilation message
glo.cpp: In function 'int main()':
glo.cpp:60:27: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'const int' [-Wsign-compare]
60 | while (dum.size() <= max(pos2, pos1)) {
| ~~~~~~~~~~~^~~~~~~~~~~~~~~~~~
glo.cpp:64:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
64 | if (pos1 == lisnormal.size()) {
| ~~~~~^~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
4444 KB |
Output is correct |
2 |
Correct |
1 ms |
4528 KB |
Output is correct |
3 |
Correct |
2 ms |
4444 KB |
Output is correct |
4 |
Correct |
2 ms |
4464 KB |
Output is correct |
5 |
Correct |
1 ms |
4544 KB |
Output is correct |
6 |
Correct |
2 ms |
4696 KB |
Output is correct |
7 |
Correct |
1 ms |
4460 KB |
Output is correct |
8 |
Correct |
1 ms |
4444 KB |
Output is correct |
9 |
Correct |
2 ms |
4444 KB |
Output is correct |
10 |
Correct |
2 ms |
4440 KB |
Output is correct |
11 |
Correct |
2 ms |
4444 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
4444 KB |
Output is correct |
2 |
Correct |
1 ms |
4528 KB |
Output is correct |
3 |
Correct |
2 ms |
4444 KB |
Output is correct |
4 |
Correct |
2 ms |
4464 KB |
Output is correct |
5 |
Correct |
1 ms |
4544 KB |
Output is correct |
6 |
Correct |
2 ms |
4696 KB |
Output is correct |
7 |
Correct |
1 ms |
4460 KB |
Output is correct |
8 |
Correct |
1 ms |
4444 KB |
Output is correct |
9 |
Correct |
2 ms |
4444 KB |
Output is correct |
10 |
Correct |
2 ms |
4440 KB |
Output is correct |
11 |
Correct |
2 ms |
4444 KB |
Output is correct |
12 |
Correct |
2 ms |
4440 KB |
Output is correct |
13 |
Correct |
1 ms |
4440 KB |
Output is correct |
14 |
Correct |
1 ms |
4444 KB |
Output is correct |
15 |
Correct |
1 ms |
4444 KB |
Output is correct |
16 |
Correct |
2 ms |
4444 KB |
Output is correct |
17 |
Correct |
1 ms |
4444 KB |
Output is correct |
18 |
Correct |
2 ms |
4444 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
4444 KB |
Output is correct |
2 |
Correct |
1 ms |
4528 KB |
Output is correct |
3 |
Correct |
2 ms |
4444 KB |
Output is correct |
4 |
Correct |
2 ms |
4464 KB |
Output is correct |
5 |
Correct |
1 ms |
4544 KB |
Output is correct |
6 |
Correct |
2 ms |
4696 KB |
Output is correct |
7 |
Correct |
1 ms |
4460 KB |
Output is correct |
8 |
Correct |
1 ms |
4444 KB |
Output is correct |
9 |
Correct |
2 ms |
4444 KB |
Output is correct |
10 |
Correct |
2 ms |
4440 KB |
Output is correct |
11 |
Correct |
2 ms |
4444 KB |
Output is correct |
12 |
Correct |
2 ms |
4440 KB |
Output is correct |
13 |
Correct |
1 ms |
4440 KB |
Output is correct |
14 |
Correct |
1 ms |
4444 KB |
Output is correct |
15 |
Correct |
1 ms |
4444 KB |
Output is correct |
16 |
Correct |
2 ms |
4444 KB |
Output is correct |
17 |
Correct |
1 ms |
4444 KB |
Output is correct |
18 |
Correct |
2 ms |
4444 KB |
Output is correct |
19 |
Correct |
2 ms |
4440 KB |
Output is correct |
20 |
Correct |
2 ms |
4440 KB |
Output is correct |
21 |
Correct |
2 ms |
4444 KB |
Output is correct |
22 |
Correct |
2 ms |
4444 KB |
Output is correct |
23 |
Correct |
3 ms |
4440 KB |
Output is correct |
24 |
Correct |
2 ms |
4440 KB |
Output is correct |
25 |
Correct |
2 ms |
4444 KB |
Output is correct |
26 |
Correct |
2 ms |
4444 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
156 ms |
6992 KB |
Output is correct |
2 |
Correct |
156 ms |
6996 KB |
Output is correct |
3 |
Correct |
160 ms |
6992 KB |
Output is correct |
4 |
Correct |
157 ms |
7244 KB |
Output is correct |
5 |
Correct |
208 ms |
7376 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
42 ms |
5360 KB |
Output is correct |
2 |
Correct |
36 ms |
5208 KB |
Output is correct |
3 |
Correct |
36 ms |
5212 KB |
Output is correct |
4 |
Correct |
45 ms |
5212 KB |
Output is correct |
5 |
Correct |
2 ms |
4440 KB |
Output is correct |
6 |
Correct |
43 ms |
5336 KB |
Output is correct |
7 |
Correct |
34 ms |
5208 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
76 ms |
5720 KB |
Output is correct |
2 |
Correct |
73 ms |
5724 KB |
Output is correct |
3 |
Correct |
147 ms |
7240 KB |
Output is correct |
4 |
Correct |
196 ms |
7388 KB |
Output is correct |
5 |
Correct |
91 ms |
6092 KB |
Output is correct |
6 |
Correct |
196 ms |
7444 KB |
Output is correct |
7 |
Correct |
141 ms |
7888 KB |
Output is correct |
8 |
Correct |
68 ms |
5720 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
4444 KB |
Output is correct |
2 |
Correct |
1 ms |
4528 KB |
Output is correct |
3 |
Correct |
2 ms |
4444 KB |
Output is correct |
4 |
Correct |
2 ms |
4464 KB |
Output is correct |
5 |
Correct |
1 ms |
4544 KB |
Output is correct |
6 |
Correct |
2 ms |
4696 KB |
Output is correct |
7 |
Correct |
1 ms |
4460 KB |
Output is correct |
8 |
Correct |
1 ms |
4444 KB |
Output is correct |
9 |
Correct |
2 ms |
4444 KB |
Output is correct |
10 |
Correct |
2 ms |
4440 KB |
Output is correct |
11 |
Correct |
2 ms |
4444 KB |
Output is correct |
12 |
Correct |
2 ms |
4440 KB |
Output is correct |
13 |
Correct |
1 ms |
4440 KB |
Output is correct |
14 |
Correct |
1 ms |
4444 KB |
Output is correct |
15 |
Correct |
1 ms |
4444 KB |
Output is correct |
16 |
Correct |
2 ms |
4444 KB |
Output is correct |
17 |
Correct |
1 ms |
4444 KB |
Output is correct |
18 |
Correct |
2 ms |
4444 KB |
Output is correct |
19 |
Correct |
2 ms |
4440 KB |
Output is correct |
20 |
Correct |
2 ms |
4440 KB |
Output is correct |
21 |
Correct |
2 ms |
4444 KB |
Output is correct |
22 |
Correct |
2 ms |
4444 KB |
Output is correct |
23 |
Correct |
3 ms |
4440 KB |
Output is correct |
24 |
Correct |
2 ms |
4440 KB |
Output is correct |
25 |
Correct |
2 ms |
4444 KB |
Output is correct |
26 |
Correct |
2 ms |
4444 KB |
Output is correct |
27 |
Correct |
156 ms |
6992 KB |
Output is correct |
28 |
Correct |
156 ms |
6996 KB |
Output is correct |
29 |
Correct |
160 ms |
6992 KB |
Output is correct |
30 |
Correct |
157 ms |
7244 KB |
Output is correct |
31 |
Correct |
208 ms |
7376 KB |
Output is correct |
32 |
Correct |
42 ms |
5360 KB |
Output is correct |
33 |
Correct |
36 ms |
5208 KB |
Output is correct |
34 |
Correct |
36 ms |
5212 KB |
Output is correct |
35 |
Correct |
45 ms |
5212 KB |
Output is correct |
36 |
Correct |
2 ms |
4440 KB |
Output is correct |
37 |
Correct |
43 ms |
5336 KB |
Output is correct |
38 |
Correct |
34 ms |
5208 KB |
Output is correct |
39 |
Correct |
76 ms |
5720 KB |
Output is correct |
40 |
Correct |
73 ms |
5724 KB |
Output is correct |
41 |
Correct |
147 ms |
7240 KB |
Output is correct |
42 |
Correct |
196 ms |
7388 KB |
Output is correct |
43 |
Correct |
91 ms |
6092 KB |
Output is correct |
44 |
Correct |
196 ms |
7444 KB |
Output is correct |
45 |
Correct |
141 ms |
7888 KB |
Output is correct |
46 |
Correct |
68 ms |
5720 KB |
Output is correct |
47 |
Correct |
103 ms |
5680 KB |
Output is correct |
48 |
Correct |
86 ms |
5724 KB |
Output is correct |
49 |
Correct |
159 ms |
7232 KB |
Output is correct |
50 |
Correct |
190 ms |
7376 KB |
Output is correct |
51 |
Correct |
166 ms |
7368 KB |
Output is correct |
52 |
Correct |
209 ms |
7352 KB |
Output is correct |
53 |
Correct |
193 ms |
7376 KB |
Output is correct |
54 |
Correct |
149 ms |
8124 KB |
Output is correct |
55 |
Correct |
149 ms |
7248 KB |
Output is correct |