Submission #1033800

# Submission time Handle Problem Language Result Execution time Memory
1033800 2024-07-25T06:32:30 Z vjudge1 Art Exhibition (JOI18_art) C++17
100 / 100
337 ms 37356 KB
#include <bits/stdc++.h>
using namespace std;
 
using ll = long long;
using pll = pair<ll, ll>;
 
#define fi first
#define se second
#define all(a) (a).begin(), (a).end()
#define sz(a) (ll)a.size()
 
const ll N = 5e5 + 5;
const ll mod = 1e9 + 7;
const ll inf = 1e18;
 
ll n;
pll a[N];
 
struct SegmentTree{
    ll st[N << 2], lz[N << 2];
    void apply(ll id, ll k){
        st[id] += k;
        lz[id] += k;
    }
    void push(ll id){
        apply(id << 1, lz[id]);
        apply(id << 1 | 1, lz[id]);
        lz[id] = 0;
    }
    void upd(ll id, ll l, ll r, ll u, ll v, ll x){
        if (r < u || l > v) return;
        if (u <= l && r <= v){
            apply(id, x);
            return;
        }
        push(id);
        ll mid = l + r >> 1;
        upd(id << 1, l, mid, u, v, x);
        upd(id << 1 | 1, mid + 1, r, u, v, x);
        st[id] = max(st[id << 1], st[id << 1 | 1]);
    }
    ll get(ll id, ll l, ll r, ll u, ll v){
        if (r < u || l > v) return -inf;
        if (u <= l && r <= v) return st[id];
        push(id);
        ll mid = l + r >> 1;
        return max(get(id << 1, l, mid, u, v), get(id << 1 | 1, mid + 1, r, u, v));
    }
} st;
 
void Solve(){
    cin >> n;
    for (int i = 1; i <= n; ++i) cin >> a[i].fi >> a[i].se;
    sort(a + 1, a + n + 1);
    ll ans = -inf;
    for (int i = 1; i <= n; ++i){
        st.upd(1, 1, n, 1, i, a[i].se);
        st.upd(1, 1, n, i, i, a[i].fi);
        ans = max(ans, st.get(1, 1, n, 1, i) - a[i].fi);
    }
    cout << ans;
}
 
signed main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
//    freopen("FILE.inp", "r", stdin);
//    freopen("FILE.out", "w", stdout);
    ll t = 1; // cin >> t;
    while (t--) Solve();
}
 

Compilation message

art.cpp: In member function 'void SegmentTree::upd(ll, ll, ll, ll, ll, ll)':
art.cpp:37:20: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   37 |         ll mid = l + r >> 1;
      |                  ~~^~~
art.cpp: In member function 'll SegmentTree::get(ll, ll, ll, ll, ll)':
art.cpp:46:20: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   46 |         ll mid = l + r >> 1;
      |                  ~~^~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 0 ms 604 KB Output is correct
5 Correct 0 ms 472 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 0 ms 604 KB Output is correct
5 Correct 0 ms 472 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 1 ms 472 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 436 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 1 ms 344 KB Output is correct
23 Correct 1 ms 600 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 0 ms 604 KB Output is correct
5 Correct 0 ms 472 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 1 ms 472 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 436 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 1 ms 344 KB Output is correct
23 Correct 1 ms 600 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 1 ms 348 KB Output is correct
27 Correct 4 ms 860 KB Output is correct
28 Correct 2 ms 860 KB Output is correct
29 Correct 3 ms 860 KB Output is correct
30 Correct 3 ms 860 KB Output is correct
31 Correct 3 ms 860 KB Output is correct
32 Correct 3 ms 860 KB Output is correct
33 Correct 2 ms 860 KB Output is correct
34 Correct 2 ms 860 KB Output is correct
35 Correct 4 ms 792 KB Output is correct
36 Correct 3 ms 860 KB Output is correct
37 Correct 3 ms 856 KB Output is correct
38 Correct 3 ms 860 KB Output is correct
39 Correct 3 ms 860 KB Output is correct
40 Correct 2 ms 756 KB Output is correct
41 Correct 4 ms 860 KB Output is correct
42 Correct 3 ms 856 KB Output is correct
43 Correct 4 ms 860 KB Output is correct
44 Correct 4 ms 860 KB Output is correct
45 Correct 3 ms 868 KB Output is correct
46 Correct 3 ms 860 KB Output is correct
47 Correct 2 ms 776 KB Output is correct
48 Correct 5 ms 860 KB Output is correct
49 Correct 3 ms 860 KB Output is correct
50 Correct 3 ms 860 KB Output is correct
51 Correct 2 ms 860 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 0 ms 604 KB Output is correct
5 Correct 0 ms 472 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 1 ms 472 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 436 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 1 ms 344 KB Output is correct
23 Correct 1 ms 600 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 1 ms 348 KB Output is correct
27 Correct 4 ms 860 KB Output is correct
28 Correct 2 ms 860 KB Output is correct
29 Correct 3 ms 860 KB Output is correct
30 Correct 3 ms 860 KB Output is correct
31 Correct 3 ms 860 KB Output is correct
32 Correct 3 ms 860 KB Output is correct
33 Correct 2 ms 860 KB Output is correct
34 Correct 2 ms 860 KB Output is correct
35 Correct 4 ms 792 KB Output is correct
36 Correct 3 ms 860 KB Output is correct
37 Correct 3 ms 856 KB Output is correct
38 Correct 3 ms 860 KB Output is correct
39 Correct 3 ms 860 KB Output is correct
40 Correct 2 ms 756 KB Output is correct
41 Correct 4 ms 860 KB Output is correct
42 Correct 3 ms 856 KB Output is correct
43 Correct 4 ms 860 KB Output is correct
44 Correct 4 ms 860 KB Output is correct
45 Correct 3 ms 868 KB Output is correct
46 Correct 3 ms 860 KB Output is correct
47 Correct 2 ms 776 KB Output is correct
48 Correct 5 ms 860 KB Output is correct
49 Correct 3 ms 860 KB Output is correct
50 Correct 3 ms 860 KB Output is correct
51 Correct 2 ms 860 KB Output is correct
52 Correct 282 ms 37108 KB Output is correct
53 Correct 274 ms 37288 KB Output is correct
54 Correct 295 ms 37204 KB Output is correct
55 Correct 280 ms 37160 KB Output is correct
56 Correct 310 ms 37200 KB Output is correct
57 Correct 275 ms 37252 KB Output is correct
58 Correct 271 ms 37204 KB Output is correct
59 Correct 274 ms 37356 KB Output is correct
60 Correct 284 ms 37292 KB Output is correct
61 Correct 280 ms 37052 KB Output is correct
62 Correct 295 ms 37336 KB Output is correct
63 Correct 276 ms 37308 KB Output is correct
64 Correct 294 ms 37184 KB Output is correct
65 Correct 275 ms 37204 KB Output is correct
66 Correct 336 ms 37320 KB Output is correct
67 Correct 274 ms 37128 KB Output is correct
68 Correct 337 ms 37260 KB Output is correct