# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1008655 |
2024-06-26T16:18:45 Z |
fimh |
Art Exhibition (JOI18_art) |
C++14 |
|
279 ms |
37528 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 |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 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 |
0 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 |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 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 |
0 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 |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
1 ms |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
0 ms |
348 KB |
Output is correct |
22 |
Correct |
0 ms |
348 KB |
Output is correct |
23 |
Correct |
0 ms |
348 KB |
Output is correct |
24 |
Correct |
0 ms |
348 KB |
Output is correct |
25 |
Correct |
0 ms |
348 KB |
Output is correct |
26 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 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 |
0 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 |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
1 ms |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
0 ms |
348 KB |
Output is correct |
22 |
Correct |
0 ms |
348 KB |
Output is correct |
23 |
Correct |
0 ms |
348 KB |
Output is correct |
24 |
Correct |
0 ms |
348 KB |
Output is correct |
25 |
Correct |
0 ms |
348 KB |
Output is correct |
26 |
Correct |
0 ms |
348 KB |
Output is correct |
27 |
Correct |
3 ms |
600 KB |
Output is correct |
28 |
Correct |
2 ms |
604 KB |
Output is correct |
29 |
Correct |
2 ms |
604 KB |
Output is correct |
30 |
Correct |
2 ms |
604 KB |
Output is correct |
31 |
Correct |
2 ms |
620 KB |
Output is correct |
32 |
Correct |
2 ms |
604 KB |
Output is correct |
33 |
Correct |
2 ms |
604 KB |
Output is correct |
34 |
Correct |
2 ms |
604 KB |
Output is correct |
35 |
Correct |
2 ms |
604 KB |
Output is correct |
36 |
Correct |
2 ms |
604 KB |
Output is correct |
37 |
Correct |
4 ms |
604 KB |
Output is correct |
38 |
Correct |
2 ms |
604 KB |
Output is correct |
39 |
Correct |
2 ms |
604 KB |
Output is correct |
40 |
Correct |
2 ms |
604 KB |
Output is correct |
41 |
Correct |
2 ms |
604 KB |
Output is correct |
42 |
Correct |
3 ms |
604 KB |
Output is correct |
43 |
Correct |
2 ms |
604 KB |
Output is correct |
44 |
Correct |
3 ms |
604 KB |
Output is correct |
45 |
Correct |
2 ms |
604 KB |
Output is correct |
46 |
Correct |
2 ms |
604 KB |
Output is correct |
47 |
Correct |
2 ms |
604 KB |
Output is correct |
48 |
Correct |
2 ms |
604 KB |
Output is correct |
49 |
Correct |
2 ms |
604 KB |
Output is correct |
50 |
Correct |
2 ms |
604 KB |
Output is correct |
51 |
Correct |
2 ms |
604 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 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 |
0 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 |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
1 ms |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
0 ms |
348 KB |
Output is correct |
22 |
Correct |
0 ms |
348 KB |
Output is correct |
23 |
Correct |
0 ms |
348 KB |
Output is correct |
24 |
Correct |
0 ms |
348 KB |
Output is correct |
25 |
Correct |
0 ms |
348 KB |
Output is correct |
26 |
Correct |
0 ms |
348 KB |
Output is correct |
27 |
Correct |
3 ms |
600 KB |
Output is correct |
28 |
Correct |
2 ms |
604 KB |
Output is correct |
29 |
Correct |
2 ms |
604 KB |
Output is correct |
30 |
Correct |
2 ms |
604 KB |
Output is correct |
31 |
Correct |
2 ms |
620 KB |
Output is correct |
32 |
Correct |
2 ms |
604 KB |
Output is correct |
33 |
Correct |
2 ms |
604 KB |
Output is correct |
34 |
Correct |
2 ms |
604 KB |
Output is correct |
35 |
Correct |
2 ms |
604 KB |
Output is correct |
36 |
Correct |
2 ms |
604 KB |
Output is correct |
37 |
Correct |
4 ms |
604 KB |
Output is correct |
38 |
Correct |
2 ms |
604 KB |
Output is correct |
39 |
Correct |
2 ms |
604 KB |
Output is correct |
40 |
Correct |
2 ms |
604 KB |
Output is correct |
41 |
Correct |
2 ms |
604 KB |
Output is correct |
42 |
Correct |
3 ms |
604 KB |
Output is correct |
43 |
Correct |
2 ms |
604 KB |
Output is correct |
44 |
Correct |
3 ms |
604 KB |
Output is correct |
45 |
Correct |
2 ms |
604 KB |
Output is correct |
46 |
Correct |
2 ms |
604 KB |
Output is correct |
47 |
Correct |
2 ms |
604 KB |
Output is correct |
48 |
Correct |
2 ms |
604 KB |
Output is correct |
49 |
Correct |
2 ms |
604 KB |
Output is correct |
50 |
Correct |
2 ms |
604 KB |
Output is correct |
51 |
Correct |
2 ms |
604 KB |
Output is correct |
52 |
Correct |
269 ms |
34580 KB |
Output is correct |
53 |
Correct |
279 ms |
37324 KB |
Output is correct |
54 |
Correct |
267 ms |
37204 KB |
Output is correct |
55 |
Correct |
273 ms |
37200 KB |
Output is correct |
56 |
Correct |
255 ms |
37216 KB |
Output is correct |
57 |
Correct |
262 ms |
37200 KB |
Output is correct |
58 |
Correct |
268 ms |
37132 KB |
Output is correct |
59 |
Correct |
267 ms |
37180 KB |
Output is correct |
60 |
Correct |
264 ms |
37264 KB |
Output is correct |
61 |
Correct |
251 ms |
37200 KB |
Output is correct |
62 |
Correct |
259 ms |
37196 KB |
Output is correct |
63 |
Correct |
262 ms |
37208 KB |
Output is correct |
64 |
Correct |
267 ms |
37168 KB |
Output is correct |
65 |
Correct |
266 ms |
37288 KB |
Output is correct |
66 |
Correct |
248 ms |
37204 KB |
Output is correct |
67 |
Correct |
261 ms |
37204 KB |
Output is correct |
68 |
Correct |
266 ms |
37528 KB |
Output is correct |