답안 #638232

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
638232 2022-09-05T04:32:39 Z bonk Just Long Neckties (JOI20_ho_t1) C++14
100 / 100
168 ms 14200 KB
#include <bits/stdc++.h>

using namespace std;

const int N = 2e5;
int ans[N + 2];
vector<pair<int, int>>a, b;

struct Segtree{
    int tree[4*N + 2];

    void update(int l, int r, int i, int pos, int val){
        if(l == r){
            tree[i] = val;
            return;
        }

        int mid = (l + r)/2;
        if(pos <= mid) update(l, mid, 2*i, pos, val);
        else update(mid + 1, r, 2*i + 1, pos, val);

        tree[i] = max(tree[2*i], tree[2*i + 1]);
    }

    int query(int l, int r, int i, int left, int right){
        if(l > right || r < left || l > r) return 0;
        if(left <= l && r <= right) return tree[i];
        
        int mid = (l + r)/2;
        return max(
            query(l, mid, 2*i, left, right),
            query(mid + 1, r, 2*i + 1, left, right)
        );
    }
} l, r;

int main(){
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    int n; cin >> n;
    a.resize(n + 2); b.resize(n + 1);
    for(int i = 1; i <= n + 1; i++){
        cin >> a[i].first;
        a[i].second = i;
    }

    for(int i = 1; i <= n; i++){
        cin >> b[i].first;
        b[i].second = i;
    }

    sort(a.begin() + 1, a.end());
    sort(b.begin() + 1, b.end());

    for(int i = 1; i <= n; i++){
        l.update(1, n, 1, i, max(a[i].first - b[i].first, 0));
    }

    for(int i = 1; i <= n; i++){
        r.update(1, n, 1, i, max(a[i + 1].first - b[i].first, 0));
    }

    for(int i = 1; i <= n + 1; i++){
        ans[a[i].second] = max(l.query(1, n, 1, 1, i - 1), r.query(1, n, 1, i, n));
    }

    for(int i = 1; i <= n + 1; i++) cout << ans[i] << " ";
    cout << '\n';

    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 0 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 0 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 0 ms 340 KB Output is correct
17 Correct 2 ms 344 KB Output is correct
18 Correct 2 ms 340 KB Output is correct
19 Correct 2 ms 340 KB Output is correct
20 Correct 2 ms 340 KB Output is correct
21 Correct 2 ms 340 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 2 ms 340 KB Output is correct
24 Correct 2 ms 348 KB Output is correct
25 Correct 2 ms 340 KB Output is correct
26 Correct 2 ms 396 KB Output is correct
27 Correct 2 ms 348 KB Output is correct
28 Correct 1 ms 344 KB Output is correct
29 Correct 1 ms 348 KB Output is correct
30 Correct 2 ms 340 KB Output is correct
31 Correct 1 ms 348 KB Output is correct
32 Correct 2 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 0 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 0 ms 340 KB Output is correct
17 Correct 2 ms 344 KB Output is correct
18 Correct 2 ms 340 KB Output is correct
19 Correct 2 ms 340 KB Output is correct
20 Correct 2 ms 340 KB Output is correct
21 Correct 2 ms 340 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 2 ms 340 KB Output is correct
24 Correct 2 ms 348 KB Output is correct
25 Correct 2 ms 340 KB Output is correct
26 Correct 2 ms 396 KB Output is correct
27 Correct 2 ms 348 KB Output is correct
28 Correct 1 ms 344 KB Output is correct
29 Correct 1 ms 348 KB Output is correct
30 Correct 2 ms 340 KB Output is correct
31 Correct 1 ms 348 KB Output is correct
32 Correct 2 ms 340 KB Output is correct
33 Correct 148 ms 13284 KB Output is correct
34 Correct 156 ms 13868 KB Output is correct
35 Correct 154 ms 13472 KB Output is correct
36 Correct 153 ms 13900 KB Output is correct
37 Correct 153 ms 14200 KB Output is correct
38 Correct 156 ms 14024 KB Output is correct
39 Correct 152 ms 13096 KB Output is correct
40 Correct 149 ms 13072 KB Output is correct
41 Correct 150 ms 13108 KB Output is correct
42 Correct 152 ms 13132 KB Output is correct
43 Correct 153 ms 13012 KB Output is correct
44 Correct 151 ms 12728 KB Output is correct
45 Correct 146 ms 12748 KB Output is correct
46 Correct 154 ms 12632 KB Output is correct
47 Correct 156 ms 12792 KB Output is correct
48 Correct 159 ms 12764 KB Output is correct
49 Correct 160 ms 13300 KB Output is correct
50 Correct 152 ms 13304 KB Output is correct
51 Correct 156 ms 13312 KB Output is correct
52 Correct 168 ms 13372 KB Output is correct
53 Correct 154 ms 13388 KB Output is correct