Submission #563896

# Submission time Handle Problem Language Result Execution time Memory
563896 2022-05-18T09:01:35 Z errorgorn Two Dishes (JOI19_dishes) C++17
100 / 100
5848 ms 300896 KB
#include <bits/stdc++.h>
using namespace std;

#define int long long
#define ii pair<int,int>
#define fi first
#define se second
#define endl '\n'

#define puf push_front
#define pof pop_front
#define pub push_back
#define pob pop_back
#define lb lower_bound
#define ub upper_bound

#define rep(x,s,e) for (int x=(s)-((s)>(e));x!=(e)-((s)>(e));((s)<(e)?x++:x--))
#define all(x) (x).begin(),(x).end()
#define sz(x) (int) (x).size()

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const int INF=1e18;

int n,m;
int arr[2][1000005];
int brr[2][1000005];
int crr[2][1000005];
int drr[2][1000005];

struct node{
	int s,e,m;
	int val=0; //stores the max value
	int lazy=0;
	bool lazyt=false; //false = increment, true = set
	node *l,*r;
	
	node (int _s,int _e){
		s=_s,e=_e,m=s+e>>1;
		
		if (s!=e){
			l=new node(s,m);
			r=new node(m+1,e);
		}
	}
	
	void propo(){
		if (lazyt){
			val=lazy;
			if (s!=e){
				l->lazy=r->lazy=lazy;
				l->lazyt=r->lazyt=true;
			}
		}
		else if (lazy){
			val+=lazy;
			if (s!=e){
				l->lazy+=lazy;
				r->lazy+=lazy;
			}
		}
		
		lazy=0;
		lazyt=false;
	}
	
	void update1(int i,int j,int k){
		propo();
		if (s==i && e==j) lazy+=k;
		else{
			if (j<=m) l->update1(i,j,k);
			else if (m<i) r->update1(i,j,k);
			else l->update1(i,m,k),r->update1(m+1,j,k);
			
			l->propo(),r->propo();
			val=max(l->val,r->val);
		}
	}
	
	void update2(int i,int j,int k){
		propo();
		if (s==i && e==j){
			lazy=k;
			lazyt=true;
		}
		else{
			if (j<=m) l->update2(i,j,k);
			else if (m<i) r->update2(i,j,k);
			else l->update2(i,m,k),r->update2(m+1,j,k);
			
			l->propo(),r->propo();
			val=max(l->val,r->val);
		}
	}
	
	int getr(int i,int k){
		propo();
		
		if (val<k) return -1;
		if (s==e) return s;
		if (m<i) return r->getr(i,k);
		else{
			int temp=l->getr(i,k);
			if (temp!=-1) return temp;
			else return r->getr(i,k);
		}
	}
	
	int query(int i){
		propo();
		
		if (s==e) return val;
		else if (i<=m) return l->query(i);
		else return r->query(i);
	}
} *root=new node(0,1000005);

void expand(int i){
	int val=root->query(i);
	int temp=root->getr(i+1,val);
	if (temp==-1) root->update2(i+1,1000005,val);
	else if (temp!=i+1) root->update2(i+1,temp-1,val);
}

