Submission #949913

# Submission time Handle Problem Language Result Execution time Memory
949913 2024-03-19T22:11:08 Z amirhoseinfar1385 Food Court (JOI21_foodcourt) C++17
68 / 100
1000 ms 55324 KB
#include<bits/stdc++.h>
using namespace std;
const long long maxn=250000+10;
long long n,m,q,res[maxn],kaf=(1<<18);
struct que{
	long long l,r,t,k,c;
}allq[maxn];
struct node{
	long long summanf,begol,kamkon;
	node(){
		summanf=begol=kamkon=0;
	}
}fakenode;
struct segment{
	node seg[(1<<19)];
	node merge(node a,node b){
		node ret;
		ret.summanf=a.summanf+b.summanf;
		ret.begol=b.begol+max(0ll,a.begol-b.kamkon);
		ret.kamkon=a.kamkon+max(0ll,b.kamkon-a.begol);
		return ret;
	}
	void ins(long long i){
		long long fu=i;
		i+=kaf;
		if(allq[fu].t==1){
			seg[i].begol=allq[fu].k;
		}else{
			seg[i].summanf=seg[i].kamkon=allq[fu].k;
		}
		i>>=1;
		while(i>0){
			seg[i]=merge(seg[(i<<1)],seg[(i<<1)^1]);
			i>>=1;
		}
	}
	void reset(long long i){
		long long fu=i;
		i+=kaf;
		seg[i].summanf=seg[i].kamkon=seg[i].begol=0;
		i>>=1;
		while(i>0){
			seg[i]=merge(seg[(i<<1)],seg[(i<<1)^1]);
			i>>=1;
		}
	}
	node pors(long long i,long long l,long long r,long long tl,long long tr){
		if(l>r||l>tr||r<tl||tl>tr){
			return fakenode;
		}
		if(l>=tl&&r<=tr){
			return seg[i];
		}
		long long m=(l+r)>>1;
		return merge(pors((i<<1),l,m,tl,tr),pors((i<<1)^1,m+1,r,tl,tr));
	}
}seg;
vector<long long>ins[maxn],del[maxn],por[maxn];

void vorod(){
	cin>>n>>m>>q;
	for(long long i=1;i<=q;i++){
		cin>>allq[i].t;
		if(allq[i].t==1){
			cin>>allq[i].l>>allq[i].r>>allq[i].c>>allq[i].k;
		}else if(allq[i].t==2){
			cin>>allq[i].l>>allq[i].r>>allq[i].k;
		}else{
			cin>>allq[i].l>>allq[i].k;
		}
	}
}

void pre(){
	for(long long i=1;i<=q;i++){
		if(allq[i].t==1){
			ins[allq[i].l].push_back(i);
			del[allq[i].r+1].push_back(i);
		}else if(allq[i].t==2){
			ins[allq[i].l].push_back(i);
			del[allq[i].r+1].push_back(i);
		}else{
			por[allq[i].l].push_back(i);
		}
	}
}

void pors(long long ind){
	node unnow=seg.pors(1,0,kaf-1,0,ind);
	//cout<<"wtf: "<<ind<<" "<<unnow.begol<<" "<<unnow.kamkon<<endl;
	if(unnow.begol<allq[ind].k){
		res[ind]=0;
		return ;
	}
	long long low=-1,high=ind,mid;
	while(high-low>1){
		mid=(high+low)>>1;
		unnow=seg.pors(1,0,kaf-1,0,mid);
		node bad=seg.pors(1,0,kaf-1,mid+1,ind);
		if(unnow.begol-bad.summanf>=allq[ind].k){
			high=mid;
		}else{
			low=mid;
		}
	}
	res[ind]=allq[high].c;
}

void solve(){
	for(long long i=1;i<=n;i++){
		for(auto x:del[i]){
			seg.reset(x);
		}
		for(auto x:ins[i]){
			seg.ins(x);
		}
		for(auto x:por[i]){
			pors(x);
		}
	}	
}

void khor(){
	for(long long i=1;i<=q;i++){
		if(allq[i].t==3){
			cout<<res[i]<<"\n";
		}
	}
}

int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	//freopen("inp.txt","r",stdin);
	vorod();
	pre();
	solve();
	khor();
}

Compilation message

foodcourt.cpp: In member function 'void segment::reset(long long int)':
foodcourt.cpp:38:13: warning: unused variable 'fu' [-Wunused-variable]
   38 |   long long fu=i;
      |             ^~
