#include <stdio.h>
#define N 200000
int max(int a, int b) { return a > b ? a : b; }
unsigned int X = 12345;
int rand_() {
return (X *= 3) >> 1;
}
int aa[N * 2];
void sort(int *ii, int l, int r) {
while (l < r) {
int i = l, j = l, k = r, i_ = ii[l + rand_() % (r - l)], tmp;
while (j < k)
if (aa[ii[j]] == aa[i_])
j++;
else if (aa[ii[j]] < aa[i_]) {
tmp = ii[i], ii[i] = ii[j], ii[j] = tmp;
i++, j++;
} else {
k--;
tmp = ii[j], ii[j] = ii[k], ii[k] = tmp;
}
sort(ii, l, i);
l = k;
}
}
void update(int *ft, int i, int n, int x) {
while (i < n) {
ft[i] = max(ft[i], x);
i |= i + 1;
}
}
int query(int *ft, int i) {
int x = 0;
while (i >= 0) {
x = max(x, ft[i]);
i &= i + 1, i--;
}
return x;
}
int main() {
static int ii[N * 2], ft1[N * 2], ft2[N * 2], dp[N], dq[N];
int n, x, i, a;
scanf("%d%d", &n, &x);
for (i = 0; i < n; i++)
scanf("%d", &aa[i]), aa[n + i] = aa[i] + x;
for (i = 0; i < n * 2; i++)
ii[i] = i;
sort(ii, 0, n * 2);
for (i = 0, a = 0; i < n * 2; i++)
aa[ii[i]] = i + 1 == n * 2 || aa[ii[i + 1]] != aa[ii[i]] ? a++ : a;
for (i = 0; i < n; i++) {
dp[i] = query(ft1, aa[i] - 1) + 1;
dq[i] = query(ft2, aa[n + i] - 1) + 1;
update(ft1, aa[i], n * 2, dp[i]), update(ft2, aa[i], n * 2, dp[i]);
update(ft2, aa[n + i], n * 2, dq[i]);
}
printf("%d\n", max(query(ft1, n * 2 - 1), query(ft2, n * 2 - 1)));
return 0;
}
Compilation message
glo.c: In function 'main':
glo.c:55:2: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
55 | scanf("%d%d", &n, &x);
| ^~~~~~~~~~~~~~~~~~~~~
glo.c:57:3: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
57 | scanf("%d", &aa[i]), aa[n + i] = aa[i] + x;
| ^~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
300 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
300 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
1 ms |
212 KB |
Output is correct |
17 |
Correct |
1 ms |
212 KB |
Output is correct |
18 |
Correct |
1 ms |
296 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
300 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
1 ms |
212 KB |
Output is correct |
17 |
Correct |
1 ms |
212 KB |
Output is correct |
18 |
Correct |
1 ms |
296 KB |
Output is correct |
19 |
Correct |
1 ms |
308 KB |
Output is correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |
21 |
Correct |
1 ms |
340 KB |
Output is correct |
22 |
Correct |
1 ms |
340 KB |
Output is correct |
23 |
Correct |
1 ms |
340 KB |
Output is correct |
24 |
Correct |
1 ms |
340 KB |
Output is correct |
25 |
Correct |
1 ms |
300 KB |
Output is correct |
26 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
120 ms |
6932 KB |
Output is correct |
2 |
Correct |
118 ms |
6820 KB |
Output is correct |
3 |
Correct |
121 ms |
6860 KB |
Output is correct |
4 |
Correct |
119 ms |
6868 KB |
Output is correct |
5 |
Correct |
79 ms |
5388 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
30 ms |
2308 KB |
Output is correct |
2 |
Correct |
37 ms |
2344 KB |
Output is correct |
3 |
Correct |
33 ms |
2252 KB |
Output is correct |
4 |
Correct |
23 ms |
1740 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
18 ms |
1740 KB |
Output is correct |
7 |
Correct |
26 ms |
2224 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
58 ms |
4008 KB |
Output is correct |
2 |
Correct |
56 ms |
4012 KB |
Output is correct |
3 |
Correct |
162 ms |
7628 KB |
Output is correct |
4 |
Correct |
77 ms |
5700 KB |
Output is correct |
5 |
Correct |
57 ms |
3576 KB |
Output is correct |
6 |
Correct |
81 ms |
6628 KB |
Output is correct |
7 |
Correct |
91 ms |
7288 KB |
Output is correct |
8 |
Correct |
65 ms |
3988 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
300 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
1 ms |
212 KB |
Output is correct |
17 |
Correct |
1 ms |
212 KB |
Output is correct |
18 |
Correct |
1 ms |
296 KB |
Output is correct |
19 |
Correct |
1 ms |
308 KB |
Output is correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |
21 |
Correct |
1 ms |
340 KB |
Output is correct |
22 |
Correct |
1 ms |
340 KB |
Output is correct |
23 |
Correct |
1 ms |
340 KB |
Output is correct |
24 |
Correct |
1 ms |
340 KB |
Output is correct |
25 |
Correct |
1 ms |
300 KB |
Output is correct |
26 |
Correct |
1 ms |
340 KB |
Output is correct |
27 |
Correct |
120 ms |
6932 KB |
Output is correct |
28 |
Correct |
118 ms |
6820 KB |
Output is correct |
29 |
Correct |
121 ms |
6860 KB |
Output is correct |
30 |
Correct |
119 ms |
6868 KB |
Output is correct |
31 |
Correct |
79 ms |
5388 KB |
Output is correct |
32 |
Correct |
30 ms |
2308 KB |
Output is correct |
33 |
Correct |
37 ms |
2344 KB |
Output is correct |
34 |
Correct |
33 ms |
2252 KB |
Output is correct |
35 |
Correct |
23 ms |
1740 KB |
Output is correct |
36 |
Correct |
1 ms |
212 KB |
Output is correct |
37 |
Correct |
18 ms |
1740 KB |
Output is correct |
38 |
Correct |
26 ms |
2224 KB |
Output is correct |
39 |
Correct |
58 ms |
4008 KB |
Output is correct |
40 |
Correct |
56 ms |
4012 KB |
Output is correct |
41 |
Correct |
162 ms |
7628 KB |
Output is correct |
42 |
Correct |
77 ms |
5700 KB |
Output is correct |
43 |
Correct |
57 ms |
3576 KB |
Output is correct |
44 |
Correct |
81 ms |
6628 KB |
Output is correct |
45 |
Correct |
91 ms |
7288 KB |
Output is correct |
46 |
Correct |
65 ms |
3988 KB |
Output is correct |
47 |
Correct |
69 ms |
4344 KB |
Output is correct |
48 |
Correct |
62 ms |
4380 KB |
Output is correct |
49 |
Correct |
124 ms |
8400 KB |
Output is correct |
50 |
Correct |
95 ms |
6124 KB |
Output is correct |
51 |
Correct |
73 ms |
4516 KB |
Output is correct |
52 |
Correct |
95 ms |
6280 KB |
Output is correct |
53 |
Correct |
82 ms |
7012 KB |
Output is correct |
54 |
Correct |
90 ms |
7660 KB |
Output is correct |
55 |
Correct |
135 ms |
7920 KB |
Output is correct |