signed main(){
	cin.tie(0);
	cout.tie(0);
	cin.sync_with_stdio(false);
	
	cin>>n>>m;
	
	rep(x,1,n+1) cin>>arr[0][x]>>brr[0][x]>>crr[0][x];
	rep(x,1,m+1) cin>>arr[1][x]>>brr[1][x]>>crr[1][x];
	
	rep(x,1,n+1) arr[0][x]+=arr[0][x-1];
	rep(x,1,m+1) arr[1][x]+=arr[1][x-1];
	
	//rep(x,0,n+1) cout<<arr[0][x]<<" "; cout<<endl;
	rep(x,1,n+1) drr[0][x]=ub(arr[1],arr[1]+m+1,brr[0][x]-arr[0][x])-arr[1];
	rep(x,1,m+1) drr[1][x]=ub(arr[0],arr[0]+n+1,brr[1][x]-arr[1][x])-arr[0];
	
	//rep(x,1,n+1) cout<<drr[0][x]<<" "; cout<<endl;
	//rep(x,1,m+1) cout<<drr[1][x]<<" "; cout<<endl;
	
	vector<int> idx;
	rep(x,1,m+1) if (drr[1][x]) idx.pub(x);
	sort(all(idx),[](int i,int j){
		return drr[1][i]>drr[1][j];
	});
	
	rep(x,1,n+2){
		vector<int> pos;
		while (!idx.empty() && drr[1][idx.back()]==x){
			int u=idx.back(); idx.pob();
			root->update1(u,1000005,crr[1][u]); //we cannot expand here
			pos.pub(u-1);
		}
		
		if (x!=n+1 && drr[0][x]){
			root->update1(0,drr[0][x]-1,crr[0][x]);
			pos.pub(drr[0][x]-1);
		}
		
		sort(all(pos));
		if (x!=n+1) for (auto it:pos) expand(it);
	}
	
	cout<<root->query(m)<<endl;
}

Compilation message

dishes.cpp: In constructor 'node::node(long long int, long long int)':
dishes.cpp:39:16: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   39 |   s=_s,e=_e,m=s+e>>1;
      |               ~^~
