답안 #683601

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
683601 2023-01-18T20:25:58 Z TimDee Art Exhibition (JOI18_art) C++17
100 / 100
381 ms 57544 KB
#include <bits/stdc++.h>
using namespace std;

#pragma GCC optimize("O3")
#pragma GCC optimize("O2")
#pragma GCC optimize("Ofast")

#define forn(i,n) for(int i=0;i<n;++i)
#define pb(x) push_back(x)
#define vii(a,n) vector<int>a(n);forn(i,n)cin>>a[i];
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define pi pair<int,int>
#define f first
#define s second
#define int long long

const int inf = 1e18;
const int mod = 1e9+7;//998244353;
using ll = long long;

struct sgt {
	struct node {
		int pref=0,suf=0,in=0,sum=0;
	};
    vector<node> t;
    int n, sz;
    node merge(node a, node b) {
    	node r;
    	r.pref = max(a.pref,a.sum+b.pref);
    	r.suf = max(b.suf,b.sum+a.suf);
    	r.sum = a.sum+b.sum;
    	r.in = max({a.in, b.in, a.suf+b.pref});
    	return r;
    }
    node zero;
    void build(int v, int l, int r) {
        if (r-l==1) return;
        int m=(l+r)>>1;
        build(2*v+1,l,m);
        build(2*v+2,m,r);
        t[v]=merge(t[2*v+1],t[2*v+2]);
    }
    sgt(vector<int>&a) {
        n=a.size();
        sz=1;
        while (sz<n) sz<<=1;
        t.assign(2*sz-1,zero);
        forn(i,n) {
        	t[sz-1+i].pref=max(a[i],0ll);
        	t[sz-1+i].suf=max(a[i],0ll);
        	t[sz-1+i].sum=a[i];
        	t[sz-1+i].in=max(a[i],0ll);
        }
        build(0,0,sz);
    }
    node query(int v, int l, int r, int lx, int rx) {
        if (r<=lx || l>=rx) return zero;
        if (lx<=l && r<=rx) return t[v];
        int m=(l+r)>>1;
       	auto L=query(2*v+1,l,m,lx,rx);
       	auto R=query(2*v+2,m,r,lx,rx);
        return merge(L,R);
    }
    int query(int l, int r) {
        auto ret = query(0,0,sz,l,r);
        return max({ret.sum,ret.in,ret.pref,ret.suf});
    }
    void build(int v, int l, int r, int i) {
    	if (r<=i || l>i) return;
    	if (r-l==1) return;
    	int m=(l+r)>>1;
    	build(2*v+1,l,m,i);
    	build(2*v+2,m,r,i);
    	t[v]=merge(t[2*v+1],t[2*v+2]);
    }
    void set(int i, int x) {
    	t[sz-1+i].pref=x;
    	t[sz-1+i].suf=x;
    	t[sz-1+i].sum=x;
    	t[sz-1+i].in=x;
    	build(0,0,sz,i);
    }
};

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
void solve() {
		
	int n; cin>>n;
	vector<pi> a(n);
	forn(i,n) cin>>a[i].f>>a[i].s;
	sort(all(a));

	vector<int> b(n);
	b[0]=a[0].s;
	for (int i=1; i<n; ++i) {
		b[i]=a[i].s-(a[i].f-a[i-1].f);
	}

	sgt st(b);
	int ans=0;
	forn(i,n) {
		st.set(i,a[i].s);
		ans=max(ans,st.query(i,n));
	}
	cout<<ans;

}

int32_t main() { 
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int t=1;
   	//cin>>t;
    while(t--) solve();
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 324 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 324 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 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 1 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 324 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 328 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 324 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 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 1 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 324 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 328 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 4 ms 1028 KB Output is correct
28 Correct 4 ms 1040 KB Output is correct
29 Correct 4 ms 980 KB Output is correct
30 Correct 4 ms 972 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 996 KB Output is correct
36 Correct 4 ms 980 KB Output is correct
37 Correct 4 ms 1040 KB Output is correct
38 Correct 4 ms 1032 KB Output is correct
39 Correct 4 ms 980 KB Output is correct
40 Correct 4 ms 1044 KB Output is correct
41 Correct 5 ms 980 KB Output is correct
42 Correct 4 ms 1044 KB Output is correct
43 Correct 4 ms 980 KB Output is correct
44 Correct 4 ms 980 KB Output is correct
45 Correct 3 ms 976 KB Output is correct
46 Correct 4 ms 972 KB Output is correct
47 Correct 5 ms 1028 KB Output is correct
48 Correct 4 ms 1108 KB Output is correct
49 Correct 4 ms 1028 KB Output is correct
50 Correct 3 ms 980 KB Output is correct
51 Correct 3 ms 980 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 324 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 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 1 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 324 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 328 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 4 ms 1028 KB Output is correct
28 Correct 4 ms 1040 KB Output is correct
29 Correct 4 ms 980 KB Output is correct
30 Correct 4 ms 972 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 996 KB Output is correct
36 Correct 4 ms 980 KB Output is correct
37 Correct 4 ms 1040 KB Output is correct
38 Correct 4 ms 1032 KB Output is correct
39 Correct 4 ms 980 KB Output is correct
40 Correct 4 ms 1044 KB Output is correct
41 Correct 5 ms 980 KB Output is correct
42 Correct 4 ms 1044 KB Output is correct
43 Correct 4 ms 980 KB Output is correct
44 Correct 4 ms 980 KB Output is correct
45 Correct 3 ms 976 KB Output is correct
46 Correct 4 ms 972 KB Output is correct
47 Correct 5 ms 1028 KB Output is correct
48 Correct 4 ms 1108 KB Output is correct
49 Correct 4 ms 1028 KB Output is correct
50 Correct 3 ms 980 KB Output is correct
51 Correct 3 ms 980 KB Output is correct
52 Correct 354 ms 57492 KB Output is correct
53 Correct 359 ms 57540 KB Output is correct
54 Correct 381 ms 57536 KB Output is correct
55 Correct 352 ms 57420 KB Output is correct
56 Correct 368 ms 57532 KB Output is correct
57 Correct 365 ms 57544 KB Output is correct
58 Correct 356 ms 57540 KB Output is correct
59 Correct 350 ms 57536 KB Output is correct
60 Correct 376 ms 57540 KB Output is correct
61 Correct 349 ms 57292 KB Output is correct
62 Correct 359 ms 57540 KB Output is correct
63 Correct 349 ms 57540 KB Output is correct
64 Correct 376 ms 57540 KB Output is correct
65 Correct 356 ms 57540 KB Output is correct
66 Correct 377 ms 57540 KB Output is correct
67 Correct 365 ms 57540 KB Output is correct
68 Correct 357 ms 57540 KB Output is correct