답안 #489522

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
489522 2021-11-23T04:56:22 Z KienTran Two Antennas (JOI19_antennas) C++14
13 / 100
428 ms 37364 KB
#include <bits/stdc++.h>
#define int long long

using namespace std;

const int O = 2e5 + 5;
const int inf = 1e16;

int n, q, l[O], r[O], h[O], a[O], b[O], res[O], tree[O * 4], Min[O * 4], Max[O * 4];
vector <int> qu[O], in[O], out[O];

int Beauti(int x){
    return max(1ll, x);
}

void Push(int id){
    int &x = Min[id];
    if (x == inf) return;

    for (int i = 2 * id; i <= 2 * id + 1; ++ i){
        Min[i] = min(Min[i], x);
        tree[i] = max(tree[i], Max[i] - Min[i]);
    }

    x = inf; return;
}

void UpdateMax(int id, int l, int r, int u, int x){
    if (l > u || r < u) return;
    if (l == r){
        Max[id] = x;
        Min[id] = inf;
        tree[id] = max(tree[id], Max[id] - Min[id]);
        return;
    }
    int mid = (l + r) / 2; Push(id);
    UpdateMax(id << 1, l, mid, u, x);
    UpdateMax(id << 1 | 1, mid + 1, r, u, x);
    tree[id] = max({tree[id], tree[id << 1], tree[id << 1 | 1]});
    Max[id] = max(Max[id << 1], Max[id << 1 | 1]);
}

void UpdateMin(int id, int l, int r, int u, int v, int x){
    if (l > v || r < u) return;
    if (u <= l && r <= v){
        Min[id] = min(Min[id], x);
        tree[id] = max(tree[id], Max[id] - Min[id]);
        return;
    }
    int mid = (l + r) / 2; Push(id);
    UpdateMin(id << 1, l, mid, u, v, x);
    UpdateMin(id << 1 | 1, mid + 1, r, u, v, x);
    tree[id] = max({tree[id], tree[id << 1], tree[id << 1 | 1], Max[id] - Min[id]});
    Max[id] = max(Max[id << 1], Max[id << 1 | 1]);
}

int Get(int id, int l, int r, int u, int v){
    if (l > v || r < u) return -inf;
    if (u <= l && r <= v) return tree[id];
    int mid = (l + r) / 2; Push(id);
    return max(Get(id << 1, l, mid, u, v), Get(id << 1 | 1, mid + 1, r, u, v));
}

void solve(){
    for (int i = 1; i <= q; ++ i) qu[r[i]].push_back(i);

    for (int i = 1; i < O; ++ i){
        tree[i] = -inf;
        Max[i] = -inf;
        Min[i] = inf;
    }

    for (int i = 1; i <= n; ++ i){
        for (int j : in[i]){
            UpdateMax(1, 1, n, j, h[j]);
        }

        for (int j : out[i]){
            UpdateMax(1, 1, n, j, -inf);
        }

        if (i - a[i] >= 1) UpdateMin(1, 1, n, Beauti(i - b[i]), Beauti(i - a[i]), h[i]);

        for (int j : qu[i]){
            res[j] = max(res[j], Get(1, 1, n, l[j], i));
        }

        if (i + a[i] <= n) in[i + a[i]].push_back(i);
        if (i + b[i] + 1 <= n) out[i + b[i] + 1].push_back(i);
    }

    for (int i = 1; i <= n; ++ i){
        qu[i].clear();
        in[i].clear();
        out[i].clear();
    }

}

main(){
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    cin >> n;
    for (int i = 1; i <= n; ++ i) cin >> h[i] >> a[i] >> b[i];

    cin >> q;
    for (int i = 1; i <= q; ++ i){
        cin >> l[i] >> r[i];
        res[i] = -1;
    }

    solve();

    reverse(h + 1, h + n + 1);
    reverse(a + 1, a + n + 1);
    reverse(b + 1, b + n + 1);

    for (int i = 1; i <= q; ++ i){
        l[i] = n - l[i] + 1;
        r[i] = n - r[i] + 1;
        swap(l[i], r[i]);
    }

    solve();

    for (int i = 1; i <= q; ++ i) cout << res[i] << "\n";
}
/***
5
10 2 4
1 1 1
2 1 3
1 1 1
100 1 1
5
1 2
2 3
1 3
1 4
1 5
***/

Compilation message