# Verdict Execution time Memory Grader output
1 Correct 486 ms 171948 KB Output is correct
2 Correct 578 ms 171896 KB Output is correct
3 Correct 504 ms 174488 KB Output is correct
4 Correct 409 ms 170808 KB Output is correct
5 Correct 116 ms 156900 KB Output is correct
6 Correct 519 ms 171568 KB Output is correct
7 Correct 258 ms 168036 KB Output is correct
8 Correct 329 ms 163572 KB Output is correct
9 Correct 504 ms 174652 KB Output is correct
10 Correct 508 ms 171968 KB Output is correct
11 Correct 439 ms 174392 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 117 ms 156884 KB Output is correct
2 Correct 102 ms 156808 KB Output is correct
3 Correct 102 ms 156888 KB Output is correct
4 Correct 103 ms 156852 KB Output is correct
5 Correct 109 ms 156876 KB Output is correct
6 Correct 105 ms 156940 KB Output is correct
7 Correct 106 ms 156812 KB Output is correct
8 Correct 105 ms 156932 KB Output is correct
9 Correct 109 ms 156872 KB Output is correct
10 Correct 119 ms 156876 KB Output is correct
11 Correct 133 ms 156812 KB Output is correct
12 Correct 105 ms 156832 KB Output is correct
13 Correct 107 ms 156848 KB Output is correct
14 Correct 109 ms 156908 KB Output is correct
15 Correct 106 ms 156852 KB Output is correct
16 Correct 105 ms 156828 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 117 ms 156884 KB Output is correct
2 Correct 102 ms 156808 KB Output is correct
3 Correct 102 ms 156888 KB Output is correct
4 Correct 103 ms 156852 KB Output is correct
5 Correct 109 ms 156876 KB Output is correct
6 Correct 105 ms 156940 KB Output is correct
7 Correct 106 ms 156812 KB Output is correct
8 Correct 105 ms 156932 KB Output is correct
9 Correct 109 ms 156872 KB Output is correct
10 Correct 119 ms 156876 KB Output is correct
11 Correct 133 ms 156812 KB Output is correct
12 Correct 105 ms 156832 KB Output is correct
13 Correct 107 ms 156848 KB Output is correct
14 Correct 109 ms 156908 KB Output is correct
15 Correct 106 ms 156852 KB Output is correct
16 Correct 105 ms 156828 KB Output is correct
17 Correct 111 ms 157140 KB Output is correct
18 Correct 118 ms 157128 KB Output is correct
19 Correct 112 ms 157084 KB Output is correct
20 Correct 110 ms 157084 KB Output is correct
21 Correct 111 ms 157056 KB Output is correct
22 Correct 110 ms 157124 KB Output is correct
23 Correct 129 ms 157048 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 117 ms 156884 KB Output is correct
2 Correct 102 ms 156808 KB Output is correct
3 Correct 102 ms 156888 KB Output is correct
4 Correct 103 ms 156852 KB Output is correct
5 Correct 109 ms 156876 KB Output is correct
6 Correct 105 ms 156940 KB Output is correct
7 Correct 106 ms 156812 KB Output is correct
8 Correct 105 ms 156932 KB Output is correct
9 Correct 109 ms 156872 KB Output is correct
10 Correct 119 ms 156876 KB Output is correct
11 Correct 133 ms 156812 KB Output is correct
12 Correct 105 ms 156832 KB Output is correct
13 Correct 107 ms 156848 KB Output is correct
14 Correct 109 ms 156908 KB Output is correct
15 Correct 106 ms 156852 KB Output is correct
16 Correct 105 ms 156828 KB Output is correct
17 Correct 111 ms 157140 KB Output is correct
18 Correct 118 ms 157128 KB Output is correct
19 Correct 112 ms 157084 KB Output is correct
20 Correct 110 ms 157084 KB Output is correct
21 Correct 111 ms 157056 KB Output is correct
22 Correct 110 ms 157124 KB Output is correct
23 Correct 129 ms 157048 KB Output is correct
24 Correct 430 ms 172172 KB Output is correct
25 Correct 449 ms 174800 KB Output is correct
26 Correct 449 ms 172548 KB Output is correct
27 Correct 475 ms 172352 KB Output is correct
28 Correct 642 ms 173628 KB Output is correct
29 Correct 475 ms 174904 KB Output is correct
30 Correct 1114 ms 172368 KB Output is correct
31 Correct 289 ms 167348 KB Output is correct
32 Correct 336 ms 163956 KB Output is correct
33 Correct 645 ms 171184 KB Output is correct
34 Correct 883 ms 172108 KB Output is correct
35 Correct 948 ms 172352 KB Output is correct
36 Correct 942 ms 172400 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 117 ms 156884 KB Output is correct
2 Correct 102 ms 156808 KB Output is correct
3 Correct 102 ms 156888 KB Output is correct
4 Correct 103 ms 156852 KB Output is correct
5 Correct 109 ms 156876 KB Output is correct
6 Correct 105 ms 156940 KB Output is correct
7 Correct 106 ms 156812 KB Output is correct
8 Correct 105 ms 156932 KB Output is correct
9 Correct 109 ms 156872 KB Output is correct
10 Correct 119 ms 156876 KB Output is correct
11 Correct 133 ms 156812 KB Output is correct
12 Correct 105 ms 156832 KB Output is correct
13 Correct 107 ms 156848 KB Output is correct
14 Correct 109 ms 156908 KB Output is correct
15 Correct 106 ms 156852 KB Output is correct
16 Correct 105 ms 156828 KB Output is correct
17 Correct 111 ms 157140 KB Output is correct
18 Correct 118 ms 157128 KB Output is correct
19 Correct 112 ms 157084 KB Output is correct
20 Correct 110 ms 157084 KB Output is correct
21 Correct 111 ms 157056 KB Output is correct
22 Correct 110 ms 157124 KB Output is correct
23 Correct 129 ms 157048 KB Output is correct
24 Correct 430 ms 172172 KB Output is correct
25 Correct 449 ms 174800 KB Output is correct
26 Correct 449 ms 172548 KB Output is correct
27 Correct 475 ms 172352 KB Output is correct
28 Correct 642 ms 173628 KB Output is correct
29 Correct 475 ms 174904 KB Output is correct
30 Correct 1114 ms 172368 KB Output is correct
31 Correct 289 ms 167348 KB Output is correct
32 Correct 336 ms 163956 KB Output is correct
33 Correct 645 ms 171184 KB Output is correct
34 Correct 883 ms 172108 KB Output is correct
35 Correct 948 ms 172352 KB Output is correct
36 Correct 942 ms 172400 KB Output is correct
37 Correct 455 ms 172556 KB Output is correct
38 Correct 484 ms 172060 KB Output is correct
39 Correct 457 ms 172248 KB Output is correct
40 Correct 596 ms 172064 KB Output is correct
41 Correct 103 ms 156872 KB Output is correct
42 Correct 985 ms 172192 KB Output is correct
43 Correct 619 ms 170988 KB Output is correct
44 Correct 829 ms 171780 KB Output is correct
45 Correct 956 ms 172076 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 117 ms 156884 KB Output is correct
2 Correct 102 ms 156808 KB Output is correct
3 Correct 102 ms 156888 KB Output is correct
4 Correct 103 ms 156852 KB Output is correct
5 Correct 109 ms 156876 KB Output is correct
6 Correct 105 ms 156940 KB Output is correct
7 Correct 106 ms 156812 KB Output is correct
8 Correct 105 ms 156932 KB Output is correct
9 Correct 109 ms 156872 KB Output is correct
10 Correct 119 ms 156876 KB Output is correct
11 Correct 133 ms 156812 KB Output is correct
12 Correct 105 ms 156832 KB Output is correct
13 Correct 107 ms 156848 KB Output is correct
14 Correct 109 ms 156908 KB Output is correct
15 Correct 106 ms 156852 KB Output is correct
16 Correct 105 ms 156828 KB Output is correct
17 Correct 111 ms 157140 KB Output is correct
18 Correct 118 ms 157128 KB Output is correct
19 Correct 112 ms 157084 KB Output is correct
20 Correct 110 ms 157084 KB Output is correct
21 Correct 111 ms 157056 KB Output is correct
22 Correct 110 ms 157124 KB Output is correct
23 Correct 129 ms 157048 KB Output is correct
24 Correct 430 ms 172172 KB Output is correct
25 Correct 449 ms 174800 KB Output is correct
26 Correct 449 ms 172548 KB Output is correct
27 Correct 475 ms 172352 KB Output is correct
28 Correct 642 ms 173628 KB Output is correct
29 Correct 475 ms 174904 KB Output is correct
30 Correct 1114 ms 172368 KB Output is correct
31 Correct 289 ms 167348 KB Output is correct
32 Correct 336 ms 163956 KB Output is correct
33 Correct 645 ms 171184 KB Output is correct
34 Correct 883 ms 172108 KB Output is correct
35 Correct 948 ms 172352 KB Output is correct
36 Correct 942 ms 172400 KB Output is correct
37 Correct 455 ms 172556 KB Output is correct
38 Correct 484 ms 172060 KB Output is correct
39 Correct 457 ms 172248 KB Output is correct
40 Correct 596 ms 172064 KB Output is correct
41 Correct 103 ms 156872 KB Output is correct
42 Correct 985 ms 172192 KB Output is correct
43 Correct 619 ms 170988 KB Output is correct
44 Correct 829 ms 171780 KB Output is correct
45 Correct 956 ms 172076 KB Output is correct
46 Correct 1873 ms 229840 KB Output is correct
47 Correct 1985 ms 228084 KB Output is correct
48 Correct 1858 ms 228084 KB Output is correct
49 Correct 2769 ms 228092 KB Output is correct
50 Correct 5647 ms 228020 KB Output is correct
51 Correct 3090 ms 222164 KB Output is correct
52 Correct 4077 ms 226096 KB Output is correct
53 Correct 5240 ms 227880 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 486 ms 171948 KB Output is correct
2 Correct 578 ms 171896 KB Output is correct
3 Correct 504 ms 174488 KB Output is correct
4 Correct 409 ms 170808 KB Output is correct
5 Correct 116 ms 156900 KB Output is correct
6 Correct 519 ms 171568 KB Output is correct
7 Correct 258 ms 168036 KB Output is correct
8 Correct 329 ms 163572 KB Output is correct
9 Correct 504 ms 174652 KB Output is correct
10 Correct 508 ms 171968 KB Output is correct
11 Correct 439 ms 174392 KB Output is correct
12 Correct 117 ms 156884 KB Output is correct
13 Correct 102 ms 156808 KB Output is correct
14 Correct 102 ms 156888 KB Output is correct
15 Correct 103 ms 156852 KB Output is correct
16 Correct 109 ms 156876 KB Output is correct
17 Correct 105 ms 156940 KB Output is correct
18 Correct 106 ms 156812 KB Output is correct
19 Correct 105 ms 156932 KB Output is correct
20 Correct 109 ms 156872 KB Output is correct
21 Correct 119 ms 156876 KB Output is correct
22 Correct 133 ms 156812 KB Output is correct
23 Correct 105 ms 156832 KB Output is correct
24 Correct 107 ms 156848 KB Output is correct
25 Correct 109 ms 156908 KB Output is correct
26 Correct 106 ms 156852 KB Output is correct
27 Correct 105 ms 156828 KB Output is correct
28 Correct 111 ms 157140 KB Output is correct
29 Correct 118 ms 157128 KB Output is correct
30 Correct 112 ms 157084 KB Output is correct
31 Correct 110 ms 157084 KB Output is correct
32 Correct 111 ms 157056 KB Output is correct
33 Correct 110 ms 157124 KB Output is correct
34 Correct 129 ms 157048 KB Output is correct
35 Correct 430 ms 172172 KB Output is correct
36 Correct 449 ms 174800 KB Output is correct
37 Correct 449 ms 172548 KB Output is correct
38 Correct 475 ms 172352 KB Output is correct
39 Correct 642 ms 173628 KB Output is correct
40 Correct 475 ms 174904 KB Output is correct
41 Correct 1114 ms 172368 KB Output is correct
42 Correct 289 ms 167348 KB Output is correct
43 Correct 336 ms 163956 KB Output is correct
44 Correct 645 ms 171184 KB Output is correct
45 Correct 883 ms 172108 KB Output is correct
46 Correct 948 ms 172352 KB Output is correct
47 Correct 942 ms 172400 KB Output is correct
48 Correct 455 ms 172556 KB Output is correct
49 Correct 484 ms 172060 KB Output is correct
50 Correct 457 ms 172248 KB Output is correct
51 Correct 596 ms 172064 KB Output is correct
52 Correct 103 ms 156872 KB Output is correct
53 Correct 985 ms 172192 KB Output is correct
54 Correct 619 ms 170988 KB Output is correct
55 Correct 829 ms 171780 KB Output is correct
56 Correct 956 ms 172076 KB Output is correct
57 Correct 409 ms 171704 KB Output is correct
58 Correct 529 ms 185760 KB Output is correct
59 Correct 598 ms 183564 KB Output is correct
60 Correct 470 ms 183560 KB Output is correct
61 Correct 751 ms 182320 KB Output is correct
62 Correct 108 ms 156824 KB Output is correct
63 Correct 1006 ms 185644 KB Output is correct
64 Correct 650 ms 183864 KB Output is correct
65 Correct 961 ms 185328 KB Output is correct
66 Correct 975 ms 179108 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 486 ms 171948 KB Output is correct
2 Correct 578 ms 171896 KB Output is correct
3 Correct 504 ms 174488 KB Output is correct
4 Correct 409 ms 170808 KB Output is correct
5 Correct 116 ms 156900 KB Output is correct
6 Correct 519 ms 171568 KB Output is correct
7 Correct 258 ms 168036 KB Output is correct
8 Correct 329 ms 163572 KB Output is correct
9 Correct 504 ms 174652 KB Output is correct
10 Correct 508 ms 171968 KB Output is correct
11 Correct 439 ms 174392 KB Output is correct
12 Correct 117 ms 156884 KB Output is correct
13 Correct 102 ms 156808 KB Output is correct
14 Correct 102 ms 156888 KB Output is correct
15 Correct 103 ms 156852 KB Output is correct
16 Correct 109 ms 156876 KB Output is correct
17 Correct 105 ms 156940 KB Output is correct
18 Correct 106 ms 156812 KB Output is correct
19 Correct 105 ms 156932 KB Output is correct
20 Correct 109 ms 156872 KB Output is correct
21 Correct 119 ms 156876 KB Output is correct
22 Correct 133 ms 156812 KB Output is correct
23 Correct 105 ms 156832 KB Output is correct
24 Correct 107 ms 156848 KB Output is correct
25 Correct 109 ms 156908 KB Output is correct
26 Correct 106 ms 156852 KB Output is correct
27 Correct 105 ms 156828 KB Output is correct
28 Correct 111 ms 157140 KB Output is correct
29 Correct 118 ms 157128 KB Output is correct
30 Correct 112 ms 157084 KB Output is correct
31 Correct 110 ms 157084 KB Output is correct
32 Correct 111 ms 157056 KB Output is correct
33 Correct 110 ms 157124 KB Output is correct
34 Correct 129 ms 157048 KB Output is correct
35 Correct 430 ms 172172 KB Output is correct
36 Correct 449 ms 174800 KB Output is correct
37 Correct 449 ms 172548 KB Output is correct
38 Correct 475 ms 172352 KB Output is correct
39 Correct 642 ms 173628 KB Output is correct
40 Correct 475 ms 174904 KB Output is correct
41 Correct 1114 ms 172368 KB Output is correct
42 Correct 289 ms 167348 KB Output is correct
43 Correct 336 ms 163956 KB Output is correct
44 Correct 645 ms 171184 KB Output is correct
45 Correct 883 ms 172108 KB Output is correct
46 Correct 948 ms 172352 KB Output is correct
47 Correct 942 ms 172400 KB Output is correct
48 Correct 455 ms 172556 KB Output is correct
49 Correct 484 ms 172060 KB Output is correct
50 Correct 457 ms 172248 KB Output is correct
51 Correct 596 ms 172064 KB Output is correct
52 Correct 103 ms 156872 KB Output is correct
53 Correct 985 ms 172192 KB Output is correct
54 Correct 619 ms 170988 KB Output is correct
55 Correct 829 ms 171780 KB Output is correct
56 Correct 956 ms 172076 KB Output is correct
57 Correct 1873 ms 229840 KB Output is correct
58 Correct 1985 ms 228084 KB Output is correct
59 Correct 1858 ms 228084 KB Output is correct
60 Correct 2769 ms 228092 KB Output is correct
61 Correct 5647 ms 228020 KB Output is correct
62 Correct 3090 ms 222164 KB Output is correct
63 Correct 4077 ms 226096 KB Output is correct
64 Correct 5240 ms 227880 KB Output is correct
65 Correct 409 ms 171704 KB Output is correct
66 Correct 529 ms 185760 KB Output is correct
67 Correct 598 ms 183564 KB Output is correct
68 Correct 470 ms 183560 KB Output is correct
69 Correct 751 ms 182320 KB Output is correct
70 Correct 108 ms 156824 KB Output is correct
71 Correct 1006 ms 185644 KB Output is correct
72 Correct 650 ms 183864 KB Output is correct
73 Correct 961 ms 185328 KB Output is correct
74 Correct 975 ms 179108 KB Output is correct
75 Correct 1700 ms 300896 KB Output is correct
76 Correct 2404 ms 299308 KB Output is correct
77 Correct 2894 ms 283860 KB Output is correct
78 Correct 1960 ms 281828 KB Output is correct
79 Correct 5848 ms 293140 KB Output is correct
80 Correct 3235 ms 288628 KB Output is correct
81 Correct 4359 ms 296912 KB Output is correct
82 Correct 5620 ms 265960 KB Output is correct
83 Correct 5472 ms 282152 KB Output is correct