#include <bits/stdc++.h>
using namespace std;
const int MXN = 2e5 + 1, INF = 1e19;
const int SL = -1e9, SR = 1e9;
struct node {
int val = -INF;
node *lc, *rc;
node() : lc(0), rc(0) {}
};
deque<node> buffer;
node* create_node() {
buffer.emplace_back();
return &buffer.back();
}
int query(node* &cur, int l, int r, int ql, int qr) {
if (!cur) return -INF;
if (l > qr || r < ql) return -INF;
if (l >= ql && r <= qr) return cur->val;
int mid = l + (r - l) / 2;
return max(query(cur->lc, l, mid, ql, qr), query(cur->rc, mid + 1, r, ql, qr));
}
void maximise(node* &cur, int l, int r, int pos, int val) {
if (!cur) cur = create_node();
if (l == r) {
cur->val = max(cur->val, val);
return;
}
int mid = l + (r - l) / 2;
if (pos <= mid) maximise(cur->lc, l, mid, pos, val);
else maximise(cur->rc, mid + 1, r, pos, val);
if (cur->lc) cur->val = max(cur->val, cur->lc->val);
if (cur->rc) cur->val = max(cur->val, cur->rc->val);
}
int query(node* &root, int l) {
return query(root, SL, SR, l, SR);
}
void maximise(node* &root, int pos, int val) {
maximise(root, SL, SR, pos, val);
}
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int N, M;
cin >> N >> M;
node* root = create_node();
maximise(root, 0, 1);
for (int i = 1; i <= N; i++) {
int x;
cin >> x;
x -= i * M;
maximise(root, x, query(root, x) + 1);
}
cout << (N + 1) - root->val;
}
Compilation message
triusis.cpp:5:32: warning: overflow in conversion from 'double' to 'int' changes value from '1.0e+19' to '2147483647' [-Woverflow]
5 | const int MXN = 2e5 + 1, INF = 1e19;
| ^~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
0 ms |
204 KB |
Output is correct |
5 |
Correct |
0 ms |
204 KB |
Output is correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
7 |
Correct |
0 ms |
204 KB |
Output is correct |
8 |
Correct |
0 ms |
312 KB |
Output is correct |
9 |
Correct |
0 ms |
204 KB |
Output is correct |
10 |
Correct |
1 ms |
316 KB |
Output is correct |
11 |
Correct |
1 ms |
204 KB |
Output is correct |
12 |
Correct |
1 ms |
204 KB |
Output is correct |
13 |
Correct |
0 ms |
204 KB |
Output is correct |
14 |
Correct |
1 ms |
308 KB |
Output is correct |
15 |
Correct |
1 ms |
204 KB |
Output is correct |
16 |
Correct |
1 ms |
204 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
0 ms |
204 KB |
Output is correct |
5 |
Correct |
0 ms |
204 KB |
Output is correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
7 |
Correct |
0 ms |
204 KB |
Output is correct |
8 |
Correct |
0 ms |
312 KB |
Output is correct |
9 |
Correct |
0 ms |
204 KB |
Output is correct |
10 |
Correct |
1 ms |
316 KB |
Output is correct |
11 |
Correct |
1 ms |
204 KB |
Output is correct |
12 |
Correct |
1 ms |
204 KB |
Output is correct |
13 |
Correct |
0 ms |
204 KB |
Output is correct |
14 |
Correct |
1 ms |
308 KB |
Output is correct |
15 |
Correct |
1 ms |
204 KB |
Output is correct |
16 |
Correct |
1 ms |
204 KB |
Output is correct |
17 |
Correct |
1 ms |
316 KB |
Output is correct |
18 |
Correct |
0 ms |
308 KB |
Output is correct |
19 |
Correct |
1 ms |
204 KB |
Output is correct |
20 |
Correct |
3 ms |
588 KB |
Output is correct |
21 |
Correct |
4 ms |
844 KB |
Output is correct |
22 |
Correct |
4 ms |
460 KB |
Output is correct |
23 |
Correct |
4 ms |
1868 KB |
Output is correct |
24 |
Correct |
4 ms |
1996 KB |
Output is correct |
25 |
Correct |
4 ms |
972 KB |
Output is correct |
26 |
Correct |
4 ms |
1484 KB |
Output is correct |
27 |
Correct |
3 ms |
336 KB |
Output is correct |
28 |
Correct |
3 ms |
324 KB |
Output is correct |
29 |
Correct |
3 ms |
844 KB |
Output is correct |
30 |
Correct |
4 ms |
960 KB |
Output is correct |
31 |
Correct |
3 ms |
460 KB |
Output is correct |
32 |
Correct |
4 ms |
1612 KB |
Output is correct |
33 |
Correct |
4 ms |
1612 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
316 KB |
Output is correct |
2 |
Correct |
0 ms |
308 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
3 ms |
588 KB |
Output is correct |
5 |
Correct |
4 ms |
844 KB |
Output is correct |
6 |
Correct |
4 ms |
460 KB |
Output is correct |
7 |
Correct |
4 ms |
1868 KB |
Output is correct |
8 |
Correct |
4 ms |
1996 KB |
Output is correct |
9 |
Correct |
4 ms |
972 KB |
Output is correct |
10 |
Correct |
4 ms |
1484 KB |
Output is correct |
11 |
Correct |
3 ms |
336 KB |
Output is correct |
12 |
Correct |
3 ms |
324 KB |
Output is correct |
13 |
Correct |
3 ms |
844 KB |
Output is correct |
14 |
Correct |
4 ms |
960 KB |
Output is correct |
15 |
Correct |
3 ms |
460 KB |
Output is correct |
16 |
Correct |
4 ms |
1612 KB |
Output is correct |
17 |
Correct |
4 ms |
1612 KB |
Output is correct |
18 |
Correct |
1 ms |
204 KB |
Output is correct |
19 |
Correct |
1 ms |
204 KB |
Output is correct |
20 |
Correct |
0 ms |
204 KB |
Output is correct |
21 |
Correct |
0 ms |
204 KB |
Output is correct |
22 |
Correct |
0 ms |
204 KB |
Output is correct |
23 |
Correct |
1 ms |
204 KB |
Output is correct |
24 |
Correct |
0 ms |
204 KB |
Output is correct |
25 |
Correct |
0 ms |
312 KB |
Output is correct |
26 |
Correct |
0 ms |
204 KB |
Output is correct |
27 |
Correct |
1 ms |
316 KB |
Output is correct |
28 |
Correct |
1 ms |
204 KB |
Output is correct |
29 |
Correct |
1 ms |
204 KB |
Output is correct |
30 |
Correct |
0 ms |
204 KB |
Output is correct |
31 |
Correct |
1 ms |
308 KB |
Output is correct |
32 |
Correct |
1 ms |
204 KB |
Output is correct |
33 |
Correct |
1 ms |
204 KB |
Output is correct |
34 |
Correct |
8 ms |
2580 KB |
Output is correct |
35 |
Correct |
5 ms |
2636 KB |
Output is correct |
36 |
Correct |
5 ms |
2636 KB |
Output is correct |
37 |
Correct |
4 ms |
1484 KB |
Output is correct |
38 |
Correct |
3 ms |
332 KB |
Output is correct |
39 |
Correct |
3 ms |
332 KB |
Output is correct |
40 |
Correct |
3 ms |
360 KB |
Output is correct |
41 |
Correct |
2 ms |
332 KB |
Output is correct |
42 |
Correct |
6 ms |
1872 KB |
Output is correct |
43 |
Correct |
7 ms |
1868 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
2580 KB |
Output is correct |
2 |
Correct |
5 ms |
2636 KB |
Output is correct |
3 |
Correct |
5 ms |
2636 KB |
Output is correct |
4 |
Correct |
4 ms |
1484 KB |
Output is correct |
5 |
Correct |
3 ms |
332 KB |
Output is correct |
6 |
Correct |
3 ms |
332 KB |
Output is correct |
7 |
Correct |
3 ms |
360 KB |
Output is correct |
8 |
Correct |
2 ms |
332 KB |
Output is correct |
9 |
Correct |
6 ms |
1872 KB |
Output is correct |
10 |
Correct |
7 ms |
1868 KB |
Output is correct |
11 |
Correct |
1 ms |
316 KB |
Output is correct |
12 |
Correct |
0 ms |
308 KB |
Output is correct |
13 |
Correct |
1 ms |
204 KB |
Output is correct |
14 |
Correct |
3 ms |
588 KB |
Output is correct |
15 |
Correct |
4 ms |
844 KB |
Output is correct |
16 |
Correct |
4 ms |
460 KB |
Output is correct |
17 |
Correct |
4 ms |
1868 KB |
Output is correct |
18 |
Correct |
4 ms |
1996 KB |
Output is correct |
19 |
Correct |
4 ms |
972 KB |
Output is correct |
20 |
Correct |
4 ms |
1484 KB |
Output is correct |
21 |
Correct |
3 ms |
336 KB |
Output is correct |
22 |
Correct |
3 ms |
324 KB |
Output is correct |
23 |
Correct |
3 ms |
844 KB |
Output is correct |
24 |
Correct |
4 ms |
960 KB |
Output is correct |
25 |
Correct |
3 ms |
460 KB |
Output is correct |
26 |
Correct |
4 ms |
1612 KB |
Output is correct |
27 |
Correct |
4 ms |
1612 KB |
Output is correct |
28 |
Correct |
1 ms |
204 KB |
Output is correct |
29 |
Correct |
1 ms |
204 KB |
Output is correct |
30 |
Correct |
0 ms |
204 KB |
Output is correct |
31 |
Correct |
0 ms |
204 KB |
Output is correct |
32 |
Correct |
0 ms |
204 KB |
Output is correct |
33 |
Correct |
1 ms |
204 KB |
Output is correct |
34 |
Correct |
0 ms |
204 KB |
Output is correct |
35 |
Correct |
0 ms |
312 KB |
Output is correct |
36 |
Correct |
0 ms |
204 KB |
Output is correct |
37 |
Correct |
1 ms |
316 KB |
Output is correct |
38 |
Correct |
1 ms |
204 KB |
Output is correct |
39 |
Correct |
1 ms |
204 KB |
Output is correct |
40 |
Correct |
0 ms |
204 KB |
Output is correct |
41 |
Correct |
1 ms |
308 KB |
Output is correct |
42 |
Correct |
1 ms |
204 KB |
Output is correct |
43 |
Correct |
1 ms |
204 KB |
Output is correct |
44 |
Correct |
146 ms |
26156 KB |
Output is correct |
45 |
Correct |
224 ms |
67184 KB |
Output is correct |
46 |
Correct |
265 ms |
70708 KB |
Output is correct |
47 |
Correct |
217 ms |
70796 KB |
Output is correct |
48 |
Correct |
138 ms |
28264 KB |
Output is correct |
49 |
Correct |
150 ms |
50256 KB |
Output is correct |
50 |
Correct |
103 ms |
2196 KB |
Output is correct |
51 |
Correct |
105 ms |
2320 KB |
Output is correct |
52 |
Correct |
110 ms |
6036 KB |
Output is correct |
53 |
Correct |
62 ms |
1552 KB |
Output is correct |
54 |
Correct |
152 ms |
60196 KB |
Output is correct |
55 |
Correct |
149 ms |
59960 KB |
Output is correct |