Submission #631054

# Submission time Handle Problem Language Result Execution time Memory
631054 2022-08-17T15:37:58 Z rainboy Radio Towers (IOI22_towers) C++17
60 / 100
1000 ms 1888 KB
#include "towers.h"
#include <vector>

using namespace std;

const int N = 100000;

int max(int a, int b) { return a > b ? a : b; }

typedef vector<int> vi;

int aa[N], ii[N], ll[N], rr[N], n, p, cnt;
int first;

void init(int n_, vi aa_) {
	n = n_;
	for (int i = 0; i < n; i++)
		aa[i] = aa_[i];
	p = 0;
	while (p < n - 1 && aa[p] < aa[p + 1])
		p++;
	for (int i = p + 1; i < n; i++)
		if (aa[i - 1] < aa[i]) {
			p = -1;
			break;
		}
	first = 1;
}

int max_towers(int l, int r, int d) {
	if (p != -1)
		return l < p && p < r && aa[p] - aa[l] >= d && aa[p] - aa[r] >= d ? 2 : 1;
	else {
		if (first) {
			cnt = 0;
			ii[cnt++] = 0;
			for (int i = 1; i < n; i++)
				if (cnt % 2 != 0) {
					if (aa[ii[cnt - 1]] > aa[i])
						ii[cnt - 1] = i;
					else if (aa[i] - aa[ii[cnt - 1]] >= d)
						ii[cnt++] = i;
				} else {
					if (aa[ii[cnt - 1]] < aa[i])
						ii[cnt - 1] = i;
					else if (aa[ii[cnt - 1]] - aa[i] >= d)
						ii[cnt++] = i;
				}
			for (int h = 1; h < cnt - 1; h += 2) {
				for (int i = ii[h] - 1; i >= 0; i--)
					if (aa[ii[h]] - aa[i] >= d) {
						ll[h / 2] = i;
						break;
					}
				for (int i = ii[h] + 1; i < n; i++)
					if (aa[ii[h]] - aa[i] >= d) {
						rr[h / 2] = i;
						break;
					}
			}
			cnt = (cnt - 1) / 2;
			first = 0;
		}
		int lower, upper;
		lower = -1, upper = cnt;
		while (upper - lower > 1) {
			int h = (lower + upper) / 2;
			if (l <= ll[h])
				upper = h;
			else
				lower = h;
		}
		l = upper;
		lower = -1, upper = cnt;
		while (upper - lower > 1) {
			int h = (lower + upper) / 2;
			if (rr[h] <= r)
				lower = h;
			else
				upper = h;
		}
		r = lower;
		return max(r - l + 1, 0) + 1;
	}
}
# Verdict Execution time Memory Grader output
1 Correct 256 ms 912 KB Output is correct
2 Correct 870 ms 1320 KB Output is correct
3 Correct 886 ms 1440 KB Output is correct
4 Correct 753 ms 1448 KB Output is correct
5 Correct 900 ms 1352 KB Output is correct
6 Correct 830 ms 1432 KB Output is correct
7 Correct 624 ms 1360 KB Output is correct
8 Correct 0 ms 208 KB Output is correct
9 Correct 1 ms 208 KB Output is correct
10 Correct 0 ms 208 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 208 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 208 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 1 ms 208 KB Output is correct
6 Correct 1 ms 208 KB Output is correct
7 Correct 1 ms 208 KB Output is correct
8 Correct 1 ms 208 KB Output is correct
9 Correct 1 ms 208 KB Output is correct
10 Correct 1 ms 208 KB Output is correct
11 Correct 1 ms 208 KB Output is correct
12 Correct 0 ms 208 KB Output is correct
13 Correct 0 ms 208 KB Output is correct
14 Correct 0 ms 208 KB Output is correct
15 Correct 1 ms 336 KB Output is correct
16 Correct 1 ms 336 KB Output is correct
17 Correct 1 ms 336 KB Output is correct
18 Correct 1 ms 208 KB Output is correct
19 Correct 1 ms 208 KB Output is correct
20 Correct 1 ms 336 KB Output is correct
21 Correct 1 ms 336 KB Output is correct
22 Correct 1 ms 336 KB Output is correct
23 Correct 1 ms 208 KB Output is correct
24 Correct 1 ms 356 KB Output is correct
25 Correct 1 ms 208 KB Output is correct
26 Correct 1 ms 208 KB Output is correct
27 Correct 0 ms 208 KB Output is correct
28 Correct 1 ms 208 KB Output is correct
29 Correct 0 ms 336 KB Output is correct
30 Correct 1 ms 336 KB Output is correct
31 Correct 1 ms 336 KB Output is correct
32 Correct 1 ms 208 KB Output is correct
33 Correct 0 ms 208 KB Output is correct
34 Correct 1 ms 208 KB Output is correct
35 Correct 0 ms 208 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 208 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 208 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 1 ms 208 KB Output is correct
6 Correct 1 ms 208 KB Output is correct
7 Correct 1 ms 208 KB Output is correct
8 Correct 1 ms 208 KB Output is correct
9 Correct 1 ms 208 KB Output is correct
10 Correct 1 ms 208 KB Output is correct
11 Correct 1 ms 208 KB Output is correct
12 Correct 0 ms 208 KB Output is correct
13 Correct 0 ms 208 KB Output is correct
14 Correct 0 ms 208 KB Output is correct
15 Correct 1 ms 336 KB Output is correct
16 Correct 1 ms 336 KB Output is correct
17 Correct 1 ms 336 KB Output is correct
18 Correct 1 ms 208 KB Output is correct
19 Correct 1 ms 208 KB Output is correct
20 Correct 1 ms 336 KB Output is correct
21 Correct 1 ms 336 KB Output is correct
22 Correct 1 ms 336 KB Output is correct
23 Correct 1 ms 208 KB Output is correct
24 Correct 1 ms 356 KB Output is correct
25 Correct 1 ms 208 KB Output is correct
26 Correct 1 ms 208 KB Output is correct
27 Correct 0 ms 208 KB Output is correct
28 Correct 1 ms 208 KB Output is correct
29 Correct 0 ms 336 KB Output is correct
30 Correct 1 ms 336 KB Output is correct
31 Correct 1 ms 336 KB Output is correct
32 Correct 1 ms 208 KB Output is correct
33 Correct 0 ms 208 KB Output is correct
34 Correct 1 ms 208 KB Output is correct
35 Correct 0 ms 208 KB Output is correct
36 Correct 13 ms 1056 KB Output is correct
37 Correct 16 ms 1436 KB Output is correct
38 Correct 14 ms 1440 KB Output is correct
39 Correct 14 ms 1456 KB Output is correct
40 Correct 14 ms 1704 KB Output is correct
41 Correct 17 ms 1444 KB Output is correct
42 Correct 12 ms 1828 KB Output is correct
43 Correct 12 ms 1360 KB Output is correct
44 Correct 13 ms 1444 KB Output is correct
45 Correct 17 ms 1432 KB Output is correct
46 Correct 19 ms 1432 KB Output is correct
47 Correct 14 ms 1564 KB Output is correct
48 Correct 13 ms 1840 KB Output is correct
49 Correct 16 ms 1728 KB Output is correct
50 Correct 12 ms 1444 KB Output is correct
51 Correct 19 ms 1352 KB Output is correct
52 Correct 21 ms 1560 KB Output is correct
53 Correct 14 ms 1808 KB Output is correct
54 Correct 13 ms 1856 KB Output is correct
55 Correct 14 ms 1440 KB Output is correct
56 Correct 14 ms 1352 KB Output is correct
57 Correct 13 ms 1312 KB Output is correct
58 Correct 15 ms 1444 KB Output is correct
59 Correct 15 ms 1424 KB Output is correct
60 Correct 12 ms 1824 KB Output is correct
61 Correct 21 ms 1700 KB Output is correct
62 Correct 21 ms 1432 KB Output is correct
63 Correct 22 ms 1688 KB Output is correct
64 Correct 13 ms 1448 KB Output is correct
65 Correct 19 ms 1440 KB Output is correct
66 Correct 18 ms 1444 KB Output is correct
67 Correct 12 ms 1352 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 614 ms 1484 KB Output is correct
2 Correct 998 ms 1556 KB Output is correct
3 Correct 1000 ms 1568 KB Output is correct
4 Correct 549 ms 1864 KB Output is correct
5 Correct 885 ms 1812 KB Output is correct
6 Correct 832 ms 1816 KB Output is correct
7 Correct 797 ms 1864 KB Output is correct
8 Correct 673 ms 1444 KB Output is correct
9 Correct 886 ms 1444 KB Output is correct
10 Correct 808 ms 1464 KB Output is correct
11 Correct 808 ms 1432 KB Output is correct
12 Correct 612 ms 1432 KB Output is correct
13 Correct 798 ms 1436 KB Output is correct
14 Correct 0 ms 208 KB Output is correct
15 Correct 1 ms 208 KB Output is correct
16 Correct 1 ms 208 KB Output is correct
17 Correct 13 ms 1556 KB Output is correct
18 Correct 13 ms 1856 KB Output is correct
19 Correct 14 ms 1820 KB Output is correct
20 Correct 11 ms 1444 KB Output is correct
21 Correct 12 ms 1360 KB Output is correct
22 Correct 12 ms 1552 KB Output is correct
23 Correct 13 ms 1812 KB Output is correct
24 Correct 18 ms 1888 KB Output is correct
25 Correct 13 ms 1432 KB Output is correct
26 Correct 12 ms 1440 KB Output is correct
27 Correct 1 ms 336 KB Output is correct
28 Correct 0 ms 336 KB Output is correct
29 Correct 0 ms 336 KB Output is correct
30 Correct 0 ms 208 KB Output is correct
31 Correct 1 ms 208 KB Output is correct
32 Correct 1 ms 208 KB Output is correct
33 Correct 1 ms 336 KB Output is correct
34 Correct 0 ms 336 KB Output is correct
35 Correct 1 ms 208 KB Output is correct
36 Correct 1 ms 208 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 295 ms 640 KB 2nd lines differ - on the 1st token, expected: '7063', found: '7197'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 208 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 208 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 1 ms 208 KB Output is correct
6 Correct 1 ms 208 KB Output is correct
7 Correct 1 ms 208 KB Output is correct
8 Correct 1 ms 208 KB Output is correct
9 Correct 1 ms 208 KB Output is correct
10 Correct 1 ms 208 KB Output is correct
11 Correct 1 ms 208 KB Output is correct
12 Correct 0 ms 208 KB Output is correct
13 Correct 0 ms 208 KB Output is correct
14 Correct 0 ms 208 KB Output is correct
15 Correct 1 ms 336 KB Output is correct
16 Correct 1 ms 336 KB Output is correct
17 Correct 1 ms 336 KB Output is correct
18 Correct 1 ms 208 KB Output is correct
19 Correct 1 ms 208 KB Output is correct
20 Correct 1 ms 336 KB Output is correct
21 Correct 1 ms 336 KB Output is correct
22 Correct 1 ms 336 KB Output is correct
23 Correct 1 ms 208 KB Output is correct
24 Correct 1 ms 356 KB Output is correct
25 Correct 1 ms 208 KB Output is correct
26 Correct 1 ms 208 KB Output is correct
27 Correct 0 ms 208 KB Output is correct
28 Correct 1 ms 208 KB Output is correct
29 Correct 0 ms 336 KB Output is correct
30 Correct 1 ms 336 KB Output is correct
31 Correct 1 ms 336 KB Output is correct
32 Correct 1 ms 208 KB Output is correct
33 Correct 0 ms 208 KB Output is correct
34 Correct 1 ms 208 KB Output is correct
35 Correct 0 ms 208 KB Output is correct
36 Correct 13 ms 1056 KB Output is correct
37 Correct 16 ms 1436 KB Output is correct
38 Correct 14 ms 1440 KB Output is correct
39 Correct 14 ms 1456 KB Output is correct
40 Correct 14 ms 1704 KB Output is correct
41 Correct 17 ms 1444 KB Output is correct
42 Correct 12 ms 1828 KB Output is correct
43 Correct 12 ms 1360 KB Output is correct
44 Correct 13 ms 1444 KB Output is correct
45 Correct 17 ms 1432 KB Output is correct
46 Correct 19 ms 1432 KB Output is correct
47 Correct 14 ms 1564 KB Output is correct
48 Correct 13 ms 1840 KB Output is correct
49 Correct 16 ms 1728 KB Output is correct
50 Correct 12 ms 1444 KB Output is correct
51 Correct 19 ms 1352 KB Output is correct
52 Correct 21 ms 1560 KB Output is correct
53 Correct 14 ms 1808 KB Output is correct
54 Correct 13 ms 1856 KB Output is correct
55 Correct 14 ms 1440 KB Output is correct
56 Correct 14 ms 1352 KB Output is correct
57 Correct 13 ms 1312 KB Output is correct
58 Correct 15 ms 1444 KB Output is correct
59 Correct 15 ms 1424 KB Output is correct
60 Correct 12 ms 1824 KB Output is correct
61 Correct 21 ms 1700 KB Output is correct
62 Correct 21 ms 1432 KB Output is correct
63 Correct 22 ms 1688 KB Output is correct
64 Correct 13 ms 1448 KB Output is correct
65 Correct 19 ms 1440 KB Output is correct
66 Correct 18 ms 1444 KB Output is correct
67 Correct 12 ms 1352 KB Output is correct
68 Correct 614 ms 1484 KB Output is correct
69 Correct 998 ms 1556 KB Output is correct
70 Correct 1000 ms 1568 KB Output is correct
71 Correct 549 ms 1864 KB Output is correct
72 Correct 885 ms 1812 KB Output is correct
73 Correct 832 ms 1816 KB Output is correct
74 Correct 797 ms 1864 KB Output is correct
75 Correct 673 ms 1444 KB Output is correct
76 Correct 886 ms 1444 KB Output is correct
77 Correct 808 ms 1464 KB Output is correct
78 Correct 808 ms 1432 KB Output is correct
79 Correct 612 ms 1432 KB Output is correct
80 Correct 798 ms 1436 KB Output is correct
81 Correct 0 ms 208 KB Output is correct
82 Correct 1 ms 208 KB Output is correct
83 Correct 1 ms 208 KB Output is correct
84 Correct 13 ms 1556 KB Output is correct
85 Correct 13 ms 1856 KB Output is correct
86 Correct 14 ms 1820 KB Output is correct
87 Correct 11 ms 1444 KB Output is correct
88 Correct 12 ms 1360 KB Output is correct
89 Correct 12 ms 1552 KB Output is correct
90 Correct 13 ms 1812 KB Output is correct
91 Correct 18 ms 1888 KB Output is correct
92 Correct 13 ms 1432 KB Output is correct
93 Correct 12 ms 1440 KB Output is correct
94 Correct 1 ms 336 KB Output is correct
95 Correct 0 ms 336 KB Output is correct
96 Correct 0 ms 336 KB Output is correct
97 Correct 0 ms 208 KB Output is correct
98 Correct 1 ms 208 KB Output is correct
99 Correct 1 ms 208 KB Output is correct
100 Correct 1 ms 336 KB Output is correct
101 Correct 0 ms 336 KB Output is correct
102 Correct 1 ms 208 KB Output is correct
103 Correct 1 ms 208 KB Output is correct
104 Correct 768 ms 1396 KB Output is correct
105 Correct 874 ms 1352 KB Output is correct
106 Correct 717 ms 1440 KB Output is correct
107 Correct 801 ms 1480 KB Output is correct
108 Correct 912 ms 1360 KB Output is correct
109 Correct 796 ms 1440 KB Output is correct
110 Correct 764 ms 1828 KB Output is correct
111 Correct 757 ms 1360 KB Output is correct
112 Correct 810 ms 1568 KB Output is correct
113 Correct 722 ms 1444 KB Output is correct
114 Correct 830 ms 1568 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 256 ms 912 KB Output is correct
2 Correct 870 ms 1320 KB Output is correct
3 Correct 886 ms 1440 KB Output is correct
4 Correct 753 ms 1448 KB Output is correct
5 Correct 900 ms 1352 KB Output is correct
6 Correct 830 ms 1432 KB Output is correct
7 Correct 624 ms 1360 KB Output is correct
8 Correct 0 ms 208 KB Output is correct
9 Correct 1 ms 208 KB Output is correct
10 Correct 0 ms 208 KB Output is correct
11 Correct 0 ms 208 KB Output is correct
12 Correct 1 ms 336 KB Output is correct
13 Correct 1 ms 208 KB Output is correct
14 Correct 1 ms 336 KB Output is correct
15 Correct 1 ms 208 KB Output is correct
16 Correct 1 ms 208 KB Output is correct
17 Correct 1 ms 208 KB Output is correct
18 Correct 1 ms 208 KB Output is correct
19 Correct 1 ms 208 KB Output is correct
20 Correct 1 ms 208 KB Output is correct
21 Correct 1 ms 208 KB Output is correct
22 Correct 0 ms 208 KB Output is correct
23 Correct 0 ms 208 KB Output is correct
24 Correct 0 ms 208 KB Output is correct
25 Correct 1 ms 336 KB Output is correct
26 Correct 1 ms 336 KB Output is correct
27 Correct 1 ms 336 KB Output is correct
28 Correct 1 ms 208 KB Output is correct
29 Correct 1 ms 208 KB Output is correct
30 Correct 1 ms 336 KB Output is correct
31 Correct 1 ms 336 KB Output is correct
32 Correct 1 ms 336 KB Output is correct
33 Correct 1 ms 208 KB Output is correct
34 Correct 1 ms 356 KB Output is correct
35 Correct 1 ms 208 KB Output is correct
36 Correct 1 ms 208 KB Output is correct
37 Correct 0 ms 208 KB Output is correct
38 Correct 1 ms 208 KB Output is correct
39 Correct 0 ms 336 KB Output is correct
40 Correct 1 ms 336 KB Output is correct
41 Correct 1 ms 336 KB Output is correct
42 Correct 1 ms 208 KB Output is correct
43 Correct 0 ms 208 KB Output is correct
44 Correct 1 ms 208 KB Output is correct
45 Correct 0 ms 208 KB Output is correct
46 Correct 13 ms 1056 KB Output is correct
47 Correct 16 ms 1436 KB Output is correct
48 Correct 14 ms 1440 KB Output is correct
49 Correct 14 ms 1456 KB Output is correct
50 Correct 14 ms 1704 KB Output is correct
51 Correct 17 ms 1444 KB Output is correct
52 Correct 12 ms 1828 KB Output is correct
53 Correct 12 ms 1360 KB Output is correct
54 Correct 13 ms 1444 KB Output is correct
55 Correct 17 ms 1432 KB Output is correct
56 Correct 19 ms 1432 KB Output is correct
57 Correct 14 ms 1564 KB Output is correct
58 Correct 13 ms 1840 KB Output is correct
59 Correct 16 ms 1728 KB Output is correct
60 Correct 12 ms 1444 KB Output is correct
61 Correct 19 ms 1352 KB Output is correct
62 Correct 21 ms 1560 KB Output is correct
63 Correct 14 ms 1808 KB Output is correct
64 Correct 13 ms 1856 KB Output is correct
65 Correct 14 ms 1440 KB Output is correct
66 Correct 14 ms 1352 KB Output is correct
67 Correct 13 ms 1312 KB Output is correct
68 Correct 15 ms 1444 KB Output is correct
69 Correct 15 ms 1424 KB Output is correct
70 Correct 12 ms 1824 KB Output is correct
71 Correct 21 ms 1700 KB Output is correct
72 Correct 21 ms 1432 KB Output is correct
73 Correct 22 ms 1688 KB Output is correct
74 Correct 13 ms 1448 KB Output is correct
75 Correct 19 ms 1440 KB Output is correct
76 Correct 18 ms 1444 KB Output is correct
77 Correct 12 ms 1352 KB Output is correct
78 Correct 614 ms 1484 KB Output is correct
79 Correct 998 ms 1556 KB Output is correct
80 Correct 1000 ms 1568 KB Output is correct
81 Correct 549 ms 1864 KB Output is correct
82 Correct 885 ms 1812 KB Output is correct
83 Correct 832 ms 1816 KB Output is correct
84 Correct 797 ms 1864 KB Output is correct
85 Correct 673 ms 1444 KB Output is correct
86 Correct 886 ms 1444 KB Output is correct
87 Correct 808 ms 1464 KB Output is correct
88 Correct 808 ms 1432 KB Output is correct
89 Correct 612 ms 1432 KB Output is correct
90 Correct 798 ms 1436 KB Output is correct
91 Correct 0 ms 208 KB Output is correct
92 Correct 1 ms 208 KB Output is correct
93 Correct 1 ms 208 KB Output is correct
94 Correct 13 ms 1556 KB Output is correct
95 Correct 13 ms 1856 KB Output is correct
96 Correct 14 ms 1820 KB Output is correct
97 Correct 11 ms 1444 KB Output is correct
98 Correct 12 ms 1360 KB Output is correct
99 Correct 12 ms 1552 KB Output is correct
100 Correct 13 ms 1812 KB Output is correct
101 Correct 18 ms 1888 KB Output is correct
102 Correct 13 ms 1432 KB Output is correct
103 Correct 12 ms 1440 KB Output is correct
104 Correct 1 ms 336 KB Output is correct
105 Correct 0 ms 336 KB Output is correct
106 Correct 0 ms 336 KB Output is correct
107 Correct 0 ms 208 KB Output is correct
108 Correct 1 ms 208 KB Output is correct
109 Correct 1 ms 208 KB Output is correct
110 Correct 1 ms 336 KB Output is correct
111 Correct 0 ms 336 KB Output is correct
112 Correct 1 ms 208 KB Output is correct
113 Correct 1 ms 208 KB Output is correct
114 Incorrect 295 ms 640 KB 2nd lines differ - on the 1st token, expected: '7063', found: '7197'
115 Halted 0 ms 0 KB -