Submission #742559

# Submission time Handle Problem Language Result Execution time Memory
742559 2023-05-16T13:01:05 Z LCJLY Art Exhibition (JOI18_art) C++14
100 / 100
792 ms 87040 KB
#include <bits/stdc++.h>
using namespace std;

#define int long long
typedef pair<int,int>pii;

inline int combine(int a, int b){
	return max(a,b);
}

const int defval=0;
#define lazyChange 1
#define setSentinel -1

struct node{
	int s,e,m;
	node *l, *r;
	int v;
	bool lset;
	int lazyUpd, lazySet;
	
	node(int ss, int ee):s(ss),e(ee),m((s+e)>>1),l(NULL),r(NULL),v(defval),lazyUpd(0),lazySet(setSentinel),lset(0){
	}
	
	inline void inst(){
		if(l==NULL)l=new node(s,m);
		if(r==NULL)r=new node(m+1,e);
	}
	
	void self_set(int x){
		lset=1;
		lazySet=x;
		v=lazyChange*x;
		lazyUpd=0;
	}
	
	void self_add(int x){
		if(lset){self_set(x+lazySet);return;}
		lazyUpd+=x;
		v+=x*lazyChange;
	}
	
	void forceProp(){
		if(s==e) return;
		if(lset){
			l->self_set(lazySet),r->self_set(lazySet);
			lset=lazySet=0;
		}
		if(lazyUpd!=0){
			l->self_add(lazyUpd),r->self_add(lazyUpd);
			lazyUpd=0;
		}
	}
	
	void rangeUpd(int first, int last, int c){
		if(first<=s&&last>=e){
			self_add(c);
			return;
		}
		inst();
		forceProp();
		if(first<=m)l->rangeUpd(first,last,c);
		if(last>m)r->rangeUpd(first,last,c);
		v=combine(l->v,r->v);
	}
	
	void rangeSet(int first, int last, int c){
		if(first<=s&&last>=e){
			self_set(c);
			return;
		}
		inst();
		forceProp();
		if(first<=m)l->rangeUpd(first,last,c);
		if(last>m)r->rangeUpd(first,last,c);
		v=combine(l->v,r->v);
	}
	
	int query(int x, int y){
		if(s==e){
			return v;
		}
		if(x<=s&&y>=e){
			forceProp(); return v;
		}
		inst();
		forceProp();
		if(y<=m) return l->query(x,y);
		if(x>m)return r->query(x,y);
		return combine(l->query(x,m),r->query(m+1,y));
	}
};

int32_t main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	int n;
	cin >> n;
	
	pii arr[n+5];
	
	//size value
	for(int x=1;x<=n;x++){
		cin >> arr[x].first >> arr[x].second;
	}
	
	sort(arr+1,arr+n+1);
	
	node st(0,n+5);
	
	int counter=0;
	for(int x=1;x<=n;x++){
		counter+=arr[x].second;
		
		st.rangeUpd(x,x,counter-arr[x].first);
	}
	
	int best=0;
	for(int x=1;x<=n;x++){
		int mini=arr[x].first;
		int hold=st.query(x,n);
		best=max(best,hold+mini);
		st.rangeUpd(x,n,-arr[x].second);
	}
	
	cout << best;
	
}

Compilation message

art.cpp: In constructor 'node::node(long long int, long long int)':
art.cpp:20:15: warning: 'node::lazySet' will be initialized after [-Wreorder]
   20 |  int lazyUpd, lazySet;
      |               ^~~~~~~
art.cpp:19:7: warning:   'bool node::lset' [-Wreorder]
   19 |  bool lset;
      |       ^~~~
