답안 #628588

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
628588 2022-08-13T14:06:33 Z dqhungdl 송신탑 (IOI22_towers) C++17
41 / 100
4000 ms 11240 KB
#include "towers.h"
#include <bits/stdc++.h>
using namespace std;

const int MAX = 1e5 + 5;
int N, lg[MAX], peaks[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 i = 1; i < N - 1; i++)
        peaks[i] = peaks[i - 1] + (H[i] > max(H[i - 1], H[i + 1]));
    peaks[N - 1] = peaks[N - 2];
    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;
    if (D == 1)
        return max(peaks[R - 1] - peaks[L], 0) + 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;
//}
# 결과 실행 시간 메모리 Grader output
1 Correct 410 ms 6096 KB Output is correct
2 Correct 719 ms 10056 KB Output is correct
3 Correct 709 ms 10064 KB Output is correct
4 Correct 839 ms 9988 KB Output is correct
5 Correct 663 ms 10064 KB Output is correct
6 Correct 638 ms 10056 KB Output is correct
7 Correct 672 ms 10020 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
# 결과 실행 시간 메모리 Grader output
1 Correct 0 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 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 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 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 492 KB Output is correct
35 Correct 1 ms 464 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 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 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 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 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 492 KB Output is correct
35 Correct 1 ms 464 KB Output is correct
36 Correct 16 ms 6608 KB Output is correct
37 Correct 26 ms 10216 KB Output is correct
38 Correct 23 ms 10028 KB Output is correct
39 Correct 25 ms 10132 KB Output is correct
40 Correct 23 ms 10024 KB Output is correct
41 Correct 35 ms 10916 KB Output is correct
42 Correct 22 ms 10044 KB Output is correct
43 Correct 22 ms 10032 KB Output is correct
44 Correct 22 ms 10064 KB Output is correct
45 Correct 29 ms 10024 KB Output is correct
46 Correct 21 ms 10064 KB Output is correct
47 Correct 21 ms 10028 KB Output is correct
48 Correct 23 ms 10024 KB Output is correct
49 Correct 22 ms 10064 KB Output is correct
50 Correct 29 ms 10056 KB Output is correct
51 Correct 22 ms 10064 KB Output is correct
52 Correct 22 ms 10028 KB Output is correct
53 Correct 24 ms 10064 KB Output is correct
54 Correct 32 ms 10140 KB Output is correct
55 Correct 22 ms 10024 KB Output is correct
56 Correct 21 ms 10036 KB Output is correct
57 Correct 39 ms 10784 KB Output is correct
58 Correct 49 ms 11216 KB Output is correct
59 Correct 42 ms 11232 KB Output is correct
60 Correct 46 ms 11136 KB Output is correct
61 Correct 49 ms 11224 KB Output is correct
62 Correct 54 ms 11240 KB Output is correct
63 Correct 43 ms 11232 KB Output is correct
64 Correct 23 ms 10056 KB Output is correct
65 Correct 22 ms 10024 KB Output is correct
66 Correct 37 ms 11240 KB Output is correct
67 Correct 34 ms 11156 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 694 ms 9892 KB Output is correct
2 Correct 712 ms 10060 KB Output is correct
3 Correct 743 ms 10024 KB Output is correct
4 Correct 818 ms 10064 KB Output is correct
5 Correct 506 ms 10024 KB Output is correct
6 Correct 597 ms 10020 KB Output is correct
7 Correct 652 ms 10000 KB Output is correct
8 Correct 797 ms 10012 KB Output is correct
9 Correct 911 ms 10056 KB Output is correct
10 Correct 791 ms 10020 KB Output is correct
11 Correct 684 ms 10080 KB Output is correct
12 Correct 882 ms 10064 KB Output is correct
13 Correct 683 ms 10024 KB Output is correct
14 Correct 0 ms 208 KB Output is correct
15 Correct 1 ms 464 KB Output is correct
16 Correct 1 ms 464 KB Output is correct
17 Correct 22 ms 10036 KB Output is correct
18 Correct 22 ms 10156 KB Output is correct
19 Correct 22 ms 10024 KB Output is correct
20 Correct 24 ms 10064 KB Output is correct
21 Correct 23 ms 10028 KB Output is correct
22 Correct 22 ms 10020 KB Output is correct
23 Correct 21 ms 9960 KB Output is correct
24 Correct 24 ms 10036 KB Output is correct
25 Correct 30 ms 10040 KB Output is correct
26 Correct 22 ms 10044 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 1 ms 464 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 4098 ms 3116 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 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 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 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 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 492 KB Output is correct
35 Correct 1 ms 464 KB Output is correct
36 Correct 16 ms 6608 KB Output is correct
37 Correct 26 ms 10216 KB Output is correct
38 Correct 23 ms 10028 KB Output is correct
39 Correct 25 ms 10132 KB Output is correct
40 Correct 23 ms 10024 KB Output is correct
41 Correct 35 ms 10916 KB Output is correct
42 Correct 22 ms 10044 KB Output is correct
43 Correct 22 ms 10032 KB Output is correct
44 Correct 22 ms 10064 KB Output is correct
45 Correct 29 ms 10024 KB Output is correct
46 Correct 21 ms 10064 KB Output is correct
47 Correct 21 ms 10028 KB Output is correct
48 Correct 23 ms 10024 KB Output is correct
49 Correct 22 ms 10064 KB Output is correct
50 Correct 29 ms 10056 KB Output is correct
51 Correct 22 ms 10064 KB Output is correct
52 Correct 22 ms 10028 KB Output is correct
53 Correct 24 ms 10064 KB Output is correct
54 Correct 32 ms 10140 KB Output is correct
55 Correct 22 ms 10024 KB Output is correct
56 Correct 21 ms 10036 KB Output is correct
57 Correct 39 ms 10784 KB Output is correct
58 Correct 49 ms 11216 KB Output is correct
59 Correct 42 ms 11232 KB Output is correct
60 Correct 46 ms 11136 KB Output is correct
61 Correct 49 ms 11224 KB Output is correct
62 Correct 54 ms 11240 KB Output is correct
63 Correct 43 ms 11232 KB Output is correct
64 Correct 23 ms 10056 KB Output is correct
65 Correct 22 ms 10024 KB Output is correct
66 Correct 37 ms 11240 KB Output is correct
67 Correct 34 ms 11156 KB Output is correct
68 Correct 694 ms 9892 KB Output is correct
69 Correct 712 ms 10060 KB Output is correct
70 Correct 743 ms 10024 KB Output is correct
71 Correct 818 ms 10064 KB Output is correct
72 Correct 506 ms 10024 KB Output is correct
73 Correct 597 ms 10020 KB Output is correct
74 Correct 652 ms 10000 KB Output is correct
75 Correct 797 ms 10012 KB Output is correct
76 Correct 911 ms 10056 KB Output is correct
77 Correct 791 ms 10020 KB Output is correct
78 Correct 684 ms 10080 KB Output is correct
79 Correct 882 ms 10064 KB Output is correct
80 Correct 683 ms 10024 KB Output is correct
81 Correct 0 ms 208 KB Output is correct
82 Correct 1 ms 464 KB Output is correct
83 Correct 1 ms 464 KB Output is correct
84 Correct 22 ms 10036 KB Output is correct
85 Correct 22 ms 10156 KB Output is correct
86 Correct 22 ms 10024 KB Output is correct
87 Correct 24 ms 10064 KB Output is correct
88 Correct 23 ms 10028 KB Output is correct
89 Correct 22 ms 10020 KB Output is correct
90 Correct 21 ms 9960 KB Output is correct
91 Correct 24 ms 10036 KB Output is correct
92 Correct 30 ms 10040 KB Output is correct
93 Correct 22 ms 10044 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 464 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 4094 ms 10108 KB Time limit exceeded
105 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 410 ms 6096 KB Output is correct
2 Correct 719 ms 10056 KB Output is correct
3 Correct 709 ms 10064 KB Output is correct
4 Correct 839 ms 9988 KB Output is correct
5 Correct 663 ms 10064 KB Output is correct
6 Correct 638 ms 10056 KB Output is correct
7 Correct 672 ms 10020 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 0 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 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 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 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 492 KB Output is correct
45 Correct 1 ms 464 KB Output is correct
46 Correct 16 ms 6608 KB Output is correct
47 Correct 26 ms 10216 KB Output is correct
48 Correct 23 ms 10028 KB Output is correct
49 Correct 25 ms 10132 KB Output is correct
50 Correct 23 ms 10024 KB Output is correct
51 Correct 35 ms 10916 KB Output is correct
52 Correct 22 ms 10044 KB Output is correct
53 Correct 22 ms 10032 KB Output is correct
54 Correct 22 ms 10064 KB Output is correct
55 Correct 29 ms 10024 KB Output is correct
56 Correct 21 ms 10064 KB Output is correct
57 Correct 21 ms 10028 KB Output is correct
58 Correct 23 ms 10024 KB Output is correct
59 Correct 22 ms 10064 KB Output is correct
60 Correct 29 ms 10056 KB Output is correct
61 Correct 22 ms 10064 KB Output is correct
62 Correct 22 ms 10028 KB Output is correct
63 Correct 24 ms 10064 KB Output is correct
64 Correct 32 ms 10140 KB Output is correct
65 Correct 22 ms 10024 KB Output is correct
66 Correct 21 ms 10036 KB Output is correct
67 Correct 39 ms 10784 KB Output is correct
68 Correct 49 ms 11216 KB Output is correct
69 Correct 42 ms 11232 KB Output is correct
70 Correct 46 ms 11136 KB Output is correct
71 Correct 49 ms 11224 KB Output is correct
72 Correct 54 ms 11240 KB Output is correct
73 Correct 43 ms 11232 KB Output is correct
74 Correct 23 ms 10056 KB Output is correct
75 Correct 22 ms 10024 KB Output is correct
76 Correct 37 ms 11240 KB Output is correct
77 Correct 34 ms 11156 KB Output is correct
78 Correct 694 ms 9892 KB Output is correct
79 Correct 712 ms 10060 KB Output is correct
80 Correct 743 ms 10024 KB Output is correct
81 Correct 818 ms 10064 KB Output is correct
82 Correct 506 ms 10024 KB Output is correct
83 Correct 597 ms 10020 KB Output is correct
84 Correct 652 ms 10000 KB Output is correct
85 Correct 797 ms 10012 KB Output is correct
86 Correct 911 ms 10056 KB Output is correct
87 Correct 791 ms 10020 KB Output is correct
88 Correct 684 ms 10080 KB Output is correct
89 Correct 882 ms 10064 KB Output is correct
90 Correct 683 ms 10024 KB Output is correct
91 Correct 0 ms 208 KB Output is correct
92 Correct 1 ms 464 KB Output is correct
93 Correct 1 ms 464 KB Output is correct
94 Correct 22 ms 10036 KB Output is correct
95 Correct 22 ms 10156 KB Output is correct
96 Correct 22 ms 10024 KB Output is correct
97 Correct 24 ms 10064 KB Output is correct
98 Correct 23 ms 10028 KB Output is correct
99 Correct 22 ms 10020 KB Output is correct
100 Correct 21 ms 9960 KB Output is correct
101 Correct 24 ms 10036 KB Output is correct
102 Correct 30 ms 10040 KB Output is correct
103 Correct 22 ms 10044 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 464 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 4098 ms 3116 KB Time limit exceeded
115 Halted 0 ms 0 KB -