Submission #628561

# Submission time Handle Problem Language Result Execution time Memory
628561 2022-08-13T13:34:55 Z dqhungdl Radio Towers (IOI22_towers) C++17
27 / 100
4000 ms 10844 KB
#include "towers.h"
#include <bits/stdc++.h>
using namespace std;

const int MAX = 1e5 + 5;
int N, lg[MAX], maxH[MAX][20];
bool isMountain = true;
vector<int> H;

struct FenwickTree {
    int n;
    vector<int> tree;

    FenwickTree(int _n) {
        n = _n;
        tree.resize(n + 5);
    }

    void update(int idx, int val) {
        idx++;
        for (int i = idx; i <= n; i += i & -i)
            tree[i] = max(tree[i], val);
    }

    int get(int idx) {
        idx++;
        int rs = 0;
        for (int i = idx; i > 0; i -= i & -i)
            rs = max(rs, tree[i]);
        return rs;
    }
};

int get(int l, int r) {
    int k = lg[r - l + 1];
    return max(maxH[l][k], maxH[r - (1 << k) + 1][k]);
}

void init(int _N, vector<int> _H) {
    N = _N, H = _H;
    for (int i = 1; i <= N; i++)
        lg[i] = log2(i);
    for (int i = 0; i < N; i++)
        maxH[i][0] = H[i];
    for (int t = 1; t <= 18; t++)
        for (int i = 0; i + (1 << t) - 1 < N; i++)
            maxH[i][t] = max(maxH[i][t - 1], maxH[i + (1 << (t - 1))][t - 1]);
    int id = max_element(H.begin(), H.end()) - H.begin();
    for (int i = id; i > 0 && isMountain; i--)
        isMountain &= (H[i] > H[i - 1]);
    for (int i = id; i < N - 1 && isMountain; i++)
        isMountain &= (H[i] > H[i + 1]);
}

int max_towers(int L, int R, int D) {
    if (isMountain)
        return get(L, R) - D >= max(H[L], H[R]) ? 2 : 1;
    vector<int> bl(R - L + 1, -1), br(R - L + 1, R - L + 1);
    for (int i = L; i <= R; i++) {
        int l = L, r = i - 1;
        while (l <= r) {
            int mid = (l + r) / 2;
            if (get(mid, i - 1) - D >= H[i]) {
                bl[i - L] = mid - L;
                l = mid + 1;
            } else
                r = mid - 1;
        }
        l = i + 1, r = R;
        while (l <= r) {
            int mid = (l + r) / 2;
            if (get(i + 1, mid) - D >= H[i]) {
                br[i - L] = mid - L;
                r = mid - 1;
            } else
                l = mid + 1;
        }
    }
    vector<int> f(R - L + 1, 1);
    FenwickTree tree(R - L + 1);
    for (int i = 0; i < R - L + 1; i++) {
        if (bl[i] != -1)
            f[i] = tree.get(bl[i]) + 1;
        tree.update(br[i], f[i]);
    }
    return *max_element(f.begin(), f.end());
}

