Submission #712968

# Submission time Handle Problem Language Result Execution time Memory
712968 2023-03-20T16:43:59 Z t6twotwo Radio Towers (IOI22_towers) C++17
41 / 100
4000 ms 14304 KB
#include "towers.h"
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int N, X = -1;
vector<int> H, pfs, lg;
vector<vector<int>> st;
int query(int l, int r) {
    int k = __lg(r - l);
    return max(st[l][k], st[r - (1 << k)][k]);
}
void init(int _N, vector<int> _H) {
    N = _N;
    H = _H;
    int L = 0, R = N - 1;
    while (L + 1 < N && H[L + 1] > H[L]) L++;
    while (R - 1 >= 0 && H[R - 1] > H[R]) R--;
    if (L == R) X = L;
    pfs.resize(N + 1);
    for (int i = 0; i < N; i++) {
        pfs[i + 1] = pfs[i];
        if ((i == 0 || H[i] < H[i - 1]) && (i == N - 1 || H[i] < H[i + 1])) {
            pfs[i + 1]++;
        }
    }
    int lg = __lg(N);
    st.assign(N, vector<int>(lg + 1));
    for (int i = 0; i < N; i++) {
        st[i][0] = H[i];
    }
    for (int j = 0; j < lg; j++) {
        for (int i = 0; i + (2 << j) <= N; i++) {
            st[i][j + 1] = max(st[i][j], st[i + (1 << j)][j]);
        }
    }
}
int subtask1(int L, int R, int D) {
    if (L < X && X < R && max(H[L], H[R]) <= H[X] - D) {
        return 2;
    } else {
        return 1;
    }
}
int subtask23(int L,int R, int D) {
    R++;
    vector<int> p(R - L);
    iota(p.begin(), p.end(), L);
    sort(p.begin(), p.end(), [&](int i, int j) {
        return H[i] < H[j];
    });
    set<int> s;
    int ans = 0;
    for (int i : p) {
        auto it = s.lower_bound(i);
        if (it != s.begin()) {
            int j = *prev(it);
            if (max(H[i], H[j]) > query(j, i + 1) - D) continue;
        }
        if (it != s.end()) {
            int j = *it;
            if (max(H[i], H[j]) > query(i, j + 1) - D) continue;
        }
        ans++;
        s.insert(i);
    }
    return ans;
}
int subtask4(int L, int R, int D) {
    if (L == R) return 1;
    int ans = pfs[R] - pfs[L + 1];
    if (H[L] < H[L + 1]) ans++;
    if (H[R] < H[R - 1]) ans++;
    return ans;
}
int max_towers(int L, int R, int D) {
    if (X != -1) return subtask1(L, R, D);
    if (D == 1) return subtask4(L, R, D);
    return subtask23(L, R, D);
}
# Verdict Execution time Memory Grader output
1 Correct 427 ms 7248 KB Output is correct
2 Correct 632 ms 11952 KB Output is correct
3 Correct 704 ms 11936 KB Output is correct
4 Correct 758 ms 12028 KB Output is correct
5 Correct 813 ms 11928 KB Output is correct
6 Correct 568 ms 11984 KB Output is correct
7 Correct 510 ms 11932 KB Output is correct
8 Correct 1 ms 208 KB Output is correct
9 Correct 1 ms 464 KB Output is correct
10 Correct 1 ms 464 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 208 KB Output is correct
2 Correct 1 ms 464 KB Output is correct
3 Correct 1 ms 464 KB Output is correct
4 Correct 1 ms 464 KB Output is correct
5 Correct 1 ms 464 KB Output is correct
6 Correct 1 ms 464 KB Output is correct
7 Correct 1 ms 464 KB Output is correct
8 Correct 1 ms 464 KB Output is correct
9 Correct 1 ms 464 KB Output is correct
10 Correct 1 ms 464 KB Output is correct
11 Correct 1 ms 464 KB Output is correct
12 Correct 1 ms 208 KB Output is correct
13 Correct 1 ms 464 KB Output is correct
14 Correct 1 ms 464 KB Output is correct
15 Correct 1 ms 464 KB Output is correct
16 Correct 1 ms 464 KB Output is correct
17 Correct 1 ms 424 KB Output is correct
18 Correct 1 ms 464 KB Output is correct
19 Correct 1 ms 464 KB Output is correct
20 Correct 1 ms 464 KB Output is correct
21 Correct 1 ms 464 KB Output is correct
22 Correct 1 ms 464 KB Output is correct
23 Correct 1 ms 464 KB Output is correct
24 Correct 1 ms 464 KB Output is correct
25 Correct 1 ms 336 KB Output is correct
26 Correct 1 ms 464 KB Output is correct
27 Correct 1 ms 464 KB Output is correct
28 Correct 1 ms 464 KB Output is correct
29 Correct 1 ms 464 KB Output is correct
30 Correct 1 ms 464 KB Output is correct
31 Correct 1 ms 464 KB Output is correct
32 Correct 1 ms 464 KB Output is correct
33 Correct 1 ms 464 KB Output is correct
34 Correct 1 ms 464 KB Output is correct
35 Correct 1 ms 464 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 208 KB Output is correct
2 Correct 1 ms 464 KB Output is correct
3 Correct 1 ms 464 KB Output is correct
4 Correct 1 ms 464 KB Output is correct
5 Correct 1 ms 464 KB Output is correct
6 Correct 1 ms 464 KB Output is correct
7 Correct 1 ms 464 KB Output is correct
8 Correct 1 ms 464 KB Output is correct
9 Correct 1 ms 464 KB Output is correct
10 Correct 1 ms 464 KB Output is correct
11 Correct 1 ms 464 KB Output is correct
12 Correct 1 ms 208 KB Output is correct
13 Correct 1 ms 464 KB Output is correct
14 Correct 1 ms 464 KB Output is correct
15 Correct 1 ms 464 KB Output is correct
16 Correct 1 ms 464 KB Output is correct
17 Correct 1 ms 424 KB Output is correct
18 Correct 1 ms 464 KB Output is correct
19 Correct 1 ms 464 KB Output is correct
20 Correct 1 ms 464 KB Output is correct
21 Correct 1 ms 464 KB Output is correct
22 Correct 1 ms 464 KB Output is correct
23 Correct 1 ms 464 KB Output is correct
24 Correct 1 ms 464 KB Output is correct
25 Correct 1 ms 336 KB Output is correct
26 Correct 1 ms 464 KB Output is correct
27 Correct 1 ms 464 KB Output is correct
28 Correct 1 ms 464 KB Output is correct
29 Correct 1 ms 464 KB Output is correct
30 Correct 1 ms 464 KB Output is correct
31 Correct 1 ms 464 KB Output is correct
32 Correct 1 ms 464 KB Output is correct
33 Correct 1 ms 464 KB Output is correct
34 Correct 1 ms 464 KB Output is correct
35 Correct 1 ms 464 KB Output is correct
36 Correct 21 ms 7976 KB Output is correct
37 Correct 38 ms 11964 KB Output is correct
38 Correct 32 ms 11984 KB Output is correct
39 Correct 33 ms 11984 KB Output is correct
40 Correct 32 ms 12044 KB Output is correct
41 Correct 54 ms 12752 KB Output is correct
42 Correct 29 ms 11940 KB Output is correct
43 Correct 31 ms 11976 KB Output is correct
44 Correct 29 ms 11976 KB Output is correct
45 Correct 30 ms 11952 KB Output is correct
46 Correct 28 ms 11924 KB Output is correct
47 Correct 36 ms 11932 KB Output is correct
48 Correct 31 ms 11976 KB Output is correct
49 Correct 32 ms 12028 KB Output is correct
50 Correct 29 ms 11976 KB Output is correct
51 Correct 30 ms 12032 KB Output is correct
52 Correct 32 ms 12028 KB Output is correct
53 Correct 29 ms 11952 KB Output is correct
54 Correct 30 ms 11932 KB Output is correct
55 Correct 28 ms 12000 KB Output is correct
56 Correct 28 ms 11964 KB Output is correct
57 Correct 53 ms 12180 KB Output is correct
58 Correct 61 ms 12812 KB Output is correct
59 Correct 66 ms 13120 KB Output is correct
60 Correct 71 ms 14304 KB Output is correct
61 Correct 68 ms 13908 KB Output is correct
62 Correct 70 ms 13304 KB Output is correct
63 Correct 76 ms 13952 KB Output is correct
64 Correct 29 ms 12032 KB Output is correct
65 Correct 28 ms 11984 KB Output is correct
66 Correct 35 ms 11936 KB Output is correct
67 Correct 37 ms 12036 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 635 ms 11840 KB Output is correct
2 Correct 852 ms 11984 KB Output is correct
3 Correct 749 ms 11984 KB Output is correct
4 Correct 707 ms 11948 KB Output is correct
5 Correct 878 ms 11984 KB Output is correct
6 Correct 796 ms 12024 KB Output is correct
7 Correct 992 ms 11948 KB Output is correct
8 Correct 906 ms 12028 KB Output is correct
9 Correct 864 ms 11920 KB Output is correct
10 Correct 961 ms 11928 KB Output is correct
11 Correct 954 ms 11976 KB Output is correct
12 Correct 784 ms 11952 KB Output is correct
13 Correct 895 ms 12028 KB Output is correct
14 Correct 0 ms 208 KB Output is correct
15 Correct 1 ms 464 KB Output is correct
16 Correct 2 ms 464 KB Output is correct
17 Correct 41 ms 11936 KB Output is correct
18 Correct 29 ms 11932 KB Output is correct
19 Correct 28 ms 11976 KB Output is correct
20 Correct 31 ms 11936 KB Output is correct
21 Correct 29 ms 11920 KB Output is correct
22 Correct 41 ms 11920 KB Output is correct
23 Correct 30 ms 11928 KB Output is correct
24 Correct 30 ms 11944 KB Output is correct
25 Correct 29 ms 11976 KB Output is correct
26 Correct 28 ms 11976 KB Output is correct
27 Correct 1 ms 464 KB Output is correct
28 Correct 1 ms 464 KB Output is correct
29 Correct 1 ms 464 KB Output is correct
30 Correct 1 ms 464 KB Output is correct
31 Correct 1 ms 464 KB Output is correct
32 Correct 1 ms 464 KB Output is correct
33 Correct 1 ms 492 KB Output is correct
34 Correct 1 ms 464 KB Output is correct
35 Correct 1 ms 464 KB Output is correct
36 Correct 1 ms 464 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 4003 ms 3500 KB Time limit exceeded
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 464 KB Output is correct
3 Correct 1 ms 464 KB Output is correct
4 Correct 1 ms 464 KB Output is correct
5 Correct 1 ms 464 KB Output is correct
6 Correct 1 ms 464 KB Output is correct
7 Correct 1 ms 464 KB Output is correct
8 Correct 1 ms 464 KB Output is correct
9 Correct 1 ms 464 KB Output is correct
10 Correct 1 ms 464 KB Output is correct
11 Correct 1 ms 464 KB Output is correct
12 Correct 1 ms 208 KB Output is correct
13 Correct 1 ms 464 KB Output is correct
14 Correct 1 ms 464 KB Output is correct
15 Correct 1 ms 464 KB Output is correct
16 Correct 1 ms 464 KB Output is correct
17 Correct 1 ms 424 KB Output is correct
18 Correct 1 ms 464 KB Output is correct
19 Correct 1 ms 464 KB Output is correct
20 Correct 1 ms 464 KB Output is correct
21 Correct 1 ms 464 KB Output is correct
22 Correct 1 ms 464 KB Output is correct
23 Correct 1 ms 464 KB Output is correct
24 Correct 1 ms 464 KB Output is correct
25 Correct 1 ms 336 KB Output is correct
26 Correct 1 ms 464 KB Output is correct
27 Correct 1 ms 464 KB Output is correct
28 Correct 1 ms 464 KB Output is correct
29 Correct 1 ms 464 KB Output is correct
30 Correct 1 ms 464 KB Output is correct
31 Correct 1 ms 464 KB Output is correct
32 Correct 1 ms 464 KB Output is correct
33 Correct 1 ms 464 KB Output is correct
34 Correct 1 ms 464 KB Output is correct
35 Correct 1 ms 464 KB Output is correct
36 Correct 21 ms 7976 KB Output is correct
37 Correct 38 ms 11964 KB Output is correct
38 Correct 32 ms 11984 KB Output is correct
39 Correct 33 ms 11984 KB Output is correct
40 Correct 32 ms 12044 KB Output is correct
41 Correct 54 ms 12752 KB Output is correct
42 Correct 29 ms 11940 KB Output is correct
43 Correct 31 ms 11976 KB Output is correct
44 Correct 29 ms 11976 KB Output is correct
45 Correct 30 ms 11952 KB Output is correct
46 Correct 28 ms 11924 KB Output is correct
47 Correct 36 ms 11932 KB Output is correct
48 Correct 31 ms 11976 KB Output is correct
49 Correct 32 ms 12028 KB Output is correct
50 Correct 29 ms 11976 KB Output is correct
51 Correct 30 ms 12032 KB Output is correct
52 Correct 32 ms 12028 KB Output is correct
53 Correct 29 ms 11952 KB Output is correct
54 Correct 30 ms 11932 KB Output is correct
55 Correct 28 ms 12000 KB Output is correct
56 Correct 28 ms 11964 KB Output is correct
57 Correct 53 ms 12180 KB Output is correct
58 Correct 61 ms 12812 KB Output is correct
59 Correct 66 ms 13120 KB Output is correct
60 Correct 71 ms 14304 KB Output is correct
61 Correct 68 ms 13908 KB Output is correct
62 Correct 70 ms 13304 KB Output is correct
63 Correct 76 ms 13952 KB Output is correct
64 Correct 29 ms 12032 KB Output is correct
65 Correct 28 ms 11984 KB Output is correct
66 Correct 35 ms 11936 KB Output is correct
67 Correct 37 ms 12036 KB Output is correct
68 Correct 635 ms 11840 KB Output is correct
69 Correct 852 ms 11984 KB Output is correct
70 Correct 749 ms 11984 KB Output is correct
71 Correct 707 ms 11948 KB Output is correct
72 Correct 878 ms 11984 KB Output is correct
73 Correct 796 ms 12024 KB Output is correct
74 Correct 992 ms 11948 KB Output is correct
75 Correct 906 ms 12028 KB Output is correct
76 Correct 864 ms 11920 KB Output is correct
77 Correct 961 ms 11928 KB Output is correct
78 Correct 954 ms 11976 KB Output is correct
79 Correct 784 ms 11952 KB Output is correct
80 Correct 895 ms 12028 KB Output is correct
81 Correct 0 ms 208 KB Output is correct
82 Correct 1 ms 464 KB Output is correct
83 Correct 2 ms 464 KB Output is correct
84 Correct 41 ms 11936 KB Output is correct
85 Correct 29 ms 11932 KB Output is correct
86 Correct 28 ms 11976 KB Output is correct
87 Correct 31 ms 11936 KB Output is correct
88 Correct 29 ms 11920 KB Output is correct
89 Correct 41 ms 11920 KB Output is correct
90 Correct 30 ms 11928 KB Output is correct
91 Correct 30 ms 11944 KB Output is correct
92 Correct 29 ms 11976 KB Output is correct
93 Correct 28 ms 11976 KB Output is correct
94 Correct 1 ms 464 KB Output is correct
95 Correct 1 ms 464 KB Output is correct
96 Correct 1 ms 464 KB Output is correct
97 Correct 1 ms 464 KB Output is correct
98 Correct 1 ms 464 KB Output is correct
99 Correct 1 ms 464 KB Output is correct
100 Correct 1 ms 492 KB Output is correct
101 Correct 1 ms 464 KB Output is correct
102 Correct 1 ms 464 KB Output is correct
103 Correct 1 ms 464 KB Output is correct
104 Execution timed out 4025 ms 11840 KB Time limit exceeded
105 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 427 ms 7248 KB Output is correct
2 Correct 632 ms 11952 KB Output is correct
3 Correct 704 ms 11936 KB Output is correct
4 Correct 758 ms 12028 KB Output is correct
5 Correct 813 ms 11928 KB Output is correct
6 Correct 568 ms 11984 KB Output is correct
7 Correct 510 ms 11932 KB Output is correct
8 Correct 1 ms 208 KB Output is correct
9 Correct 1 ms 464 KB Output is correct
10 Correct 1 ms 464 KB Output is correct
11 Correct 0 ms 208 KB Output is correct
12 Correct 1 ms 464 KB Output is correct
13 Correct 1 ms 464 KB Output is correct
14 Correct 1 ms 464 KB Output is correct
15 Correct 1 ms 464 KB Output is correct
16 Correct 1 ms 464 KB Output is correct
17 Correct 1 ms 464 KB Output is correct
18 Correct 1 ms 464 KB Output is correct
19 Correct 1 ms 464 KB Output is correct
20 Correct 1 ms 464 KB Output is correct
21 Correct 1 ms 464 KB Output is correct
22 Correct 1 ms 208 KB Output is correct
23 Correct 1 ms 464 KB Output is correct
24 Correct 1 ms 464 KB Output is correct
25 Correct 1 ms 464 KB Output is correct
26 Correct 1 ms 464 KB Output is correct
27 Correct 1 ms 424 KB Output is correct
28 Correct 1 ms 464 KB Output is correct
29 Correct 1 ms 464 KB Output is correct
30 Correct 1 ms 464 KB Output is correct
31 Correct 1 ms 464 KB Output is correct
32 Correct 1 ms 464 KB Output is correct
33 Correct 1 ms 464 KB Output is correct
34 Correct 1 ms 464 KB Output is correct
35 Correct 1 ms 336 KB Output is correct
36 Correct 1 ms 464 KB Output is correct
37 Correct 1 ms 464 KB Output is correct
38 Correct 1 ms 464 KB Output is correct
39 Correct 1 ms 464 KB Output is correct
40 Correct 1 ms 464 KB Output is correct
41 Correct 1 ms 464 KB Output is correct
42 Correct 1 ms 464 KB Output is correct
43 Correct 1 ms 464 KB Output is correct
44 Correct 1 ms 464 KB Output is correct
45 Correct 1 ms 464 KB Output is correct
46 Correct 21 ms 7976 KB Output is correct
47 Correct 38 ms 11964 KB Output is correct
48 Correct 32 ms 11984 KB Output is correct
49 Correct 33 ms 11984 KB Output is correct
50 Correct 32 ms 12044 KB Output is correct
51 Correct 54 ms 12752 KB Output is correct
52 Correct 29 ms 11940 KB Output is correct
53 Correct 31 ms 11976 KB Output is correct
54 Correct 29 ms 11976 KB Output is correct
55 Correct 30 ms 11952 KB Output is correct
56 Correct 28 ms 11924 KB Output is correct
57 Correct 36 ms 11932 KB Output is correct
58 Correct 31 ms 11976 KB Output is correct
59 Correct 32 ms 12028 KB Output is correct
60 Correct 29 ms 11976 KB Output is correct
61 Correct 30 ms 12032 KB Output is correct
62 Correct 32 ms 12028 KB Output is correct
63 Correct 29 ms 11952 KB Output is correct
64 Correct 30 ms 11932 KB Output is correct
65 Correct 28 ms 12000 KB Output is correct
66 Correct 28 ms 11964 KB Output is correct
67 Correct 53 ms 12180 KB Output is correct
68 Correct 61 ms 12812 KB Output is correct
69 Correct 66 ms 13120 KB Output is correct
70 Correct 71 ms 14304 KB Output is correct
71 Correct 68 ms 13908 KB Output is correct
72 Correct 70 ms 13304 KB Output is correct
73 Correct 76 ms 13952 KB Output is correct
74 Correct 29 ms 12032 KB Output is correct
75 Correct 28 ms 11984 KB Output is correct
76 Correct 35 ms 11936 KB Output is correct
77 Correct 37 ms 12036 KB Output is correct
78 Correct 635 ms 11840 KB Output is correct
79 Correct 852 ms 11984 KB Output is correct
80 Correct 749 ms 11984 KB Output is correct
81 Correct 707 ms 11948 KB Output is correct
82 Correct 878 ms 11984 KB Output is correct
83 Correct 796 ms 12024 KB Output is correct
84 Correct 992 ms 11948 KB Output is correct
85 Correct 906 ms 12028 KB Output is correct
86 Correct 864 ms 11920 KB Output is correct
87 Correct 961 ms 11928 KB Output is correct
88 Correct 954 ms 11976 KB Output is correct
89 Correct 784 ms 11952 KB Output is correct
90 Correct 895 ms 12028 KB Output is correct
91 Correct 0 ms 208 KB Output is correct
92 Correct 1 ms 464 KB Output is correct
93 Correct 2 ms 464 KB Output is correct
94 Correct 41 ms 11936 KB Output is correct
95 Correct 29 ms 11932 KB Output is correct
96 Correct 28 ms 11976 KB Output is correct
97 Correct 31 ms 11936 KB Output is correct
98 Correct 29 ms 11920 KB Output is correct
99 Correct 41 ms 11920 KB Output is correct
100 Correct 30 ms 11928 KB Output is correct
101 Correct 30 ms 11944 KB Output is correct
102 Correct 29 ms 11976 KB Output is correct
103 Correct 28 ms 11976 KB Output is correct
104 Correct 1 ms 464 KB Output is correct
105 Correct 1 ms 464 KB Output is correct
106 Correct 1 ms 464 KB Output is correct
107 Correct 1 ms 464 KB Output is correct
108 Correct 1 ms 464 KB Output is correct
109 Correct 1 ms 464 KB Output is correct
110 Correct 1 ms 492 KB Output is correct
111 Correct 1 ms 464 KB Output is correct
112 Correct 1 ms 464 KB Output is correct
113 Correct 1 ms 464 KB Output is correct
114 Execution timed out 4003 ms 3500 KB Time limit exceeded
115 Halted 0 ms 0 KB -