답안 #949912

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
949912 2024-03-19T22:10:05 Z amirhoseinfar1385 푸드 코트 (JOI21_foodcourt) C++17
68 / 100
1000 ms 70200 KB
#include<bits/stdc++.h>
using namespace std;
const long long maxn=250000+10;
long long n,m,q,res[maxn],kaf=(1<<19);
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<<20)];
	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;
      |             ^~
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 45660 KB Output is correct
2 Correct 11 ms 45660 KB Output is correct
3 Correct 12 ms 45792 KB Output is correct
4 Correct 10 ms 45660 KB Output is correct
5 Correct 10 ms 45656 KB Output is correct
6 Correct 10 ms 45660 KB Output is correct
7 Correct 11 ms 45660 KB Output is correct
8 Correct 10 ms 45660 KB Output is correct
9 Correct 10 ms 45660 KB Output is correct
10 Correct 11 ms 45660 KB Output is correct
11 Correct 11 ms 45660 KB Output is correct
12 Correct 10 ms 45912 KB Output is correct
13 Correct 10 ms 45660 KB Output is correct
14 Correct 11 ms 45656 KB Output is correct
15 Correct 10 ms 45660 KB Output is correct
16 Correct 11 ms 45660 KB Output is correct
17 Correct 10 ms 45800 KB Output is correct
18 Correct 11 ms 45660 KB Output is correct
19 Correct 10 ms 45748 KB Output is correct
20 Correct 10 ms 45660 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 45660 KB Output is correct
2 Correct 11 ms 45660 KB Output is correct
3 Correct 12 ms 45792 KB Output is correct
4 Correct 10 ms 45660 KB Output is correct
5 Correct 10 ms 45656 KB Output is correct
6 Correct 10 ms 45660 KB Output is correct
7 Correct 11 ms 45660 KB Output is correct
8 Correct 10 ms 45660 KB Output is correct
9 Correct 10 ms 45660 KB Output is correct
10 Correct 11 ms 45660 KB Output is correct
11 Correct 11 ms 45660 KB Output is correct
12 Correct 10 ms 45912 KB Output is correct
13 Correct 10 ms 45660 KB Output is correct
14 Correct 11 ms 45656 KB Output is correct
15 Correct 10 ms 45660 KB Output is correct
16 Correct 11 ms 45660 KB Output is correct
17 Correct 10 ms 45800 KB Output is correct
18 Correct 11 ms 45660 KB Output is correct
19 Correct 10 ms 45748 KB Output is correct
20 Correct 10 ms 45660 KB Output is correct
21 Correct 11 ms 45656 KB Output is correct
22 Correct 12 ms 45660 KB Output is correct
23 Correct 11 ms 45656 KB Output is correct
24 Correct 10 ms 45660 KB Output is correct
25 Correct 11 ms 45660 KB Output is correct
26 Correct 10 ms 45660 KB Output is correct
27 Correct 11 ms 45660 KB Output is correct
28 Correct 10 ms 45660 KB Output is correct
29 Correct 10 ms 45660 KB Output is correct
30 Correct 11 ms 45660 KB Output is correct
31 Correct 11 ms 45660 KB Output is correct
32 Correct 11 ms 45660 KB Output is correct
33 Correct 10 ms 45656 KB Output is correct
34 Correct 11 ms 45660 KB Output is correct
35 Correct 11 ms 45796 KB Output is correct
36 Correct 11 ms 45660 KB Output is correct
37 Correct 9 ms 45660 KB Output is correct
38 Correct 10 ms 45896 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 54 ms 50428 KB Output is correct
2 Correct 57 ms 50372 KB Output is correct
3 Correct 48 ms 50256 KB Output is correct
4 Correct 49 ms 50268 KB Output is correct
5 Correct 52 ms 50384 KB Output is correct
6 Correct 53 ms 50296 KB Output is correct
7 Correct 68 ms 48696 KB Output is correct
8 Correct 74 ms 48848 KB Output is correct
9 Correct 52 ms 50268 KB Output is correct
10 Correct 46 ms 50432 KB Output is correct
11 Correct 47 ms 50456 KB Output is correct
12 Correct 50 ms 50260 KB Output is correct
13 Correct 70 ms 50004 KB Output is correct
14 Correct 82 ms 50256 KB Output is correct
15 Correct 49 ms 50116 KB Output is correct
16 Correct 49 ms 50476 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 681 ms 68460 KB Output is correct
2 Correct 510 ms 65348 KB Output is correct
3 Correct 768 ms 69996 KB Output is correct
4 Correct 453 ms 63828 KB Output is correct
5 Correct 448 ms 65540 KB Output is correct
6 Correct 638 ms 70200 KB Output is correct
7 Correct 527 ms 62832 KB Output is correct
8 Correct 537 ms 62904 KB Output is correct
9 Execution timed out 1016 ms 69312 KB Time limit exceeded
10 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 45660 KB Output is correct
2 Correct 11 ms 45660 KB Output is correct
3 Correct 12 ms 45792 KB Output is correct
4 Correct 10 ms 45660 KB Output is correct
5 Correct 10 ms 45656 KB Output is correct
6 Correct 10 ms 45660 KB Output is correct
7 Correct 11 ms 45660 KB Output is correct
8 Correct 10 ms 45660 KB Output is correct
9 Correct 10 ms 45660 KB Output is correct
10 Correct 11 ms 45660 KB Output is correct
11 Correct 11 ms 45660 KB Output is correct
12 Correct 10 ms 45912 KB Output is correct
13 Correct 10 ms 45660 KB Output is correct
14 Correct 11 ms 45656 KB Output is correct
15 Correct 10 ms 45660 KB Output is correct
16 Correct 11 ms 45660 KB Output is correct
17 Correct 10 ms 45800 KB Output is correct
18 Correct 11 ms 45660 KB Output is correct
19 Correct 10 ms 45748 KB Output is correct
20 Correct 10 ms 45660 KB Output is correct
21 Correct 54 ms 50428 KB Output is correct
22 Correct 57 ms 50372 KB Output is correct
23 Correct 48 ms 50256 KB Output is correct
24 Correct 49 ms 50268 KB Output is correct
25 Correct 52 ms 50384 KB Output is correct
26 Correct 53 ms 50296 KB Output is correct
27 Correct 68 ms 48696 KB Output is correct
28 Correct 74 ms 48848 KB Output is correct
29 Correct 52 ms 50268 KB Output is correct
30 Correct 46 ms 50432 KB Output is correct
31 Correct 47 ms 50456 KB Output is correct
32 Correct 50 ms 50260 KB Output is correct
33 Correct 70 ms 50004 KB Output is correct
34 Correct 82 ms 50256 KB Output is correct
35 Correct 49 ms 50116 KB Output is correct
36 Correct 49 ms 50476 KB Output is correct
37 Correct 136 ms 50008 KB Output is correct
38 Correct 100 ms 49828 KB Output is correct
39 Correct 90 ms 48648 KB Output is correct
40 Correct 94 ms 48844 KB Output is correct
41 Correct 128 ms 50124 KB Output is correct
42 Correct 133 ms 50260 KB Output is correct
43 Correct 124 ms 50484 KB Output is correct
44 Correct 129 ms 50228 KB Output is correct
45 Correct 128 ms 50260 KB Output is correct
46 Correct 152 ms 50228 KB Output is correct
47 Correct 147 ms 49092 KB Output is correct
48 Correct 147 ms 49492 KB Output is correct
49 Correct 75 ms 49568 KB Output is correct
50 Correct 91 ms 50060 KB Output is correct
51 Correct 108 ms 50260 KB Output is correct
52 Correct 114 ms 50308 KB Output is correct
53 Correct 43 ms 49744 KB Output is correct
54 Correct 50 ms 50268 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 189 ms 51536 KB Output is correct
2 Correct 229 ms 51664 KB Output is correct
3 Correct 218 ms 51764 KB Output is correct
4 Correct 161 ms 50648 KB Output is correct
5 Correct 201 ms 51244 KB Output is correct
6 Correct 217 ms 52048 KB Output is correct
7 Correct 167 ms 49788 KB Output is correct
8 Correct 157 ms 49704 KB Output is correct
9 Correct 204 ms 50608 KB Output is correct
10 Correct 140 ms 50000 KB Output is correct
11 Correct 224 ms 51024 KB Output is correct
12 Correct 211 ms 51028 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 45660 KB Output is correct
2 Correct 11 ms 45660 KB Output is correct
3 Correct 12 ms 45792 KB Output is correct
4 Correct 10 ms 45660 KB Output is correct
5 Correct 10 ms 45656 KB Output is correct
6 Correct 10 ms 45660 KB Output is correct
7 Correct 11 ms 45660 KB Output is correct
8 Correct 10 ms 45660 KB Output is correct
9 Correct 10 ms 45660 KB Output is correct
10 Correct 11 ms 45660 KB Output is correct
11 Correct 11 ms 45660 KB Output is correct
12 Correct 10 ms 45912 KB Output is correct
13 Correct 10 ms 45660 KB Output is correct
14 Correct 11 ms 45656 KB Output is correct
15 Correct 10 ms 45660 KB Output is correct
16 Correct 11 ms 45660 KB Output is correct
17 Correct 10 ms 45800 KB Output is correct
18 Correct 11 ms 45660 KB Output is correct
19 Correct 10 ms 45748 KB Output is correct
20 Correct 10 ms 45660 KB Output is correct
21 Correct 11 ms 45656 KB Output is correct
22 Correct 12 ms 45660 KB Output is correct
23 Correct 11 ms 45656 KB Output is correct
24 Correct 10 ms 45660 KB Output is correct
25 Correct 11 ms 45660 KB Output is correct
26 Correct 10 ms 45660 KB Output is correct
27 Correct 11 ms 45660 KB Output is correct
28 Correct 10 ms 45660 KB Output is correct
29 Correct 10 ms 45660 KB Output is correct
30 Correct 11 ms 45660 KB Output is correct
31 Correct 11 ms 45660 KB Output is correct
32 Correct 11 ms 45660 KB Output is correct
33 Correct 10 ms 45656 KB Output is correct
34 Correct 11 ms 45660 KB Output is correct
35 Correct 11 ms 45796 KB Output is correct
36 Correct 11 ms 45660 KB Output is correct
37 Correct 9 ms 45660 KB Output is correct
38 Correct 10 ms 45896 KB Output is correct
39 Correct 54 ms 50428 KB Output is correct
40 Correct 57 ms 50372 KB Output is correct
41 Correct 48 ms 50256 KB Output is correct
42 Correct 49 ms 50268 KB Output is correct
43 Correct 52 ms 50384 KB Output is correct
44 Correct 53 ms 50296 KB Output is correct
45 Correct 68 ms 48696 KB Output is correct
46 Correct 74 ms 48848 KB Output is correct
47 Correct 52 ms 50268 KB Output is correct
48 Correct 46 ms 50432 KB Output is correct
49 Correct 47 ms 50456 KB Output is correct
50 Correct 50 ms 50260 KB Output is correct
51 Correct 70 ms 50004 KB Output is correct
52 Correct 82 ms 50256 KB Output is correct
53 Correct 49 ms 50116 KB Output is correct
54 Correct 49 ms 50476 KB Output is correct
55 Correct 136 ms 50008 KB Output is correct
56 Correct 100 ms 49828 KB Output is correct
57 Correct 90 ms 48648 KB Output is correct
58 Correct 94 ms 48844 KB Output is correct
59 Correct 128 ms 50124 KB Output is correct
60 Correct 133 ms 50260 KB Output is correct
61 Correct 124 ms 50484 KB Output is correct
62 Correct 129 ms 50228 KB Output is correct
63 Correct 128 ms 50260 KB Output is correct
64 Correct 152 ms 50228 KB Output is correct
65 Correct 147 ms 49092 KB Output is correct
66 Correct 147 ms 49492 KB Output is correct
67 Correct 75 ms 49568 KB Output is correct
68 Correct 91 ms 50060 KB Output is correct
69 Correct 108 ms 50260 KB Output is correct
70 Correct 114 ms 50308 KB Output is correct
71 Correct 43 ms 49744 KB Output is correct
72 Correct 50 ms 50268 KB Output is correct
73 Correct 189 ms 51536 KB Output is correct
74 Correct 229 ms 51664 KB Output is correct
75 Correct 218 ms 51764 KB Output is correct
76 Correct 161 ms 50648 KB Output is correct
77 Correct 201 ms 51244 KB Output is correct
78 Correct 217 ms 52048 KB Output is correct
79 Correct 167 ms 49788 KB Output is correct
80 Correct 157 ms 49704 KB Output is correct
81 Correct 204 ms 50608 KB Output is correct
82 Correct 140 ms 50000 KB Output is correct
83 Correct 224 ms 51024 KB Output is correct
84 Correct 211 ms 51028 KB Output is correct
85 Correct 143 ms 51268 KB Output is correct
86 Correct 159 ms 51796 KB Output is correct
87 Correct 115 ms 51388 KB Output is correct
88 Correct 132 ms 51952 KB Output is correct
89 Correct 88 ms 50488 KB Output is correct
90 Correct 135 ms 51840 KB Output is correct
91 Correct 103 ms 50948 KB Output is correct
92 Correct 99 ms 50772 KB Output is correct
93 Correct 131 ms 51788 KB Output is correct
94 Correct 138 ms 51824 KB Output is correct
95 Correct 131 ms 51696 KB Output is correct
96 Correct 133 ms 51828 KB Output is correct
97 Correct 131 ms 51804 KB Output is correct
98 Correct 123 ms 51140 KB Output is correct
99 Correct 143 ms 50608 KB Output is correct
100 Correct 123 ms 50640 KB Output is correct
101 Correct 148 ms 51116 KB Output is correct
102 Correct 107 ms 52524 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 45660 KB Output is correct
2 Correct 11 ms 45660 KB Output is correct
3 Correct 12 ms 45792 KB Output is correct
4 Correct 10 ms 45660 KB Output is correct
5 Correct 10 ms 45656 KB Output is correct
6 Correct 10 ms 45660 KB Output is correct
7 Correct 11 ms 45660 KB Output is correct
8 Correct 10 ms 45660 KB Output is correct
9 Correct 10 ms 45660 KB Output is correct
10 Correct 11 ms 45660 KB Output is correct
11 Correct 11 ms 45660 KB Output is correct
12 Correct 10 ms 45912 KB Output is correct
13 Correct 10 ms 45660 KB Output is correct
14 Correct 11 ms 45656 KB Output is correct
15 Correct 10 ms 45660 KB Output is correct
16 Correct 11 ms 45660 KB Output is correct
17 Correct 10 ms 45800 KB Output is correct
18 Correct 11 ms 45660 KB Output is correct
19 Correct 10 ms 45748 KB Output is correct
20 Correct 10 ms 45660 KB Output is correct
21 Correct 11 ms 45656 KB Output is correct
22 Correct 12 ms 45660 KB Output is correct
23 Correct 11 ms 45656 KB Output is correct
24 Correct 10 ms 45660 KB Output is correct
25 Correct 11 ms 45660 KB Output is correct
26 Correct 10 ms 45660 KB Output is correct
27 Correct 11 ms 45660 KB Output is correct
28 Correct 10 ms 45660 KB Output is correct
29 Correct 10 ms 45660 KB Output is correct
30 Correct 11 ms 45660 KB Output is correct
31 Correct 11 ms 45660 KB Output is correct
32 Correct 11 ms 45660 KB Output is correct
33 Correct 10 ms 45656 KB Output is correct
34 Correct 11 ms 45660 KB Output is correct
35 Correct 11 ms 45796 KB Output is correct
36 Correct 11 ms 45660 KB Output is correct
37 Correct 9 ms 45660 KB Output is correct
38 Correct 10 ms 45896 KB Output is correct
39 Correct 54 ms 50428 KB Output is correct
40 Correct 57 ms 50372 KB Output is correct
41 Correct 48 ms 50256 KB Output is correct
42 Correct 49 ms 50268 KB Output is correct
43 Correct 52 ms 50384 KB Output is correct
44 Correct 53 ms 50296 KB Output is correct
45 Correct 68 ms 48696 KB Output is correct
46 Correct 74 ms 48848 KB Output is correct
47 Correct 52 ms 50268 KB Output is correct
48 Correct 46 ms 50432 KB Output is correct
49 Correct 47 ms 50456 KB Output is correct
50 Correct 50 ms 50260 KB Output is correct
51 Correct 70 ms 50004 KB Output is correct
52 Correct 82 ms 50256 KB Output is correct
53 Correct 49 ms 50116 KB Output is correct
54 Correct 49 ms 50476 KB Output is correct
55 Correct 681 ms 68460 KB Output is correct
56 Correct 510 ms 65348 KB Output is correct
57 Correct 768 ms 69996 KB Output is correct
58 Correct 453 ms 63828 KB Output is correct
59 Correct 448 ms 65540 KB Output is correct
60 Correct 638 ms 70200 KB Output is correct
61 Correct 527 ms 62832 KB Output is correct
62 Correct 537 ms 62904 KB Output is correct
63 Execution timed out 1016 ms 69312 KB Time limit exceeded
64 Halted 0 ms 0 KB -