#include <bits/stdc++.h>
using namespace std;
#define fr first
#define sc second
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
int n, x, t[200069], ans, dp[2], a, b;
vector<int> comp;
struct node
{
int l, r, val;
node *le, *ri;
void bd(int cl, int cr)
{
l = cl;
r = cr;
if (l == r) val = 0;
else
{
int md = (l+r)/2;
le = new node();
ri = new node();
le->bd(l, md);
ri->bd(md+1, r);
val = 0;
}
}
void upd(int idx, int x)
{
if (l>idx || r<idx) return;
if (l == r)
{
val = max(val, x);
return;
}
le->upd(idx, x);
ri->upd(idx, x);
val = max(le->val, ri->val);
}
int qry(int ql, int qr)
{
if (l>qr || r<ql) return 0;
if (ql<=l && r<=qr) return val;
return max(le->qry(ql, qr), ri->qry(ql, qr));
}
} *rt[2];
int main()
{
int i, j;
scanf("%d%d", &n, &x);
rt[0] = new node();
rt[1] = new node();
rt[0]->bd(1, n+1);
rt[1]->bd(1, n+1);
comp.push_back(0);
for (i=1; i<=n; i++)
{
scanf("%d", t+i);
comp.push_back(t[i]);
}
sort(comp.begin(), comp.end());
comp.resize(unique(comp.begin(), comp.end())-comp.begin());
for (i=1; i<=n; i++)
{
a = lower_bound(comp.begin(), comp.end(), t[i])-comp.begin()+1;
b = lower_bound(comp.begin(), comp.end(), t[i]+x)-comp.begin()+1;
dp[0] = 1+rt[0]->qry(1, a-1);
dp[1] = 1+max(rt[0]->qry(1, b-1), rt[1]->qry(1, a-1));
rt[0]->upd(a, dp[0]);
rt[1]->upd(a, dp[1]);
ans = max(ans, dp[1]);
}
printf("%d\n", ans);
}
Compilation message
glo.cpp: In function 'int main()':
glo.cpp:51:12: warning: unused variable 'j' [-Wunused-variable]
51 | int i, j;
| ^
glo.cpp:52:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
52 | scanf("%d%d", &n, &x);
| ~~~~~^~~~~~~~~~~~~~~~
glo.cpp:60:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
60 | scanf("%d", t+i);
| ~~~~~^~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 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 |
1 ms |
344 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
604 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 |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 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 |
1 ms |
344 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
604 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 |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
1 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 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 |
1 ms |
344 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
604 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 |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
1 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
1 ms |
604 KB |
Output is correct |
20 |
Correct |
1 ms |
656 KB |
Output is correct |
21 |
Correct |
1 ms |
604 KB |
Output is correct |
22 |
Correct |
2 ms |
600 KB |
Output is correct |
23 |
Correct |
1 ms |
600 KB |
Output is correct |
24 |
Correct |
1 ms |
604 KB |
Output is correct |
25 |
Correct |
1 ms |
604 KB |
Output is correct |
26 |
Correct |
1 ms |
644 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
336 ms |
41416 KB |
Output is correct |
2 |
Correct |
339 ms |
41412 KB |
Output is correct |
3 |
Correct |
339 ms |
41532 KB |
Output is correct |
4 |
Correct |
324 ms |
41464 KB |
Output is correct |
5 |
Correct |
126 ms |
40820 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
60 ms |
10756 KB |
Output is correct |
2 |
Correct |
73 ms |
10840 KB |
Output is correct |
3 |
Correct |
59 ms |
10844 KB |
Output is correct |
4 |
Correct |
26 ms |
10588 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
32 ms |
10552 KB |
Output is correct |
7 |
Correct |
46 ms |
10844 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
128 ms |
20940 KB |
Output is correct |
2 |
Correct |
126 ms |
20952 KB |
Output is correct |
3 |
Correct |
359 ms |
41412 KB |
Output is correct |
4 |
Correct |
114 ms |
40648 KB |
Output is correct |
5 |
Correct |
62 ms |
20696 KB |
Output is correct |
6 |
Correct |
113 ms |
38860 KB |
Output is correct |
7 |
Correct |
139 ms |
39372 KB |
Output is correct |
8 |
Correct |
99 ms |
20952 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 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 |
1 ms |
344 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
604 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 |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
1 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
1 ms |
604 KB |
Output is correct |
20 |
Correct |
1 ms |
656 KB |
Output is correct |
21 |
Correct |
1 ms |
604 KB |
Output is correct |
22 |
Correct |
2 ms |
600 KB |
Output is correct |
23 |
Correct |
1 ms |
600 KB |
Output is correct |
24 |
Correct |
1 ms |
604 KB |
Output is correct |
25 |
Correct |
1 ms |
604 KB |
Output is correct |
26 |
Correct |
1 ms |
644 KB |
Output is correct |
27 |
Correct |
336 ms |
41416 KB |
Output is correct |
28 |
Correct |
339 ms |
41412 KB |
Output is correct |
29 |
Correct |
339 ms |
41532 KB |
Output is correct |
30 |
Correct |
324 ms |
41464 KB |
Output is correct |
31 |
Correct |
126 ms |
40820 KB |
Output is correct |
32 |
Correct |
60 ms |
10756 KB |
Output is correct |
33 |
Correct |
73 ms |
10840 KB |
Output is correct |
34 |
Correct |
59 ms |
10844 KB |
Output is correct |
35 |
Correct |
26 ms |
10588 KB |
Output is correct |
36 |
Correct |
0 ms |
348 KB |
Output is correct |
37 |
Correct |
32 ms |
10552 KB |
Output is correct |
38 |
Correct |
46 ms |
10844 KB |
Output is correct |
39 |
Correct |
128 ms |
20940 KB |
Output is correct |
40 |
Correct |
126 ms |
20952 KB |
Output is correct |
41 |
Correct |
359 ms |
41412 KB |
Output is correct |
42 |
Correct |
114 ms |
40648 KB |
Output is correct |
43 |
Correct |
62 ms |
20696 KB |
Output is correct |
44 |
Correct |
113 ms |
38860 KB |
Output is correct |
45 |
Correct |
139 ms |
39372 KB |
Output is correct |
46 |
Correct |
99 ms |
20952 KB |
Output is correct |
47 |
Correct |
136 ms |
20952 KB |
Output is correct |
48 |
Correct |
139 ms |
20892 KB |
Output is correct |
49 |
Correct |
345 ms |
41412 KB |
Output is correct |
50 |
Correct |
113 ms |
40648 KB |
Output is correct |
51 |
Correct |
97 ms |
31128 KB |
Output is correct |
52 |
Correct |
144 ms |
40904 KB |
Output is correct |
53 |
Correct |
115 ms |
40900 KB |
Output is correct |
54 |
Correct |
119 ms |
41412 KB |
Output is correct |
55 |
Correct |
225 ms |
41668 KB |
Output is correct |