# Verdict Execution time Memory Grader output
1 Correct 10 ms 33368 KB Output is correct
2 Correct 9 ms 33372 KB Output is correct
3 Correct 8 ms 33372 KB Output is correct
4 Correct 9 ms 33372 KB Output is correct
5 Correct 8 ms 33372 KB Output is correct
6 Correct 8 ms 33472 KB Output is correct
7 Correct 8 ms 33368 KB Output is correct
8 Correct 9 ms 33624 KB Output is correct
9 Correct 9 ms 33572 KB Output is correct
10 Correct 9 ms 33372 KB Output is correct
11 Correct 9 ms 33476 KB Output is correct
12 Correct 9 ms 33372 KB Output is correct
13 Correct 9 ms 33628 KB Output is correct
14 Correct 9 ms 33368 KB Output is correct
15 Correct 9 ms 33372 KB Output is correct
16 Correct 9 ms 33368 KB Output is correct
17 Correct 8 ms 33372 KB Output is correct
18 Correct 9 ms 33576 KB Output is correct
19 Correct 8 ms 33476 KB Output is correct
20 Correct 8 ms 33372 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 10 ms 33368 KB Output is correct
2 Correct 9 ms 33372 KB Output is correct
3 Correct 8 ms 33372 KB Output is correct
4 Correct 9 ms 33372 KB Output is correct
5 Correct 8 ms 33372 KB Output is correct
6 Correct 8 ms 33472 KB Output is correct
7 Correct 8 ms 33368 KB Output is correct
8 Correct 9 ms 33624 KB Output is correct
9 Correct 9 ms 33572 KB Output is correct
10 Correct 9 ms 33372 KB Output is correct
11 Correct 9 ms 33476 KB Output is correct
12 Correct 9 ms 33372 KB Output is correct
13 Correct 9 ms 33628 KB Output is correct
14 Correct 9 ms 33368 KB Output is correct
15 Correct 9 ms 33372 KB Output is correct
16 Correct 9 ms 33368 KB Output is correct
17 Correct 8 ms 33372 KB Output is correct
18 Correct 9 ms 33576 KB Output is correct
19 Correct 8 ms 33476 KB Output is correct
20 Correct 8 ms 33372 KB Output is correct
21 Correct 9 ms 33372 KB Output is correct
22 Correct 10 ms 33372 KB Output is correct
23 Correct 8 ms 33480 KB Output is correct
24 Correct 9 ms 33372 KB Output is correct
25 Correct 8 ms 33476 KB Output is correct
26 Correct 8 ms 33624 KB Output is correct
27 Correct 9 ms 33372 KB Output is correct
28 Correct 9 ms 33372 KB Output is correct
29 Correct 9 ms 33372 KB Output is correct
30 Correct 9 ms 33592 KB Output is correct
31 Correct 9 ms 33480 KB Output is correct
32 Correct 8 ms 33372 KB Output is correct
33 Correct 9 ms 33572 KB Output is correct
34 Correct 9 ms 33372 KB Output is correct
35 Correct 9 ms 33372 KB Output is correct
36 Correct 9 ms 33472 KB Output is correct
37 Correct 8 ms 33624 KB Output is correct
38 Correct 8 ms 33368 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 46 ms 38740 KB Output is correct
2 Correct 49 ms 38976 KB Output is correct
3 Correct 47 ms 38748 KB Output is correct
4 Correct 50 ms 38864 KB Output is correct
5 Correct 47 ms 38932 KB Output is correct
6 Correct 46 ms 38948 KB Output is correct
7 Correct 66 ms 37060 KB Output is correct
8 Correct 72 ms 37060 KB Output is correct
9 Correct 49 ms 38876 KB Output is correct
10 Correct 45 ms 38876 KB Output is correct
11 Correct 46 ms 38740 KB Output is correct
12 Correct 47 ms 38740 KB Output is correct
13 Correct 68 ms 38480 KB Output is correct
14 Correct 81 ms 38740 KB Output is correct
15 Correct 45 ms 38480 KB Output is correct
16 Correct 48 ms 39176 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 684 ms 53592 KB Output is correct
2 Correct 504 ms 51140 KB Output is correct
3 Correct 735 ms 55324 KB Output is correct
4 Correct 446 ms 49748 KB Output is correct
5 Correct 435 ms 51280 KB Output is correct
6 Correct 667 ms 54940 KB Output is correct
7 Correct 511 ms 48660 KB Output is correct
8 Correct 525 ms 48568 KB Output is correct
9 Execution timed out 1012 ms 54352 KB Time limit exceeded
10 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 10 ms 33368 KB Output is correct
2 Correct 9 ms 33372 KB Output is correct
3 Correct 8 ms 33372 KB Output is correct
4 Correct 9 ms 33372 KB Output is correct
5 Correct 8 ms 33372 KB Output is correct
6 Correct 8 ms 33472 KB Output is correct
7 Correct 8 ms 33368 KB Output is correct
8 Correct 9 ms 33624 KB Output is correct
9 Correct 9 ms 33572 KB Output is correct
10 Correct 9 ms 33372 KB Output is correct
11 Correct 9 ms 33476 KB Output is correct
12 Correct 9 ms 33372 KB Output is correct
13 Correct 9 ms 33628 KB Output is correct
14 Correct 9 ms 33368 KB Output is correct
15 Correct 9 ms 33372 KB Output is correct
16 Correct 9 ms 33368 KB Output is correct
17 Correct 8 ms 33372 KB Output is correct
18 Correct 9 ms 33576 KB Output is correct
19 Correct 8 ms 33476 KB Output is correct
20 Correct 8 ms 33372 KB Output is correct
21 Correct 46 ms 38740 KB Output is correct
22 Correct 49 ms 38976 KB Output is correct
23 Correct 47 ms 38748 KB Output is correct
24 Correct 50 ms 38864 KB Output is correct
25 Correct 47 ms 38932 KB Output is correct
26 Correct 46 ms 38948 KB Output is correct
27 Correct 66 ms 37060 KB Output is correct
28 Correct 72 ms 37060 KB Output is correct
29 Correct 49 ms 38876 KB Output is correct
30 Correct 45 ms 38876 KB Output is correct
31 Correct 46 ms 38740 KB Output is correct
32 Correct 47 ms 38740 KB Output is correct
33 Correct 68 ms 38480 KB Output is correct
34 Correct 81 ms 38740 KB Output is correct
35 Correct 45 ms 38480 KB Output is correct
36 Correct 48 ms 39176 KB Output is correct
37 Correct 170 ms 38512 KB Output is correct
38 Correct 96 ms 38244 KB Output is correct
39 Correct 79 ms 37068 KB Output is correct
40 Correct 102 ms 37124 KB Output is correct
41 Correct 126 ms 38740 KB Output is correct
42 Correct 126 ms 38540 KB Output is correct
43 Correct 128 ms 38696 KB Output is correct
44 Correct 128 ms 38740 KB Output is correct
45 Correct 126 ms 38684 KB Output is correct
46 Correct 127 ms 38680 KB Output is correct
47 Correct 130 ms 37560 KB Output is correct
48 Correct 144 ms 37972 KB Output is correct
49 Correct 73 ms 37596 KB Output is correct
50 Correct 95 ms 38456 KB Output is correct
51 Correct 119 ms 38768 KB Output is correct
52 Correct 108 ms 38768 KB Output is correct
53 Correct 43 ms 38228 KB Output is correct
54 Correct 49 ms 39000 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 187 ms 38736 KB Output is correct
2 Correct 221 ms 38764 KB Output is correct
3 Correct 212 ms 38992 KB Output is correct
4 Correct 143 ms 37980 KB Output is correct
5 Correct 183 ms 38492 KB Output is correct
6 Correct 215 ms 38740 KB Output is correct
7 Correct 167 ms 37080 KB Output is correct
8 Correct 151 ms 37192 KB Output is correct
9 Correct 214 ms 37960 KB Output is correct
10 Correct 139 ms 37468 KB Output is correct
11 Correct 202 ms 38224 KB Output is correct
12 Correct 213 ms 38068 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 10 ms 33368 KB Output is correct
2 Correct 9 ms 33372 KB Output is correct
3 Correct 8 ms 33372 KB Output is correct
4 Correct 9 ms 33372 KB Output is correct
5 Correct 8 ms 33372 KB Output is correct
6 Correct 8 ms 33472 KB Output is correct
7 Correct 8 ms 33368 KB Output is correct
8 Correct 9 ms 33624 KB Output is correct
9 Correct 9 ms 33572 KB Output is correct
10 Correct 9 ms 33372 KB Output is correct
11 Correct 9 ms 33476 KB Output is correct
12 Correct 9 ms 33372 KB Output is correct
13 Correct 9 ms 33628 KB Output is correct
14 Correct 9 ms 33368 KB Output is correct
15 Correct 9 ms 33372 KB Output is correct
16 Correct 9 ms 33368 KB Output is correct
17 Correct 8 ms 33372 KB Output is correct
18 Correct 9 ms 33576 KB Output is correct
19 Correct 8 ms 33476 KB Output is correct
20 Correct 8 ms 33372 KB Output is correct
21 Correct 9 ms 33372 KB Output is correct
22 Correct 10 ms 33372 KB Output is correct
23 Correct 8 ms 33480 KB Output is correct
24 Correct 9 ms 33372 KB Output is correct
25 Correct 8 ms 33476 KB Output is correct
26 Correct 8 ms 33624 KB Output is correct
27 Correct 9 ms 33372 KB Output is correct
28 Correct 9 ms 33372 KB Output is correct
29 Correct 9 ms 33372 KB Output is correct
30 Correct 9 ms 33592 KB Output is correct
31 Correct 9 ms 33480 KB Output is correct
32 Correct 8 ms 33372 KB Output is correct
33 Correct 9 ms 33572 KB Output is correct
34 Correct 9 ms 33372 KB Output is correct
35 Correct 9 ms 33372 KB Output is correct
36 Correct 9 ms 33472 KB Output is correct
37 Correct 8 ms 33624 KB Output is correct
38 Correct 8 ms 33368 KB Output is correct
39 Correct 46 ms 38740 KB Output is correct
40 Correct 49 ms 38976 KB Output is correct
41 Correct 47 ms 38748 KB Output is correct
42 Correct 50 ms 38864 KB Output is correct
43 Correct 47 ms 38932 KB Output is correct
44 Correct 46 ms 38948 KB Output is correct
45 Correct 66 ms 37060 KB Output is correct
46 Correct 72 ms 37060 KB Output is correct
47 Correct 49 ms 38876 KB Output is correct
48 Correct 45 ms 38876 KB Output is correct
49 Correct 46 ms 38740 KB Output is correct
50 Correct 47 ms 38740 KB Output is correct
51 Correct 68 ms 38480 KB Output is correct
52 Correct 81 ms 38740 KB Output is correct
53 Correct 45 ms 38480 KB Output is correct
54 Correct 48 ms 39176 KB Output is correct
55 Correct 170 ms 38512 KB Output is correct
56 Correct 96 ms 38244 KB Output is correct
57 Correct 79 ms 37068 KB Output is correct
58 Correct 102 ms 37124 KB Output is correct
59 Correct 126 ms 38740 KB Output is correct
60 Correct 126 ms 38540 KB Output is correct
61 Correct 128 ms 38696 KB Output is correct
62 Correct 128 ms 38740 KB Output is correct
63 Correct 126 ms 38684 KB Output is correct
64 Correct 127 ms 38680 KB Output is correct
65 Correct 130 ms 37560 KB Output is correct
66 Correct 144 ms 37972 KB Output is correct
67 Correct 73 ms 37596 KB Output is correct
68 Correct 95 ms 38456 KB Output is correct
69 Correct 119 ms 38768 KB Output is correct
70 Correct 108 ms 38768 KB Output is correct
71 Correct 43 ms 38228 KB Output is correct
72 Correct 49 ms 39000 KB Output is correct
73 Correct 187 ms 38736 KB Output is correct
74 Correct 221 ms 38764 KB Output is correct
75 Correct 212 ms 38992 KB Output is correct
76 Correct 143 ms 37980 KB Output is correct
77 Correct 183 ms 38492 KB Output is correct
78 Correct 215 ms 38740 KB Output is correct
79 Correct 167 ms 37080 KB Output is correct
80 Correct 151 ms 37192 KB Output is correct
81 Correct 214 ms 37960 KB Output is correct
82 Correct 139 ms 37468 KB Output is correct
83 Correct 202 ms 38224 KB Output is correct
84 Correct 213 ms 38068 KB Output is correct
85 Correct 136 ms 38584 KB Output is correct
86 Correct 152 ms 38992 KB Output is correct
87 Correct 114 ms 38772 KB Output is correct
88 Correct 132 ms 39144 KB Output is correct
89 Correct 82 ms 37772 KB Output is correct
90 Correct 128 ms 38840 KB Output is correct
91 Correct 101 ms 38420 KB Output is correct
92 Correct 95 ms 37980 KB Output is correct
93 Correct 127 ms 38996 KB Output is correct
94 Correct 136 ms 38828 KB Output is correct
95 Correct 140 ms 38916 KB Output is correct
96 Correct 144 ms 38996 KB Output is correct
97 Correct 131 ms 38992 KB Output is correct
98 Correct 109 ms 38436 KB Output is correct
99 Correct 150 ms 37808 KB Output is correct
100 Correct 132 ms 37460 KB Output is correct
101 Correct 140 ms 38224 KB Output is correct
102 Correct 118 ms 39512 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 10 ms 33368 KB Output is correct
2 Correct 9 ms 33372 KB Output is correct
3 Correct 8 ms 33372 KB Output is correct
4 Correct 9 ms 33372 KB Output is correct
5 Correct 8 ms 33372 KB Output is correct
6 Correct 8 ms 33472 KB Output is correct
7 Correct 8 ms 33368 KB Output is correct
8 Correct 9 ms 33624 KB Output is correct
9 Correct 9 ms 33572 KB Output is correct
10 Correct 9 ms 33372 KB Output is correct
11 Correct 9 ms 33476 KB Output is correct
12 Correct 9 ms 33372 KB Output is correct
13 Correct 9 ms 33628 KB Output is correct
14 Correct 9 ms 33368 KB Output is correct
15 Correct 9 ms 33372 KB Output is correct
16 Correct 9 ms 33368 KB Output is correct
17 Correct 8 ms 33372 KB Output is correct
18 Correct 9 ms 33576 KB Output is correct
19 Correct 8 ms 33476 KB Output is correct
20 Correct 8 ms 33372 KB Output is correct
21 Correct 9 ms 33372 KB Output is correct
22 Correct 10 ms 33372 KB Output is correct
23 Correct 8 ms 33480 KB Output is correct
24 Correct 9 ms 33372 KB Output is correct
25 Correct 8 ms 33476 KB Output is correct
26 Correct 8 ms 33624 KB Output is correct
27 Correct 9 ms 33372 KB Output is correct
28 Correct 9 ms 33372 KB Output is correct
29 Correct 9 ms 33372 KB Output is correct
30 Correct 9 ms 33592 KB Output is correct
31 Correct 9 ms 33480 KB Output is correct
32 Correct 8 ms 33372 KB Output is correct
33 Correct 9 ms 33572 KB Output is correct
34 Correct 9 ms 33372 KB Output is correct
35 Correct 9 ms 33372 KB Output is correct
36 Correct 9 ms 33472 KB Output is correct
37 Correct 8 ms 33624 KB Output is correct
38 Correct 8 ms 33368 KB Output is correct
39 Correct 46 ms 38740 KB Output is correct
40 Correct 49 ms 38976 KB Output is correct
41 Correct 47 ms 38748 KB Output is correct
42 Correct 50 ms 38864 KB Output is correct
43 Correct 47 ms 38932 KB Output is correct
44 Correct 46 ms 38948 KB Output is correct
45 Correct 66 ms 37060 KB Output is correct
46 Correct 72 ms 37060 KB Output is correct
47 Correct 49 ms 38876 KB Output is correct
48 Correct 45 ms 38876 KB Output is correct
49 Correct 46 ms 38740 KB Output is correct
50 Correct 47 ms 38740 KB Output is correct
51 Correct 68 ms 38480 KB Output is correct
52 Correct 81 ms 38740 KB Output is correct
53 Correct 45 ms 38480 KB Output is correct
54 Correct 48 ms 39176 KB Output is correct
55 Correct 684 ms 53592 KB Output is correct
56 Correct 504 ms 51140 KB Output is correct
57 Correct 735 ms 55324 KB Output is correct
58 Correct 446 ms 49748 KB Output is correct
59 Correct 435 ms 51280 KB Output is correct
60 Correct 667 ms 54940 KB Output is correct
61 Correct 511 ms 48660 KB Output is correct
62 Correct 525 ms 48568 KB Output is correct
63 Execution timed out 1012 ms 54352 KB Time limit exceeded
64 Halted 0 ms 0 KB -