//int main() {
//    freopen("../_input", "r", stdin);
//    int N, Q;
//    assert(2 == scanf("%d %d", &N, &Q));
//    std::vector<int> H(N);
//    for (int i = 0; i < N; ++i) {
//        assert(1 == scanf("%d", &H[i]));
//    }
//    init(N, H);
//
//    for (int i = 0; i < Q; ++i) {
//        int L, R, D;
//        assert(3 == scanf("%d %d %d", &L, &R, &D));
//        printf("%d\n", max_towers(L, R, D));
//    }
//    return 0;
//}
# Verdict Execution time Memory Grader output
1 Correct 387 ms 5840 KB Output is correct
2 Correct 612 ms 9680 KB Output is correct
3 Correct 846 ms 9640 KB Output is correct
4 Correct 1062 ms 9632 KB Output is correct
5 Correct 859 ms 9680 KB Output is correct
6 Correct 744 ms 9656 KB Output is correct
7 Correct 823 ms 9648 KB Output is correct
8 Correct 0 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 1 ms 336 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 2 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 0 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 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 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 420 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 1 ms 336 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 2 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 0 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 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 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 420 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 15 ms 6436 KB Output is correct
37 Correct 33 ms 9804 KB Output is correct
38 Correct 25 ms 9632 KB Output is correct
39 Correct 31 ms 9756 KB Output is correct
40 Correct 22 ms 9588 KB Output is correct
41 Correct 35 ms 10580 KB Output is correct
42 Correct 21 ms 9644 KB Output is correct
43 Correct 24 ms 9672 KB Output is correct
44 Correct 30 ms 9640 KB Output is correct
45 Correct 22 ms 9660 KB Output is correct
46 Correct 21 ms 9640 KB Output is correct
47 Correct 28 ms 9792 KB Output is correct
48 Correct 25 ms 9624 KB Output is correct
49 Correct 25 ms 9672 KB Output is correct
50 Correct 21 ms 9632 KB Output is correct
51 Correct 43 ms 9888 KB Output is correct
52 Correct 53 ms 10816 KB Output is correct
53 Correct 47 ms 10796 KB Output is correct
54 Correct 53 ms 10816 KB Output is correct
55 Correct 23 ms 9640 KB Output is correct
56 Correct 35 ms 10840 KB Output is correct
57 Correct 37 ms 10396 KB Output is correct
58 Correct 45 ms 10832 KB Output is correct
59 Correct 54 ms 10840 KB Output is correct
60 Correct 47 ms 10844 KB Output is correct
61 Correct 44 ms 10840 KB Output is correct
62 Correct 46 ms 10840 KB Output is correct
63 Correct 42 ms 10840 KB Output is correct
64 Correct 23 ms 9652 KB Output is correct
65 Correct 22 ms 9672 KB Output is correct
66 Correct 36 ms 10840 KB Output is correct
67 Correct 41 ms 10780 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 4086 ms 10836 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 4067 ms 3020 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 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 2 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 0 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 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 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 420 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 15 ms 6436 KB Output is correct
37 Correct 33 ms 9804 KB Output is correct
38 Correct 25 ms 9632 KB Output is correct
39 Correct 31 ms 9756 KB Output is correct
40 Correct 22 ms 9588 KB Output is correct
41 Correct 35 ms 10580 KB Output is correct
42 Correct 21 ms 9644 KB Output is correct
43 Correct 24 ms 9672 KB Output is correct
44 Correct 30 ms 9640 KB Output is correct
45 Correct 22 ms 9660 KB Output is correct
46 Correct 21 ms 9640 KB Output is correct
47 Correct 28 ms 9792 KB Output is correct
48 Correct 25 ms 9624 KB Output is correct
49 Correct 25 ms 9672 KB Output is correct
50 Correct 21 ms 9632 KB Output is correct
51 Correct 43 ms 9888 KB Output is correct
52 Correct 53 ms 10816 KB Output is correct
53 Correct 47 ms 10796 KB Output is correct
54 Correct 53 ms 10816 KB Output is correct
55 Correct 23 ms 9640 KB Output is correct
56 Correct 35 ms 10840 KB Output is correct
57 Correct 37 ms 10396 KB Output is correct
58 Correct 45 ms 10832 KB Output is correct
59 Correct 54 ms 10840 KB Output is correct
60 Correct 47 ms 10844 KB Output is correct
61 Correct 44 ms 10840 KB Output is correct
62 Correct 46 ms 10840 KB Output is correct
63 Correct 42 ms 10840 KB Output is correct
64 Correct 23 ms 9652 KB Output is correct
65 Correct 22 ms 9672 KB Output is correct
66 Correct 36 ms 10840 KB Output is correct
67 Correct 41 ms 10780 KB Output is correct
68 Execution timed out 4086 ms 10836 KB Time limit exceeded
69 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 387 ms 5840 KB Output is correct
2 Correct 612 ms 9680 KB Output is correct
3 Correct 846 ms 9640 KB Output is correct
4 Correct 1062 ms 9632 KB Output is correct
5 Correct 859 ms 9680 KB Output is correct
6 Correct 744 ms 9656 KB Output is correct
7 Correct 823 ms 9648 KB Output is correct
8 Correct 0 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 1 ms 336 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 2 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 0 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 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 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 420 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 15 ms 6436 KB Output is correct
47 Correct 33 ms 9804 KB Output is correct
48 Correct 25 ms 9632 KB Output is correct
49 Correct 31 ms 9756 KB Output is correct
50 Correct 22 ms 9588 KB Output is correct
51 Correct 35 ms 10580 KB Output is correct
52 Correct 21 ms 9644 KB Output is correct
53 Correct 24 ms 9672 KB Output is correct
54 Correct 30 ms 9640 KB Output is correct
55 Correct 22 ms 9660 KB Output is correct
56 Correct 21 ms 9640 KB Output is correct
57 Correct 28 ms 9792 KB Output is correct
58 Correct 25 ms 9624 KB Output is correct
59 Correct 25 ms 9672 KB Output is correct
60 Correct 21 ms 9632 KB Output is correct
61 Correct 43 ms 9888 KB Output is correct
62 Correct 53 ms 10816 KB Output is correct
63 Correct 47 ms 10796 KB Output is correct
64 Correct 53 ms 10816 KB Output is correct
65 Correct 23 ms 9640 KB Output is correct
66 Correct 35 ms 10840 KB Output is correct
67 Correct 37 ms 10396 KB Output is correct
68 Correct 45 ms 10832 KB Output is correct
69 Correct 54 ms 10840 KB Output is correct
70 Correct 47 ms 10844 KB Output is correct
71 Correct 44 ms 10840 KB Output is correct
72 Correct 46 ms 10840 KB Output is correct
73 Correct 42 ms 10840 KB Output is correct
74 Correct 23 ms 9652 KB Output is correct
75 Correct 22 ms 9672 KB Output is correct
76 Correct 36 ms 10840 KB Output is correct
77 Correct 41 ms 10780 KB Output is correct
78 Execution timed out 4086 ms 10836 KB Time limit exceeded
79 Halted 0 ms 0 KB -