답안 #762988

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
762988 2023-06-22T02:08:16 Z vjudge1 Just Long Neckties (JOI20_ho_t1) C++17
100 / 100
113 ms 7460 KB
#include<bits/stdc++.h>
using namespace std;

const int MAXN = 2e5 + 10;

int n;

pair<int, int> a[MAXN];
int b[MAXN], tree[4*MAXN], ans[MAXN];

void build(int id, int l, int r){
    if(l == r){
        tree[id] = max(a[l].first - b[l], 0);
        return;
    }
    int mid = (l + r) / 2;
    build(id*2, l, mid);
    build(id*2 + 1, mid + 1, r);
    tree[id] = max(tree[id*2], tree[id*2 + 1]);
}

void update(int id, int l, int r, int ind){
    if(l > ind || r < ind) return;
    if(l == r){
        tree[id] = max(a[l+1].first - b[l], 0);
        return; 
    }
    int mid = (l + r) / 2;
    update(id*2, l, mid, ind);
    update(id*2 + 1, mid + 1, r, ind);
    tree[id] = max(tree[id*2], tree[id*2 + 1]);
}

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

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);

    cin >> n;
    for(int i = 1; i <= n + 1; i++){
        cin >> a[i].first;
        a[i].second = i;
    }
    sort(a + 1, a + n + 2);
    for(int i = 1; i <= n; i++){
        cin >> b[i];
    }
    sort(b + 1, b + n + 1);
    build(1, 1, n);
    ans[a[n+1].second] = get(1, 1, n, 1, n);
    for(int i = n; i >= 1; i--){
        update(1, 1, n, i);
        ans[a[i].second] = get(1, 1, n, 1, n);
    }
    for(int i = 1; i <= n + 1; i++){
        cout << ans[i] << ' ';
    }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 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 0 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 0 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 0 ms 340 KB Output is correct
12 Correct 0 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 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 0 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 0 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 0 ms 340 KB Output is correct
12 Correct 0 ms 340 KB Output is correct
13 Correct 0 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 1 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 2 ms 340 KB Output is correct
28 Correct 1 ms 340 KB Output is correct
29 Correct 1 ms 340 KB Output is correct
30 Correct 1 ms 340 KB Output is correct
31 Correct 1 ms 340 KB Output is correct
32 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 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 0 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 0 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 0 ms 340 KB Output is correct
12 Correct 0 ms 340 KB Output is correct
13 Correct 0 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 1 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 2 ms 340 KB Output is correct
28 Correct 1 ms 340 KB Output is correct
29 Correct 1 ms 340 KB Output is correct
30 Correct 1 ms 340 KB Output is correct
31 Correct 1 ms 340 KB Output is correct
32 Correct 1 ms 340 KB Output is correct
33 Correct 91 ms 6788 KB Output is correct
34 Correct 98 ms 6992 KB Output is correct
35 Correct 96 ms 6800 KB Output is correct
36 Correct 95 ms 7312 KB Output is correct
37 Correct 97 ms 7460 KB Output is correct
38 Correct 99 ms 7396 KB Output is correct
39 Correct 94 ms 6568 KB Output is correct
40 Correct 95 ms 6536 KB Output is correct
41 Correct 103 ms 6588 KB Output is correct
42 Correct 95 ms 6476 KB Output is correct
43 Correct 93 ms 6432 KB Output is correct
44 Correct 92 ms 6252 KB Output is correct
45 Correct 96 ms 6276 KB Output is correct
46 Correct 100 ms 6212 KB Output is correct
47 Correct 89 ms 5972 KB Output is correct
48 Correct 94 ms 5984 KB Output is correct
49 Correct 99 ms 6628 KB Output is correct
50 Correct 97 ms 6628 KB Output is correct
51 Correct 113 ms 6604 KB Output is correct
52 Correct 101 ms 6612 KB Output is correct
53 Correct 108 ms 6652 KB Output is correct