#include<bits/stdc++.h>
using namespace std;
const int maxn=250000+10;
int n,m,q,res[maxn],kaf=(1<<19);
struct que{
int 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(int i){
int 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(int i){
int 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(int i,int l,int r,int tl,int tr){
if(l>r||l>tr||r<tl||tl>tr){
return fakenode;
}
if(l>=tl&&r<=tr){
return seg[i];
}
int m=(l+r)>>1;
return merge(pors((i<<1),l,m,tl,tr),pors((i<<1)^1,m+1,r,tl,tr));
}
}seg;
vector<int>ins[maxn],del[maxn],por[maxn];
void vorod(){
cin>>n>>m>>q;
for(int 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(int 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(int 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 ;
}
int 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(int 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(int 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(int)':
foodcourt.cpp:38:7: warning: unused variable 'fu' [-Wunused-variable]
38 | int fu=i;
| ^~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
11 ms |
45660 KB |
Output is correct |
2 |
Correct |
12 ms |
45660 KB |
Output is correct |
3 |
Correct |
11 ms |
45660 KB |
Output is correct |
4 |
Correct |
11 ms |
45660 KB |
Output is correct |
5 |
Correct |
10 ms |
45660 KB |
Output is correct |
6 |
Correct |
10 ms |
45660 KB |
Output is correct |
7 |
Correct |
10 ms |
45660 KB |
Output is correct |
8 |
Correct |
12 ms |
45808 KB |
Output is correct |
9 |
Correct |
13 ms |
45784 KB |
Output is correct |
10 |
Correct |
11 ms |
45660 KB |
Output is correct |
11 |
Correct |
12 ms |
45888 KB |
Output is correct |
12 |
Correct |
13 ms |
45656 KB |
Output is correct |
13 |
Correct |
11 ms |
45656 KB |
Output is correct |
14 |
Correct |
11 ms |
45660 KB |
Output is correct |
15 |
Correct |
10 ms |
45660 KB |
Output is correct |
16 |
Correct |
11 ms |
45796 KB |
Output is correct |
17 |
Correct |
11 ms |
45660 KB |
Output is correct |
18 |
Correct |
10 ms |
45660 KB |
Output is correct |
19 |
Correct |
10 ms |
45660 KB |
Output is correct |
20 |
Correct |
13 ms |
45660 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
11 ms |
45660 KB |
Output is correct |
2 |
Correct |
12 ms |
45660 KB |
Output is correct |
3 |
Correct |
11 ms |
45660 KB |
Output is correct |
4 |
Correct |
11 ms |
45660 KB |
Output is correct |
5 |
Correct |
10 ms |
45660 KB |
Output is correct |
6 |
Correct |
10 ms |
45660 KB |
Output is correct |
7 |
Correct |
10 ms |
45660 KB |
Output is correct |
8 |
Correct |
12 ms |
45808 KB |
Output is correct |
9 |
Correct |
13 ms |
45784 KB |
Output is correct |
10 |
Correct |
11 ms |
45660 KB |
Output is correct |
11 |
Correct |
12 ms |
45888 KB |
Output is correct |
12 |
Correct |
13 ms |
45656 KB |
Output is correct |
13 |
Correct |
11 ms |
45656 KB |
Output is correct |
14 |
Correct |
11 ms |
45660 KB |
Output is correct |
15 |
Correct |
10 ms |
45660 KB |
Output is correct |
16 |
Correct |
11 ms |
45796 KB |
Output is correct |
17 |
Correct |
11 ms |
45660 KB |
Output is correct |
18 |
Correct |
10 ms |
45660 KB |
Output is correct |
19 |
Correct |
10 ms |
45660 KB |
Output is correct |
20 |
Correct |
13 ms |
45660 KB |
Output is correct |
21 |
Incorrect |
9 ms |
45816 KB |
Output isn't correct |
22 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
57 ms |
51544 KB |
Output is correct |
2 |
Correct |
50 ms |
51648 KB |
Output is correct |
3 |
Correct |
46 ms |
51536 KB |
Output is correct |
4 |
Correct |
48 ms |
51540 KB |
Output is correct |
5 |
Correct |
47 ms |
51668 KB |
Output is correct |
6 |
Correct |
48 ms |
51536 KB |
Output is correct |
7 |
Correct |
66 ms |
49108 KB |
Output is correct |
8 |
Correct |
73 ms |
49112 KB |
Output is correct |
9 |
Correct |
53 ms |
51548 KB |
Output is correct |
10 |
Correct |
46 ms |
51540 KB |
Output is correct |
11 |
Correct |
50 ms |
51516 KB |
Output is correct |
12 |
Correct |
46 ms |
51544 KB |
Output is correct |
13 |
Correct |
73 ms |
50776 KB |
Output is correct |
14 |
Correct |
80 ms |
51280 KB |
Output is correct |
15 |
Correct |
47 ms |
51284 KB |
Output is correct |
16 |
Correct |
49 ms |
51536 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
14 ms |
44756 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
11 ms |
45660 KB |
Output is correct |
2 |
Correct |
12 ms |
45660 KB |
Output is correct |
3 |
Correct |
11 ms |
45660 KB |
Output is correct |
4 |
Correct |
11 ms |
45660 KB |
Output is correct |
5 |
Correct |
10 ms |
45660 KB |
Output is correct |
6 |
Correct |
10 ms |
45660 KB |
Output is correct |
7 |
Correct |
10 ms |
45660 KB |
Output is correct |
8 |
Correct |
12 ms |
45808 KB |
Output is correct |
9 |
Correct |
13 ms |
45784 KB |
Output is correct |
10 |
Correct |
11 ms |
45660 KB |
Output is correct |
11 |
Correct |
12 ms |
45888 KB |
Output is correct |
12 |
Correct |
13 ms |
45656 KB |
Output is correct |
13 |
Correct |
11 ms |
45656 KB |
Output is correct |
14 |
Correct |
11 ms |
45660 KB |
Output is correct |
15 |
Correct |
10 ms |
45660 KB |
Output is correct |
16 |
Correct |
11 ms |
45796 KB |
Output is correct |
17 |
Correct |
11 ms |
45660 KB |
Output is correct |
18 |
Correct |
10 ms |
45660 KB |
Output is correct |
19 |
Correct |
10 ms |
45660 KB |
Output is correct |
20 |
Correct |
13 ms |
45660 KB |
Output is correct |
21 |
Correct |
57 ms |
51544 KB |
Output is correct |
22 |
Correct |
50 ms |
51648 KB |
Output is correct |
23 |
Correct |
46 ms |
51536 KB |
Output is correct |
24 |
Correct |
48 ms |
51540 KB |
Output is correct |
25 |
Correct |
47 ms |
51668 KB |
Output is correct |
26 |
Correct |
48 ms |
51536 KB |
Output is correct |
27 |
Correct |
66 ms |
49108 KB |
Output is correct |
28 |
Correct |
73 ms |
49112 KB |
Output is correct |
29 |
Correct |
53 ms |
51548 KB |
Output is correct |
30 |
Correct |
46 ms |
51540 KB |
Output is correct |
31 |
Correct |
50 ms |
51516 KB |
Output is correct |
32 |
Correct |
46 ms |
51544 KB |
Output is correct |
33 |
Correct |
73 ms |
50776 KB |
Output is correct |
34 |
Correct |
80 ms |
51280 KB |
Output is correct |
35 |
Correct |
47 ms |
51284 KB |
Output is correct |
36 |
Correct |
49 ms |
51536 KB |
Output is correct |
37 |
Correct |
132 ms |
50772 KB |
Output is correct |
38 |
Correct |
99 ms |
48564 KB |
Output is correct |
39 |
Correct |
81 ms |
48888 KB |
Output is correct |
40 |
Correct |
93 ms |
49108 KB |
Output is correct |
41 |
Correct |
127 ms |
51024 KB |
Output is correct |
42 |
Correct |
127 ms |
51024 KB |
Output is correct |
43 |
Correct |
121 ms |
51120 KB |
Output is correct |
44 |
Correct |
124 ms |
51144 KB |
Output is correct |
45 |
Correct |
129 ms |
51140 KB |
Output is correct |
46 |
Correct |
125 ms |
51024 KB |
Output is correct |
47 |
Correct |
134 ms |
49740 KB |
Output is correct |
48 |
Correct |
144 ms |
50004 KB |
Output is correct |
49 |
Correct |
74 ms |
48148 KB |
Output is correct |
50 |
Correct |
92 ms |
50780 KB |
Output is correct |
51 |
Correct |
107 ms |
51284 KB |
Output is correct |
52 |
Correct |
112 ms |
51240 KB |
Output is correct |
53 |
Correct |
39 ms |
48720 KB |
Output is correct |
54 |
Correct |
50 ms |
51884 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
11 ms |
46044 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
11 ms |
45660 KB |
Output is correct |
2 |
Correct |
12 ms |
45660 KB |
Output is correct |
3 |
Correct |
11 ms |
45660 KB |
Output is correct |
4 |
Correct |
11 ms |
45660 KB |
Output is correct |
5 |
Correct |
10 ms |
45660 KB |
Output is correct |
6 |
Correct |
10 ms |
45660 KB |
Output is correct |
7 |
Correct |
10 ms |
45660 KB |
Output is correct |
8 |
Correct |
12 ms |
45808 KB |
Output is correct |
9 |
Correct |
13 ms |
45784 KB |
Output is correct |
10 |
Correct |
11 ms |
45660 KB |
Output is correct |
11 |
Correct |
12 ms |
45888 KB |
Output is correct |
12 |
Correct |
13 ms |
45656 KB |
Output is correct |
13 |
Correct |
11 ms |
45656 KB |
Output is correct |
14 |
Correct |
11 ms |
45660 KB |
Output is correct |
15 |
Correct |
10 ms |
45660 KB |
Output is correct |
16 |
Correct |
11 ms |
45796 KB |
Output is correct |
17 |
Correct |
11 ms |
45660 KB |
Output is correct |
18 |
Correct |
10 ms |
45660 KB |
Output is correct |
19 |
Correct |
10 ms |
45660 KB |
Output is correct |
20 |
Correct |
13 ms |
45660 KB |
Output is correct |
21 |
Incorrect |
9 ms |
45816 KB |
Output isn't correct |
22 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
11 ms |
45660 KB |
Output is correct |
2 |
Correct |
12 ms |
45660 KB |
Output is correct |
3 |
Correct |
11 ms |
45660 KB |
Output is correct |
4 |
Correct |
11 ms |
45660 KB |
Output is correct |
5 |
Correct |
10 ms |
45660 KB |
Output is correct |
6 |
Correct |
10 ms |
45660 KB |
Output is correct |
7 |
Correct |
10 ms |
45660 KB |
Output is correct |
8 |
Correct |
12 ms |
45808 KB |
Output is correct |
9 |
Correct |
13 ms |
45784 KB |
Output is correct |
10 |
Correct |
11 ms |
45660 KB |
Output is correct |
11 |
Correct |
12 ms |
45888 KB |
Output is correct |
12 |
Correct |
13 ms |
45656 KB |
Output is correct |
13 |
Correct |
11 ms |
45656 KB |
Output is correct |
14 |
Correct |
11 ms |
45660 KB |
Output is correct |
15 |
Correct |
10 ms |
45660 KB |
Output is correct |
16 |
Correct |
11 ms |
45796 KB |
Output is correct |
17 |
Correct |
11 ms |
45660 KB |
Output is correct |
18 |
Correct |
10 ms |
45660 KB |
Output is correct |
19 |
Correct |
10 ms |
45660 KB |
Output is correct |
20 |
Correct |
13 ms |
45660 KB |
Output is correct |
21 |
Incorrect |
9 ms |
45816 KB |
Output isn't correct |
22 |
Halted |
0 ms |
0 KB |
- |