art.cpp:22:2: warning:   when initialized here [-Wreorder]
   22 |  node(int ss, int ee):s(ss),e(ee),m((s+e)>>1),l(NULL),r(NULL),v(defval),lazyUpd(0),lazySet(setSentinel),lset(0){
      |  ^~~~
art.cpp: In member function 'void node::forceProp()':
art.cpp:47:16: warning: suggest parentheses around assignment used as truth value [-Wparentheses]
   47 |    lset=lazySet=0;
      |         ~~~~~~~^~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 324 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 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 320 KB Output is correct
7 Correct 1 ms 320 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 324 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 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 320 KB Output is correct
7 Correct 1 ms 320 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 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 320 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 324 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 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
# Verdict Execution time Memory Grader output
1 Correct 1 ms 324 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 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 320 KB Output is correct
7 Correct 1 ms 320 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 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 320 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 324 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 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 6 ms 1236 KB Output is correct
28 Correct 8 ms 1228 KB Output is correct
29 Correct 7 ms 1224 KB Output is correct
30 Correct 7 ms 1236 KB Output is correct
31 Correct 6 ms 1236 KB Output is correct
32 Correct 6 ms 1236 KB Output is correct
33 Correct 6 ms 1288 KB Output is correct
34 Correct 7 ms 1268 KB Output is correct
35 Correct 6 ms 1224 KB Output is correct
36 Correct 6 ms 1228 KB Output is correct
37 Correct 6 ms 1288 KB Output is correct
38 Correct 5 ms 1304 KB Output is correct
39 Correct 6 ms 1232 KB Output is correct
40 Correct 6 ms 1236 KB Output is correct
41 Correct 6 ms 1224 KB Output is correct
42 Correct 6 ms 1304 KB Output is correct
43 Correct 6 ms 1304 KB Output is correct
44 Correct 6 ms 1224 KB Output is correct
45 Correct 6 ms 1236 KB Output is correct
46 Correct 6 ms 1248 KB Output is correct
47 Correct 5 ms 1308 KB Output is correct
48 Correct 7 ms 1236 KB Output is correct
49 Correct 9 ms 1236 KB Output is correct
50 Correct 7 ms 1236 KB Output is correct
51 Correct 8 ms 1236 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 324 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 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 320 KB Output is correct
7 Correct 1 ms 320 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 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 320 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 324 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 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 6 ms 1236 KB Output is correct
28 Correct 8 ms 1228 KB Output is correct
29 Correct 7 ms 1224 KB Output is correct
30 Correct 7 ms 1236 KB Output is correct
31 Correct 6 ms 1236 KB Output is correct
32 Correct 6 ms 1236 KB Output is correct
33 Correct 6 ms 1288 KB Output is correct
34 Correct 7 ms 1268 KB Output is correct
35 Correct 6 ms 1224 KB Output is correct
36 Correct 6 ms 1228 KB Output is correct
37 Correct 6 ms 1288 KB Output is correct
38 Correct 5 ms 1304 KB Output is correct
39 Correct 6 ms 1232 KB Output is correct
40 Correct 6 ms 1236 KB Output is correct
41 Correct 6 ms 1224 KB Output is correct
42 Correct 6 ms 1304 KB Output is correct
43 Correct 6 ms 1304 KB Output is correct
44 Correct 6 ms 1224 KB Output is correct
45 Correct 6 ms 1236 KB Output is correct
46 Correct 6 ms 1248 KB Output is correct
47 Correct 5 ms 1308 KB Output is correct
48 Correct 7 ms 1236 KB Output is correct
49 Correct 9 ms 1236 KB Output is correct
50 Correct 7 ms 1236 KB Output is correct
51 Correct 8 ms 1236 KB Output is correct
52 Correct 679 ms 86936 KB Output is correct
53 Correct 649 ms 86860 KB Output is correct
54 Correct 638 ms 86860 KB Output is correct
55 Correct 656 ms 86664 KB Output is correct
56 Correct 667 ms 86928 KB Output is correct
57 Correct 667 ms 86932 KB Output is correct
58 Correct 792 ms 86928 KB Output is correct
59 Correct 721 ms 87040 KB Output is correct
60 Correct 676 ms 86928 KB Output is correct
61 Correct 656 ms 86908 KB Output is correct
62 Correct 639 ms 86932 KB Output is correct
63 Correct 665 ms 86920 KB Output is correct
64 Correct 683 ms 86936 KB Output is correct
65 Correct 680 ms 86928 KB Output is correct
66 Correct 631 ms 86928 KB Output is correct
67 Correct 743 ms 86980 KB Output is correct
68 Correct 651 ms 86928 KB Output is correct