#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5+10;
const int maxv = 2e9+10;
struct Node
{
int v;
Node *l, *r;
Node()
{
v = 0;
l = r = NULL;
}
};
int n, x;
int num[maxn];
int suf[maxn];
int get(Node *t) {return (t ? t->v : 0);}
void clear(Node *node, int l, int r)
{
if (!node) return;
if (l == r)
{
node->v = 0;
return;
}
int mid = (l+r)>>1;
clear(node->l, l, mid); clear(node->r, mid+1, r);
node->v = 0;
}
void upd(Node *node, int l, int r, int pos, int v)
{
if (l == r)
{
node->v = max(v, node->v);
return;
}
int mid = (l+r)>>1;
if (pos <= mid)
{
if (!node->l) node->l = new Node();
upd(node->l, l, mid, pos, v);
}
else
{
if (!node->r) node->r = new Node();
upd(node->r, mid+1, r, pos, v);
}
node->v = max(get(node->l), get(node->r));
}
int query(Node *node, int l, int r, int a, int b)
{
if (!node || l > b || r < a) return 0;
if (l >= a && r <= b) return node->v;
int mid = (l+r)>>1;
int p1 = query(node->l, l, mid, a, b);
int p2 = query(node->r, mid+1, r, a, b);
return max(p1, p2);
}
int main(void)
{
scanf("%d %d", &n, &x);
Node *t = new Node();
for (int i = 1; i <= n; i++)
scanf("%d", &num[i]);
for (int i = n; i >= 1; i--)
{
int val = query(t, 1, maxv, num[i]+1, maxv);
suf[i] = val+1;
upd(t, 1, maxv, num[i], suf[i]);
}
int ans = 0;
t = new Node();
for (int i = 1; i <= n; i++)
{
int val = 0;
if (num[i]+x > 1) val = query(t, 1, maxv, 1, num[i]+x-1);
ans = max(ans, suf[i]+val);
int p = 0;
if (num[i] > 1) p = query(t, 1, maxv, 1, num[i]-1);
upd(t, 1, maxv, num[i], p+1);
}
printf("%d\n", ans);
}
Compilation message
glo.cpp: In function 'int main()':
glo.cpp:82:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d %d", &n, &x);
~~~~~^~~~~~~~~~~~~~~~~
glo.cpp:87:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d", &num[i]);
~~~~~^~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
256 KB |
Output is correct |
2 |
Correct |
2 ms |
256 KB |
Output is correct |
3 |
Correct |
2 ms |
384 KB |
Output is correct |
4 |
Correct |
2 ms |
384 KB |
Output is correct |
5 |
Correct |
2 ms |
384 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 |
384 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 |
304 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
256 KB |
Output is correct |
2 |
Correct |
2 ms |
256 KB |
Output is correct |
3 |
Correct |
2 ms |
384 KB |
Output is correct |
4 |
Correct |
2 ms |
384 KB |
Output is correct |
5 |
Correct |
2 ms |
384 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 |
384 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 |
304 KB |
Output is correct |
12 |
Correct |
2 ms |
384 KB |
Output is correct |
13 |
Correct |
2 ms |
384 KB |
Output is correct |
14 |
Correct |
2 ms |
256 KB |
Output is correct |
15 |
Correct |
2 ms |
256 KB |
Output is correct |
16 |
Correct |
3 ms |
384 KB |
Output is correct |
17 |
Correct |
2 ms |
384 KB |
Output is correct |
18 |
Correct |
2 ms |
256 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
256 KB |
Output is correct |
2 |
Correct |
2 ms |
256 KB |
Output is correct |
3 |
Correct |
2 ms |
384 KB |
Output is correct |
4 |
Correct |
2 ms |
384 KB |
Output is correct |
5 |
Correct |
2 ms |
384 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 |
384 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 |
304 KB |
Output is correct |
12 |
Correct |
2 ms |
384 KB |
Output is correct |
13 |
Correct |
2 ms |
384 KB |
Output is correct |
14 |
Correct |
2 ms |
256 KB |
Output is correct |
15 |
Correct |
2 ms |
256 KB |
Output is correct |
16 |
Correct |
3 ms |
384 KB |
Output is correct |
17 |
Correct |
2 ms |
384 KB |
Output is correct |
18 |
Correct |
2 ms |
256 KB |
Output is correct |
19 |
Correct |
5 ms |
1664 KB |
Output is correct |
20 |
Correct |
5 ms |
1664 KB |
Output is correct |
21 |
Correct |
5 ms |
1664 KB |
Output is correct |
22 |
Correct |
5 ms |
1664 KB |
Output is correct |
23 |
Correct |
4 ms |
1024 KB |
Output is correct |
24 |
Correct |
5 ms |
1024 KB |
Output is correct |
25 |
Correct |
3 ms |
384 KB |
Output is correct |
26 |
Correct |
4 ms |
512 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
840 ms |
169792 KB |
Output is correct |
2 |
Correct |
804 ms |
169788 KB |
Output is correct |
3 |
Correct |
787 ms |
169804 KB |
Output is correct |
4 |
Correct |
827 ms |
169880 KB |
Output is correct |
5 |
Correct |
315 ms |
92140 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
169 ms |
49028 KB |
Output is correct |
2 |
Correct |
202 ms |
48988 KB |
Output is correct |
3 |
Correct |
194 ms |
49016 KB |
Output is correct |
4 |
Correct |
91 ms |
26380 KB |
Output is correct |
5 |
Correct |
2 ms |
256 KB |
Output is correct |
6 |
Correct |
63 ms |
5368 KB |
Output is correct |
7 |
Correct |
123 ms |
35064 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
379 ms |
91640 KB |
Output is correct |
2 |
Correct |
374 ms |
91356 KB |
Output is correct |
3 |
Correct |
793 ms |
169956 KB |
Output is correct |
4 |
Correct |
299 ms |
92072 KB |
Output is correct |
5 |
Correct |
108 ms |
13612 KB |
Output is correct |
6 |
Correct |
196 ms |
25704 KB |
Output is correct |
7 |
Correct |
228 ms |
25612 KB |
Output is correct |
8 |
Correct |
262 ms |
65636 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
256 KB |
Output is correct |
2 |
Correct |
2 ms |
256 KB |
Output is correct |
3 |
Correct |
2 ms |
384 KB |
Output is correct |
4 |
Correct |
2 ms |
384 KB |
Output is correct |
5 |
Correct |
2 ms |
384 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 |
384 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 |
304 KB |
Output is correct |
12 |
Correct |
2 ms |
384 KB |
Output is correct |
13 |
Correct |
2 ms |
384 KB |
Output is correct |
14 |
Correct |
2 ms |
256 KB |
Output is correct |
15 |
Correct |
2 ms |
256 KB |
Output is correct |
16 |
Correct |
3 ms |
384 KB |
Output is correct |
17 |
Correct |
2 ms |
384 KB |
Output is correct |
18 |
Correct |
2 ms |
256 KB |
Output is correct |
19 |
Correct |
5 ms |
1664 KB |
Output is correct |
20 |
Correct |
5 ms |
1664 KB |
Output is correct |
21 |
Correct |
5 ms |
1664 KB |
Output is correct |
22 |
Correct |
5 ms |
1664 KB |
Output is correct |
23 |
Correct |
4 ms |
1024 KB |
Output is correct |
24 |
Correct |
5 ms |
1024 KB |
Output is correct |
25 |
Correct |
3 ms |
384 KB |
Output is correct |
26 |
Correct |
4 ms |
512 KB |
Output is correct |
27 |
Correct |
840 ms |
169792 KB |
Output is correct |
28 |
Correct |
804 ms |
169788 KB |
Output is correct |
29 |
Correct |
787 ms |
169804 KB |
Output is correct |
30 |
Correct |
827 ms |
169880 KB |
Output is correct |
31 |
Correct |
315 ms |
92140 KB |
Output is correct |
32 |
Correct |
169 ms |
49028 KB |
Output is correct |
33 |
Correct |
202 ms |
48988 KB |
Output is correct |
34 |
Correct |
194 ms |
49016 KB |
Output is correct |
35 |
Correct |
91 ms |
26380 KB |
Output is correct |
36 |
Correct |
2 ms |
256 KB |
Output is correct |
37 |
Correct |
63 ms |
5368 KB |
Output is correct |
38 |
Correct |
123 ms |
35064 KB |
Output is correct |
39 |
Correct |
379 ms |
91640 KB |
Output is correct |
40 |
Correct |
374 ms |
91356 KB |
Output is correct |
41 |
Correct |
793 ms |
169956 KB |
Output is correct |
42 |
Correct |
299 ms |
92072 KB |
Output is correct |
43 |
Correct |
108 ms |
13612 KB |
Output is correct |
44 |
Correct |
196 ms |
25704 KB |
Output is correct |
45 |
Correct |
228 ms |
25612 KB |
Output is correct |
46 |
Correct |
262 ms |
65636 KB |
Output is correct |
47 |
Correct |
411 ms |
91348 KB |
Output is correct |
48 |
Correct |
376 ms |
91424 KB |
Output is correct |
49 |
Correct |
866 ms |
169788 KB |
Output is correct |
50 |
Correct |
326 ms |
92176 KB |
Output is correct |
51 |
Correct |
158 ms |
13944 KB |
Output is correct |
52 |
Correct |
248 ms |
27040 KB |
Output is correct |
53 |
Correct |
220 ms |
26916 KB |
Output is correct |
54 |
Correct |
202 ms |
27000 KB |
Output is correct |
55 |
Correct |
608 ms |
122328 KB |
Output is correct |