antennas.cpp:100:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
  100 | main(){
      | ^~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 13 ms 19276 KB Output is correct
2 Correct 13 ms 19156 KB Output is correct
3 Correct 11 ms 19192 KB Output is correct
4 Correct 13 ms 19184 KB Output is correct
5 Correct 10 ms 19188 KB Output is correct
6 Correct 15 ms 19152 KB Output is correct
7 Correct 10 ms 19156 KB Output is correct
8 Correct 11 ms 19152 KB Output is correct
9 Correct 14 ms 19152 KB Output is correct
10 Correct 10 ms 19084 KB Output is correct
11 Correct 12 ms 19100 KB Output is correct
12 Correct 12 ms 19152 KB Output is correct
13 Correct 11 ms 19152 KB Output is correct
14 Correct 11 ms 19212 KB Output is correct
15 Correct 11 ms 19152 KB Output is correct
16 Correct 11 ms 19156 KB Output is correct
17 Correct 12 ms 19152 KB Output is correct
18 Correct 12 ms 19280 KB Output is correct
19 Correct 10 ms 19152 KB Output is correct
20 Correct 11 ms 19152 KB Output is correct
21 Correct 12 ms 19212 KB Output is correct
22 Correct 11 ms 19152 KB Output is correct
23 Correct 12 ms 19136 KB Output is correct
24 Correct 11 ms 19140 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 13 ms 19276 KB Output is correct
2 Correct 13 ms 19156 KB Output is correct
3 Correct 11 ms 19192 KB Output is correct
4 Correct 13 ms 19184 KB Output is correct
5 Correct 10 ms 19188 KB Output is correct
6 Correct 15 ms 19152 KB Output is correct
7 Correct 10 ms 19156 KB Output is correct
8 Correct 11 ms 19152 KB Output is correct
9 Correct 14 ms 19152 KB Output is correct
10 Correct 10 ms 19084 KB Output is correct
11 Correct 12 ms 19100 KB Output is correct
12 Correct 12 ms 19152 KB Output is correct
13 Correct 11 ms 19152 KB Output is correct
14 Correct 11 ms 19212 KB Output is correct
15 Correct 11 ms 19152 KB Output is correct
16 Correct 11 ms 19156 KB Output is correct
17 Correct 12 ms 19152 KB Output is correct
18 Correct 12 ms 19280 KB Output is correct
19 Correct 10 ms 19152 KB Output is correct
20 Correct 11 ms 19152 KB Output is correct
21 Correct 12 ms 19212 KB Output is correct
22 Correct 11 ms 19152 KB Output is correct
23 Correct 12 ms 19136 KB Output is correct
24 Correct 11 ms 19140 KB Output is correct
25 Correct 119 ms 27472 KB Output is correct
26 Correct 22 ms 20176 KB Output is correct
27 Correct 155 ms 30772 KB Output is correct
28 Correct 140 ms 30664 KB Output is correct
29 Correct 92 ms 27672 KB Output is correct
30 Correct 100 ms 27012 KB Output is correct
31 Correct 117 ms 29896 KB Output is correct
32 Correct 166 ms 30600 KB Output is correct
33 Correct 123 ms 30268 KB Output is correct
34 Correct 82 ms 24648 KB Output is correct
35 Correct 135 ms 31076 KB Output is correct
36 Correct 197 ms 30664 KB Output is correct
37 Correct 81 ms 25272 KB Output is correct
38 Correct 176 ms 29640 KB Output is correct
39 Correct 31 ms 20680 KB Output is correct
40 Correct 139 ms 29640 KB Output is correct
41 Correct 106 ms 27124 KB Output is correct
42 Correct 141 ms 29640 KB Output is correct
43 Correct 52 ms 22728 KB Output is correct
44 Correct 131 ms 29664 KB Output is correct
45 Correct 34 ms 21116 KB Output is correct
46 Correct 160 ms 29656 KB Output is correct
47 Correct 45 ms 21908 KB Output is correct
48 Correct 167 ms 29768 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 424 ms 36148 KB Output is correct
2 Correct 428 ms 37168 KB Output is correct
3 Correct 259 ms 34012 KB Output is correct
4 Incorrect 397 ms 37364 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 13 ms 19276 KB Output is correct
2 Correct 13 ms 19156 KB Output is correct
3 Correct 11 ms 19192 KB Output is correct
4 Correct 13 ms 19184 KB Output is correct
5 Correct 10 ms 19188 KB Output is correct
6 Correct 15 ms 19152 KB Output is correct
7 Correct 10 ms 19156 KB Output is correct
8 Correct 11 ms 19152 KB Output is correct
9 Correct 14 ms 19152 KB Output is correct
10 Correct 10 ms 19084 KB Output is correct
11 Correct 12 ms 19100 KB Output is correct
12 Correct 12 ms 19152 KB Output is correct
13 Correct 11 ms 19152 KB Output is correct
14 Correct 11 ms 19212 KB Output is correct
15 Correct 11 ms 19152 KB Output is correct
16 Correct 11 ms 19156 KB Output is correct
17 Correct 12 ms 19152 KB Output is correct
18 Correct 12 ms 19280 KB Output is correct
19 Correct 10 ms 19152 KB Output is correct
20 Correct 11 ms 19152 KB Output is correct
21 Correct 12 ms 19212 KB Output is correct
22 Correct 11 ms 19152 KB Output is correct
23 Correct 12 ms 19136 KB Output is correct
24 Correct 11 ms 19140 KB Output is correct
25 Correct 119 ms 27472 KB Output is correct
26 Correct 22 ms 20176 KB Output is correct
27 Correct 155 ms 30772 KB Output is correct
28 Correct 140 ms 30664 KB Output is correct
29 Correct 92 ms 27672 KB Output is correct
30 Correct 100 ms 27012 KB Output is correct
31 Correct 117 ms 29896 KB Output is correct
32 Correct 166 ms 30600 KB Output is correct
33 Correct 123 ms 30268 KB Output is correct
34 Correct 82 ms 24648 KB Output is correct
35 Correct 135 ms 31076 KB Output is correct
36 Correct 197 ms 30664 KB Output is correct
37 Correct 81 ms 25272 KB Output is correct
38 Correct 176 ms 29640 KB Output is correct
39 Correct 31 ms 20680 KB Output is correct
40 Correct 139 ms 29640 KB Output is correct
41 Correct 106 ms 27124 KB Output is correct
42 Correct 141 ms 29640 KB Output is correct
43 Correct 52 ms 22728 KB Output is correct
44 Correct 131 ms 29664 KB Output is correct
45 Correct 34 ms 21116 KB Output is correct
46 Correct 160 ms 29656 KB Output is correct
47 Correct 45 ms 21908 KB Output is correct
48 Correct 167 ms 29768 KB Output is correct
49 Correct 424 ms 36148 KB Output is correct
50 Correct 428 ms 37168 KB Output is correct
51 Correct 259 ms 34012 KB Output is correct
52 Incorrect 397 ms 37364 KB Output isn't correct
53 Halted 0 ms 0 KB -