#pragma gcc diagnostic "-std=c++1z"
#include <bits/stdc++.h>
using namespace std;
/* /\_/\
(= ._.)
/ > \>
*/
//#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native") // codeforces
// #define int long long
#define fi first
#define se second
#define send {ios_base::sync_with_stdio(false);}
#define help {cin.tie(0);}
#define endl '\n'
#define print(x) cout<<(x)<<" ";
#define printl(x) cout<<(x)<<endl
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const int MAXN=5e5+5;
int n;
ll T[4*MAXN],lazy[4*MAXN];
void push(int v) {
if(!lazy[v]) return;
T[2*v] += lazy[v];
lazy[2*v] += lazy[v];
T[2*v+1] += lazy[v];
lazy[2*v+1] += lazy[v];
lazy[v] = 0;
}
ll query(int v,int l,int r,int tl,int tr) {
if(l > r) return 0;
if(l == tl and r == tr) return T[v];
push(v);
int tm = (tl + tr)/2;
return max(query(2*v,l,min(r,tm),tl,tm),query(2*v+1,max(l,tm+1),r,tm+1,tr));
}
void update(int v,int l,int r,int tl,int tr,ll addend) {
if(l > r) return;
if(l == tl and r == tr) {
T[v] += addend;
lazy[v] += addend;
}else {
push(v);
int tm = (tl + tr)/2;
update(2*v,l,min(r,tm),tl,tm,addend);
update(2*v+1,max(l,tm+1),r,tm+1,tr,addend);
T[v] = max(T[2*v],T[2*v+1]);
}
}
signed main(){
send help
cin>>n; pll A[n]; memset(T,0,sizeof(T)); memset(lazy,0,sizeof(lazy));
for(int i=0;i<n;i++) cin>>A[i].fi>>A[i].se;
sort(A,A+n); ll ans = 0;
for(int i=0;i<n;i++) {
update(1,i,i,0,n-1,A[i].fi);
update(1,0,i,0,n-1,A[i].se);
ans = max(ans,query(1,0,i,0,n-1) - A[i].fi);
} printl(ans);
}
Compilation message
art.cpp:1: warning: ignoring '#pragma gcc diagnostic' [-Wunknown-pragmas]
1 | #pragma gcc diagnostic "-std=c++1z"
|
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
31580 KB |
Output is correct |
2 |
Correct |
6 ms |
31704 KB |
Output is correct |
3 |
Correct |
7 ms |
31664 KB |
Output is correct |
4 |
Correct |
7 ms |
31580 KB |
Output is correct |
5 |
Correct |
8 ms |
31576 KB |
Output is correct |
6 |
Correct |
8 ms |
31576 KB |
Output is correct |
7 |
Correct |
6 ms |
31832 KB |
Output is correct |
8 |
Correct |
6 ms |
31580 KB |
Output is correct |
9 |
Correct |
6 ms |
31580 KB |
Output is correct |
10 |
Correct |
5 ms |
31576 KB |
Output is correct |
11 |
Correct |
5 ms |
31580 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
31580 KB |
Output is correct |
2 |
Correct |
6 ms |
31704 KB |
Output is correct |
3 |
Correct |
7 ms |
31664 KB |
Output is correct |
4 |
Correct |
7 ms |
31580 KB |
Output is correct |
5 |
Correct |
8 ms |
31576 KB |
Output is correct |
6 |
Correct |
8 ms |
31576 KB |
Output is correct |
7 |
Correct |
6 ms |
31832 KB |
Output is correct |
8 |
Correct |
6 ms |
31580 KB |
Output is correct |
9 |
Correct |
6 ms |
31580 KB |
Output is correct |
10 |
Correct |
5 ms |
31576 KB |
Output is correct |
11 |
Correct |
5 ms |
31580 KB |
Output is correct |
12 |
Correct |
4 ms |
31960 KB |
Output is correct |
13 |
Correct |
5 ms |
31580 KB |
Output is correct |
14 |
Correct |
5 ms |
31712 KB |
Output is correct |
15 |
Correct |
5 ms |
31580 KB |
Output is correct |
16 |
Correct |
5 ms |
31580 KB |
Output is correct |
17 |
Correct |
5 ms |
31560 KB |
Output is correct |
18 |
Correct |
5 ms |
31576 KB |
Output is correct |
19 |
Correct |
6 ms |
31580 KB |
Output is correct |
20 |
Correct |
5 ms |
31760 KB |
Output is correct |
21 |
Correct |
6 ms |
31688 KB |
Output is correct |
22 |
Correct |
5 ms |
31736 KB |
Output is correct |
23 |
Correct |
5 ms |
31764 KB |
Output is correct |
24 |
Correct |
6 ms |
31580 KB |
Output is correct |
25 |
Correct |
6 ms |
31576 KB |
Output is correct |
26 |
Correct |
6 ms |
31580 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
31580 KB |
Output is correct |
2 |
Correct |
6 ms |
31704 KB |
Output is correct |
3 |
Correct |
7 ms |
31664 KB |
Output is correct |
4 |
Correct |
7 ms |
31580 KB |
Output is correct |
5 |
Correct |
8 ms |
31576 KB |
Output is correct |
6 |
Correct |
8 ms |
31576 KB |
Output is correct |
7 |
Correct |
6 ms |
31832 KB |
Output is correct |
8 |
Correct |
6 ms |
31580 KB |
Output is correct |
9 |
Correct |
6 ms |
31580 KB |
Output is correct |
10 |
Correct |
5 ms |
31576 KB |
Output is correct |
11 |
Correct |
5 ms |
31580 KB |
Output is correct |
12 |
Correct |
4 ms |
31960 KB |
Output is correct |
13 |
Correct |
5 ms |
31580 KB |
Output is correct |
14 |
Correct |
5 ms |
31712 KB |
Output is correct |
15 |
Correct |
5 ms |
31580 KB |
Output is correct |
16 |
Correct |
5 ms |
31580 KB |
Output is correct |
17 |
Correct |
5 ms |
31560 KB |
Output is correct |
18 |
Correct |
5 ms |
31576 KB |
Output is correct |
19 |
Correct |
6 ms |
31580 KB |
Output is correct |
20 |
Correct |
5 ms |
31760 KB |
Output is correct |
21 |
Correct |
6 ms |
31688 KB |
Output is correct |
22 |
Correct |
5 ms |
31736 KB |
Output is correct |
23 |
Correct |
5 ms |
31764 KB |
Output is correct |
24 |
Correct |
6 ms |
31580 KB |
Output is correct |
25 |
Correct |
6 ms |
31576 KB |
Output is correct |
26 |
Correct |
6 ms |
31580 KB |
Output is correct |
27 |
Correct |
7 ms |
31832 KB |
Output is correct |
28 |
Correct |
7 ms |
31836 KB |
Output is correct |
29 |
Correct |
7 ms |
31804 KB |
Output is correct |
30 |
Correct |
9 ms |
31836 KB |
Output is correct |
31 |
Correct |
8 ms |
31836 KB |
Output is correct |
32 |
Correct |
9 ms |
31836 KB |
Output is correct |
33 |
Correct |
9 ms |
31836 KB |
Output is correct |
34 |
Correct |
7 ms |
31764 KB |
Output is correct |
35 |
Correct |
10 ms |
31836 KB |
Output is correct |
36 |
Correct |
8 ms |
31972 KB |
Output is correct |
37 |
Correct |
8 ms |
31864 KB |
Output is correct |
38 |
Correct |
11 ms |
32088 KB |
Output is correct |
39 |
Correct |
8 ms |
31836 KB |
Output is correct |
40 |
Correct |
7 ms |
31960 KB |
Output is correct |
41 |
Correct |
7 ms |
31836 KB |
Output is correct |
42 |
Correct |
7 ms |
31756 KB |
Output is correct |
43 |
Correct |
7 ms |
31952 KB |
Output is correct |
44 |
Correct |
8 ms |
31972 KB |
Output is correct |
45 |
Correct |
7 ms |
31836 KB |
Output is correct |
46 |
Correct |
9 ms |
31832 KB |
Output is correct |
47 |
Correct |
11 ms |
31832 KB |
Output is correct |
48 |
Correct |
7 ms |
31836 KB |
Output is correct |
49 |
Correct |
8 ms |
31836 KB |
Output is correct |
50 |
Correct |
7 ms |
31832 KB |
Output is correct |
51 |
Correct |
9 ms |
31832 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
31580 KB |
Output is correct |
2 |
Correct |
6 ms |
31704 KB |
Output is correct |
3 |
Correct |
7 ms |
31664 KB |
Output is correct |
4 |
Correct |
7 ms |
31580 KB |
Output is correct |
5 |
Correct |
8 ms |
31576 KB |
Output is correct |
6 |
Correct |
8 ms |
31576 KB |
Output is correct |
7 |
Correct |
6 ms |
31832 KB |
Output is correct |
8 |
Correct |
6 ms |
31580 KB |
Output is correct |
9 |
Correct |
6 ms |
31580 KB |
Output is correct |
10 |
Correct |
5 ms |
31576 KB |
Output is correct |
11 |
Correct |
5 ms |
31580 KB |
Output is correct |
12 |
Correct |
4 ms |
31960 KB |
Output is correct |
13 |
Correct |
5 ms |
31580 KB |
Output is correct |
14 |
Correct |
5 ms |
31712 KB |
Output is correct |
15 |
Correct |
5 ms |
31580 KB |
Output is correct |
16 |
Correct |
5 ms |
31580 KB |
Output is correct |
17 |
Correct |
5 ms |
31560 KB |
Output is correct |
18 |
Correct |
5 ms |
31576 KB |
Output is correct |
19 |
Correct |
6 ms |
31580 KB |
Output is correct |
20 |
Correct |
5 ms |
31760 KB |
Output is correct |
21 |
Correct |
6 ms |
31688 KB |
Output is correct |
22 |
Correct |
5 ms |
31736 KB |
Output is correct |
23 |
Correct |
5 ms |
31764 KB |
Output is correct |
24 |
Correct |
6 ms |
31580 KB |
Output is correct |
25 |
Correct |
6 ms |
31576 KB |
Output is correct |
26 |
Correct |
6 ms |
31580 KB |
Output is correct |
27 |
Correct |
7 ms |
31832 KB |
Output is correct |
28 |
Correct |
7 ms |
31836 KB |
Output is correct |
29 |
Correct |
7 ms |
31804 KB |
Output is correct |
30 |
Correct |
9 ms |
31836 KB |
Output is correct |
31 |
Correct |
8 ms |
31836 KB |
Output is correct |
32 |
Correct |
9 ms |
31836 KB |
Output is correct |
33 |
Correct |
9 ms |
31836 KB |
Output is correct |
34 |
Correct |
7 ms |
31764 KB |
Output is correct |
35 |
Correct |
10 ms |
31836 KB |
Output is correct |
36 |
Correct |
8 ms |
31972 KB |
Output is correct |
37 |
Correct |
8 ms |
31864 KB |
Output is correct |
38 |
Correct |
11 ms |
32088 KB |
Output is correct |
39 |
Correct |
8 ms |
31836 KB |
Output is correct |
40 |
Correct |
7 ms |
31960 KB |
Output is correct |
41 |
Correct |
7 ms |
31836 KB |
Output is correct |
42 |
Correct |
7 ms |
31756 KB |
Output is correct |
43 |
Correct |
7 ms |
31952 KB |
Output is correct |
44 |
Correct |
8 ms |
31972 KB |
Output is correct |
45 |
Correct |
7 ms |
31836 KB |
Output is correct |
46 |
Correct |
9 ms |
31832 KB |
Output is correct |
47 |
Correct |
11 ms |
31832 KB |
Output is correct |
48 |
Correct |
7 ms |
31836 KB |
Output is correct |
49 |
Correct |
8 ms |
31836 KB |
Output is correct |
50 |
Correct |
7 ms |
31832 KB |
Output is correct |
51 |
Correct |
9 ms |
31832 KB |
Output is correct |
52 |
Correct |
307 ms |
52120 KB |
Output is correct |
53 |
Correct |
294 ms |
51988 KB |
Output is correct |
54 |
Correct |
299 ms |
52248 KB |
Output is correct |
55 |
Correct |
336 ms |
52248 KB |
Output is correct |
56 |
Correct |
302 ms |
52120 KB |
Output is correct |
57 |
Correct |
290 ms |
52248 KB |
Output is correct |
58 |
Correct |
293 ms |
52008 KB |
Output is correct |
59 |
Correct |
326 ms |
52052 KB |
Output is correct |
60 |
Correct |
288 ms |
52116 KB |
Output is correct |
61 |
Correct |
288 ms |
51976 KB |
Output is correct |
62 |
Correct |
301 ms |
52056 KB |
Output is correct |
63 |
Correct |
307 ms |
52240 KB |
Output is correct |
64 |
Correct |
316 ms |
52236 KB |
Output is correct |
65 |
Correct |
309 ms |
52052 KB |
Output is correct |
66 |
Correct |
300 ms |
52232 KB |
Output is correct |
67 |
Correct |
289 ms |
52240 KB |
Output is correct |
68 |
Correct |
335 ms |
52056 KB |
Output is correct |