답안 #519541

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
519541 2022-01-26T15:29:47 Z Jomnoi Just Long Neckties (JOI20_ho_t1) C++17
100 / 100
151 ms 16328 KB
#include <bits/stdc++.h>
#define DEBUG 0
using namespace std;

const int N = 2e5 + 10;

pair <int, int> a[N];
int b[N], p[N];
int ans[N];

class A {
public :
    int a, b;
    A() : a(), b() {}
    A(int l, int r) : a(l), b(r) {}
    A operator+(const A &o) const {
        return A(max(a, o.a), max(b, o.b));
    }
};

class SegmentTree {
private :
    int N;
    vector <A> tree;
public :
    SegmentTree(int n) : N(n) {
        tree.resize(4 * N, A());
        build(1, 1, N);
    }

    void build(int idx, int l, int r) {
        if(l == r) {
            tree[idx] = A(max(0, a[l].first - b[l]), max(0, a[l + 1].first - b[l]));
            return;
        }

        int mid = (l + r) / 2;
        build(idx * 2, l, mid);
        build(idx * 2 + 1, mid + 1, r);
        tree[idx] = tree[idx * 2] + tree[idx * 2 + 1];
    }

    A query(int idx, int l, int r, int ql, int qr) {
        if(r < ql or qr < l) {
            return A(0, 0);
        }
        if(ql <= l and r <= qr) {
            return tree[idx];
        }

        int mid = (l + r) / 2;
        return query(idx * 2, l, mid, ql, qr) + query(idx * 2 + 1, mid + 1, r, ql, qr);
    }
};

int main() {
    cin.tie(0)->sync_with_stdio(0);
    int n;
    cin >> n;
    for(int i = 1; i <= n + 1; i++) {
        cin >> a[i].first;
        p[i] = i;
        a[i].second = i;
    }
    for(int i = 1; i <= n; i++) {
        cin >> b[i];
    }

    sort(a + 1, a + n + 2);
    sort(b + 1, b + n + 1);
    SegmentTree ST(n);
    for(int i = 1; i <= n + 1; i++) {
        ans[a[i].second] = max(ST.query(1, 1, n, 1, i - 1).a, ST.query(1, 1, n, i, n).b);
    }

    for(int i = 1; i <= n + 1; i++) {
        cout << ans[p[i]] << " ";
    }
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 328 KB Output is correct
6 Correct 0 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 320 KB Output is correct
10 Correct 1 ms 308 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 0 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 328 KB Output is correct
6 Correct 0 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 320 KB Output is correct
10 Correct 1 ms 308 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 0 ms 332 KB Output is correct
13 Correct 1 ms 304 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 2 ms 364 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 2 ms 460 KB Output is correct
18 Correct 1 ms 460 KB Output is correct
19 Correct 1 ms 376 KB Output is correct
20 Correct 2 ms 396 KB Output is correct
21 Correct 2 ms 472 KB Output is correct
22 Correct 2 ms 472 KB Output is correct
23 Correct 2 ms 380 KB Output is correct
24 Correct 1 ms 384 KB Output is correct
25 Correct 2 ms 468 KB Output is correct
26 Correct 2 ms 460 KB Output is correct
27 Correct 2 ms 380 KB Output is correct
28 Correct 2 ms 460 KB Output is correct
29 Correct 1 ms 460 KB Output is correct
30 Correct 1 ms 460 KB Output is correct
31 Correct 2 ms 460 KB Output is correct
32 Correct 2 ms 464 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 328 KB Output is correct
6 Correct 0 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 320 KB Output is correct
10 Correct 1 ms 308 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 0 ms 332 KB Output is correct
13 Correct 1 ms 304 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 2 ms 364 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 2 ms 460 KB Output is correct
18 Correct 1 ms 460 KB Output is correct
19 Correct 1 ms 376 KB Output is correct
20 Correct 2 ms 396 KB Output is correct
21 Correct 2 ms 472 KB Output is correct
22 Correct 2 ms 472 KB Output is correct
23 Correct 2 ms 380 KB Output is correct
24 Correct 1 ms 384 KB Output is correct
25 Correct 2 ms 468 KB Output is correct
26 Correct 2 ms 460 KB Output is correct
27 Correct 2 ms 380 KB Output is correct
28 Correct 2 ms 460 KB Output is correct
29 Correct 1 ms 460 KB Output is correct
30 Correct 1 ms 460 KB Output is correct
31 Correct 2 ms 460 KB Output is correct
32 Correct 2 ms 464 KB Output is correct
33 Correct 125 ms 15176 KB Output is correct
34 Correct 132 ms 15836 KB Output is correct
35 Correct 137 ms 15300 KB Output is correct
36 Correct 133 ms 15800 KB Output is correct
37 Correct 133 ms 16328 KB Output is correct
38 Correct 129 ms 16204 KB Output is correct
39 Correct 133 ms 15084 KB Output is correct
40 Correct 126 ms 15048 KB Output is correct
41 Correct 133 ms 15240 KB Output is correct
42 Correct 145 ms 15084 KB Output is correct
43 Correct 149 ms 14980 KB Output is correct
44 Correct 123 ms 14520 KB Output is correct
45 Correct 151 ms 14704 KB Output is correct
46 Correct 123 ms 14548 KB Output is correct
47 Correct 122 ms 14896 KB Output is correct
48 Correct 120 ms 14892 KB Output is correct
49 Correct 134 ms 15540 KB Output is correct
50 Correct 130 ms 15592 KB Output is correct
51 Correct 133 ms 15508 KB Output is correct
52 Correct 129 ms 15424 KB Output is correct
53 Correct 126 ms 15612 KB Output is correct