답안 #746396

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
746396 2023-05-22T12:22:53 Z Sami_Massah Art Exhibition (JOI18_art) C++17
100 / 100
479 ms 53860 KB
#include <bits/stdc++.h>
using namespace std;



const int maxn = 5e5 + 12;
long long n, L[maxn * 4], R[maxn * 4], mx[maxn * 4], num[maxn * 4];
vector <pair<long long, long long>> pos;
void make_tree(int l, int r, int ind){
    int mid = (l + r) / 2;
    L[ind] = l;
    R[ind] = r;
    if(l == r)
        return;
    make_tree(l, mid, ind * 2);
    make_tree(mid + 1, r, ind * 2 + 1);
}
void update_tree(int l, int r, int u, long long k){
    if(r < L[u] || R[u] < l)
        return;
    if(l <= L[u] && R[u] <= r){
        mx[u] += k;
        num[u] += k;
        return;
    }
    update_tree(l, r, u * 2, k);
    update_tree(l, r, u * 2 + 1, k);
    mx[u] = max(mx[u * 2], mx[u * 2 + 1]) + num[u];
}
long long get_max(int l, int r, int u){
    if(r < L[u] || R[u] < l)
        return 0;
    if(l <= L[u] && R[u] <= r)
        return mx[u];
    return max(get_max(l, r, u * 2), get_max(l, r, u * 2 + 1)) + num[u];
}
int main(){
    ios_base::sync_with_stdio(false), cin.tie(0);
    cin >> n;
    for(int i = 0; i < n; i++){
        long long a, b;
        cin >> a >> b;
        pos.push_back(make_pair(a, b));

    }
    sort(pos.begin(), pos.end());
    make_tree(0, n, 1);
    long long ans = 0;
    for(int i = 0; i < n; i++){
        update_tree(0, i, 1, pos[i].second);
        update_tree(i, i, 1, pos[i].first);
        ans = max(ans, get_max(0, i, 1) - pos[i].first);


    }
    cout << ans << endl;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 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 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 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 0 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 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 0 ms 340 KB Output is correct
12 Correct 1 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 1 ms 340 KB Output is correct
17 Correct 0 ms 340 KB Output is correct
18 Correct 0 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
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 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 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 0 ms 340 KB Output is correct
12 Correct 1 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 1 ms 340 KB Output is correct
17 Correct 0 ms 340 KB Output is correct
18 Correct 0 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 4 ms 980 KB Output is correct
28 Correct 4 ms 980 KB Output is correct
29 Correct 4 ms 980 KB Output is correct
30 Correct 4 ms 980 KB Output is correct
31 Correct 4 ms 980 KB Output is correct
32 Correct 4 ms 980 KB Output is correct
33 Correct 4 ms 980 KB Output is correct
34 Correct 4 ms 980 KB Output is correct
35 Correct 4 ms 980 KB Output is correct
36 Correct 5 ms 980 KB Output is correct
37 Correct 4 ms 1016 KB Output is correct
38 Correct 5 ms 1056 KB Output is correct
39 Correct 4 ms 980 KB Output is correct
40 Correct 4 ms 980 KB Output is correct
41 Correct 4 ms 980 KB Output is correct
42 Correct 4 ms 980 KB Output is correct
43 Correct 4 ms 980 KB Output is correct
44 Correct 4 ms 980 KB Output is correct
45 Correct 4 ms 980 KB Output is correct
46 Correct 4 ms 980 KB Output is correct
47 Correct 5 ms 980 KB Output is correct
48 Correct 4 ms 1028 KB Output is correct
49 Correct 5 ms 1072 KB Output is correct
50 Correct 5 ms 980 KB Output is correct
51 Correct 4 ms 980 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 0 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 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 0 ms 340 KB Output is correct
12 Correct 1 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 1 ms 340 KB Output is correct
17 Correct 0 ms 340 KB Output is correct
18 Correct 0 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 4 ms 980 KB Output is correct
28 Correct 4 ms 980 KB Output is correct
29 Correct 4 ms 980 KB Output is correct
30 Correct 4 ms 980 KB Output is correct
31 Correct 4 ms 980 KB Output is correct
32 Correct 4 ms 980 KB Output is correct
33 Correct 4 ms 980 KB Output is correct
34 Correct 4 ms 980 KB Output is correct
35 Correct 4 ms 980 KB Output is correct
36 Correct 5 ms 980 KB Output is correct
37 Correct 4 ms 1016 KB Output is correct
38 Correct 5 ms 1056 KB Output is correct
39 Correct 4 ms 980 KB Output is correct
40 Correct 4 ms 980 KB Output is correct
41 Correct 4 ms 980 KB Output is correct
42 Correct 4 ms 980 KB Output is correct
43 Correct 4 ms 980 KB Output is correct
44 Correct 4 ms 980 KB Output is correct
45 Correct 4 ms 980 KB Output is correct
46 Correct 4 ms 980 KB Output is correct
47 Correct 5 ms 980 KB Output is correct
48 Correct 4 ms 1028 KB Output is correct
49 Correct 5 ms 1072 KB Output is correct
50 Correct 5 ms 980 KB Output is correct
51 Correct 4 ms 980 KB Output is correct
52 Correct 441 ms 41188 KB Output is correct
53 Correct 449 ms 53860 KB Output is correct
54 Correct 465 ms 53720 KB Output is correct
55 Correct 478 ms 53740 KB Output is correct
56 Correct 454 ms 53764 KB Output is correct
57 Correct 444 ms 53700 KB Output is correct
58 Correct 439 ms 53800 KB Output is correct
59 Correct 449 ms 53748 KB Output is correct
60 Correct 442 ms 53772 KB Output is correct
61 Correct 448 ms 53760 KB Output is correct
62 Correct 443 ms 53736 KB Output is correct
63 Correct 441 ms 53832 KB Output is correct
64 Correct 455 ms 53696 KB Output is correct
65 Correct 479 ms 53696 KB Output is correct
66 Correct 434 ms 53740 KB Output is correct
67 Correct 449 ms 53852 KB Output is correct
68 Correct 442 ms 53840 KB Output is correct