답안 #628585

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
628585 2022-08-13T14:04:13 Z dqhungdl 송신탑 (IOI22_towers) C++17
27 / 100
4000 ms 11236 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 peaks[R - 1] - peaks[L] + 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 435 ms 6052 KB Output is correct
2 Correct 748 ms 10044 KB Output is correct
3 Correct 897 ms 10028 KB Output is correct
4 Correct 776 ms 10020 KB Output is correct
5 Correct 865 ms 10084 KB Output is correct
6 Correct 748 ms 10020 KB Output is correct
7 Correct 669 ms 10076 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 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 2 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 2 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
# 결과 실행 시간 메모리 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 2 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 2 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 23 ms 6696 KB Output is correct
37 Correct 37 ms 10216 KB Output is correct
38 Correct 23 ms 10028 KB Output is correct
39 Correct 34 ms 10168 KB Output is correct
40 Correct 26 ms 10032 KB Output is correct
41 Correct 37 ms 10964 KB Output is correct
42 Correct 23 ms 10012 KB Output is correct
43 Correct 22 ms 10028 KB Output is correct
44 Correct 25 ms 10076 KB Output is correct
45 Correct 34 ms 10024 KB Output is correct
46 Correct 30 ms 10032 KB Output is correct
47 Correct 21 ms 10044 KB Output is correct
48 Correct 25 ms 10064 KB Output is correct
49 Correct 28 ms 10056 KB Output is correct
50 Correct 31 ms 10024 KB Output is correct
51 Correct 23 ms 10020 KB Output is correct
52 Correct 22 ms 10048 KB Output is correct
53 Correct 28 ms 10044 KB Output is correct
54 Correct 22 ms 10064 KB Output is correct
55 Correct 24 ms 10008 KB Output is correct
56 Correct 24 ms 10076 KB Output is correct
57 Correct 42 ms 10788 KB Output is correct
58 Correct 45 ms 11172 KB Output is correct
59 Correct 45 ms 11236 KB Output is correct
60 Correct 43 ms 11236 KB Output is correct
61 Correct 44 ms 11136 KB Output is correct
62 Correct 47 ms 11200 KB Output is correct
63 Correct 46 ms 11172 KB Output is correct
64 Correct 20 ms 10040 KB Output is correct
65 Correct 22 ms 10056 KB Output is correct
66 Correct 39 ms 11200 KB Output is correct
67 Correct 34 ms 11188 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 563 ms 10016 KB Output is correct
2 Correct 691 ms 10020 KB Output is correct
3 Incorrect 944 ms 10032 KB 18409th lines differ - on the 1st token, expected: '1', found: '0'
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 4038 ms 3112 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 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 2 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 2 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 23 ms 6696 KB Output is correct
37 Correct 37 ms 10216 KB Output is correct
38 Correct 23 ms 10028 KB Output is correct
39 Correct 34 ms 10168 KB Output is correct
40 Correct 26 ms 10032 KB Output is correct
41 Correct 37 ms 10964 KB Output is correct
42 Correct 23 ms 10012 KB Output is correct
43 Correct 22 ms 10028 KB Output is correct
44 Correct 25 ms 10076 KB Output is correct
45 Correct 34 ms 10024 KB Output is correct
46 Correct 30 ms 10032 KB Output is correct
47 Correct 21 ms 10044 KB Output is correct
48 Correct 25 ms 10064 KB Output is correct
49 Correct 28 ms 10056 KB Output is correct
50 Correct 31 ms 10024 KB Output is correct
51 Correct 23 ms 10020 KB Output is correct
52 Correct 22 ms 10048 KB Output is correct
53 Correct 28 ms 10044 KB Output is correct
54 Correct 22 ms 10064 KB Output is correct
55 Correct 24 ms 10008 KB Output is correct
56 Correct 24 ms 10076 KB Output is correct
57 Correct 42 ms 10788 KB Output is correct
58 Correct 45 ms 11172 KB Output is correct
59 Correct 45 ms 11236 KB Output is correct
60 Correct 43 ms 11236 KB Output is correct
61 Correct 44 ms 11136 KB Output is correct
62 Correct 47 ms 11200 KB Output is correct
63 Correct 46 ms 11172 KB Output is correct
64 Correct 20 ms 10040 KB Output is correct
65 Correct 22 ms 10056 KB Output is correct
66 Correct 39 ms 11200 KB Output is correct
67 Correct 34 ms 11188 KB Output is correct
68 Correct 563 ms 10016 KB Output is correct
69 Correct 691 ms 10020 KB Output is correct
70 Incorrect 944 ms 10032 KB 18409th lines differ - on the 1st token, expected: '1', found: '0'
71 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 435 ms 6052 KB Output is correct
2 Correct 748 ms 10044 KB Output is correct
3 Correct 897 ms 10028 KB Output is correct
4 Correct 776 ms 10020 KB Output is correct
5 Correct 865 ms 10084 KB Output is correct
6 Correct 748 ms 10020 KB Output is correct
7 Correct 669 ms 10076 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 2 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 2 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 23 ms 6696 KB Output is correct
47 Correct 37 ms 10216 KB Output is correct
48 Correct 23 ms 10028 KB Output is correct
49 Correct 34 ms 10168 KB Output is correct
50 Correct 26 ms 10032 KB Output is correct
51 Correct 37 ms 10964 KB Output is correct
52 Correct 23 ms 10012 KB Output is correct
53 Correct 22 ms 10028 KB Output is correct
54 Correct 25 ms 10076 KB Output is correct
55 Correct 34 ms 10024 KB Output is correct
56 Correct 30 ms 10032 KB Output is correct
57 Correct 21 ms 10044 KB Output is correct
58 Correct 25 ms 10064 KB Output is correct
59 Correct 28 ms 10056 KB Output is correct
60 Correct 31 ms 10024 KB Output is correct
61 Correct 23 ms 10020 KB Output is correct
62 Correct 22 ms 10048 KB Output is correct
63 Correct 28 ms 10044 KB Output is correct
64 Correct 22 ms 10064 KB Output is correct
65 Correct 24 ms 10008 KB Output is correct
66 Correct 24 ms 10076 KB Output is correct
67 Correct 42 ms 10788 KB Output is correct
68 Correct 45 ms 11172 KB Output is correct
69 Correct 45 ms 11236 KB Output is correct
70 Correct 43 ms 11236 KB Output is correct
71 Correct 44 ms 11136 KB Output is correct
72 Correct 47 ms 11200 KB Output is correct
73 Correct 46 ms 11172 KB Output is correct
74 Correct 20 ms 10040 KB Output is correct
75 Correct 22 ms 10056 KB Output is correct
76 Correct 39 ms 11200 KB Output is correct
77 Correct 34 ms 11188 KB Output is correct
78 Correct 563 ms 10016 KB Output is correct
79 Correct 691 ms 10020 KB Output is correct
80 Incorrect 944 ms 10032 KB 18409th lines differ - on the 1st token, expected: '1', found: '0'
81 Halted 0 ms 0 KB -