#include <bits/stdc++.h>
#pragma optimize("Ofast")
#pragma target("avx2")
#pragma optimize("unroll-loops")
using namespace std;
#define ll long long
#define ld long double
#define pb push_back
#define pf push_front
#define pii pair<int,int>
#define all(v) v.begin(),v.end()
#define F first
#define S second
#define mem(a,i) memset(a,i,sizeof(a))
#define sz(s) (int)s.size()
#define y1 yy
#define ppb pop_back
#define lb lower_bound
#define ub upper_bound
#define gcd(a,b) __gcd(a,b)
#define in insert
#define int ll
#define ull unsigned ll
const int MAX=3e5+10;
const int B=331;
const int maxB=1000;
const int N=104;
const int block=450;
const int inf=1e9;
const int mod=1e9+7;
const int mod1=1e9+9;
const ld eps=1e-9;
int dx[8]={1,0,-1,0,1,-1,-1,1};
int dy[8]={0,1,0,-1,1,-1,1,-1};
int binpow(int a,int n){
if(!n)return 1;
if(n%2==1)return a*binpow(a,n-1)%mod;
int k=binpow(a,n/2);
return k*k%mod;
}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
struct segtree{
int t[3][4*MAX],op[3][4*MAX];
void init(){
mem(t,0);
mem(op,0);
}
void upd(int v,int o,int x){
if(op[2][v]==o){
t[2][v]+=x;
return;
}
if(op[2][v]==1){
if(t[2][v]>=x){
t[2][v]-=x;
}
else{
op[2][v]=(op[2][v]^1);
t[2][v]=x-t[2][v];
}
return;
}
if(op[1][v]==op[2][v]){
t[1][v]+=t[2][v];
}
else{
if(t[1][v]>=t[2][v]){
t[1][v]-=t[2][v];
}
else{
op[1][v]=(op[1][v]^1);
t[1][v]=t[2][v]-t[1][v];
}
}
t[2][v]=x;
op[2][v]=o;
}
void push(int v){
for(int i=1;i<=2;i++){
upd(2*v,op[i][v],t[i][v]);
upd(2*v+1,op[i][v],t[i][v]);
op[i][v]=t[i][v]=0;
}
}
void update(int v,int tl,int tr,int l,int r,int o,int x){
if(l>r||tl>r||l>tr)return;
if(l<=tl&&tr<=r){
upd(v,o,x);
return;
}
push(v);
int tm=(tl+tr)/2;
update(2*v,tl,tm,l,r,o,x);
update(2*v+1,tm+1,tr,l,r,o,x);
}
int get(int v,int tl,int tr,int pos){
if(tl==tr){
int ans=0;
for(int i=1;i<=2;i++){
if(op[i][v]==0)ans-=t[i][v];
else ans+=t[i][v];
ans=max(ans,0ll);
}
return ans;
}
push(v);
int tm=(tl+tr)/2;
if(pos<=tm)return get(2*v,tl,tm,pos);
else return get(2*v+1,tm+1,tr,pos);
}
}t;
int n,m,q;
int del[MAX];
int type[MAX];
int l[MAX],r[MAX],c[MAX],x[MAX];
vector<pii> zap[MAX];
int ans[MAX];
struct segtree1{
pii t[4*MAX];
int add[4*MAX];
void build(int v,int tl,int tr){
if(tl==tr){
t[v].S=tl;
return;
}
int tm=(tl+tr)/2;
build(2*v,tl,tm);
build(2*v+1,tm+1,tr);
t[v]=max(t[2*v],t[2*v+1]);
}
void init(){
mem(t,0);
mem(add,0);
build(1,1,n);
}
void push(int v){
add[2*v]+=add[v];
add[2*v+1]+=add[v];
t[2*v].F+=add[v];
t[2*v+1].F+=add[v];
add[v]=0;
}
pii get(int v,int tl,int tr,int l,int r){
if(l>r||tl>r||l>tr)return {-inf,-inf};
if(l<=tl&&tr<=r)return t[v];
push(v);
int tm=(tl+tr)/2;
return max(get(2*v,tl,tm,l,r),get(2*v+1,tm+1,tr,l,r));
}
void update(int v,int tl,int tr,int l,int r,int x){
if(l>r||tl>r||l>tr)return;
if(l<=tl&&tr<=r){
t[v].F+=x;
add[v]+=x;
return;
}
push(v);
int tm=(tl+tr)/2;
update(2*v,tl,tm,l,r,x);
update(2*v+1,tm+1,tr,l,r,x);
t[v]=max(t[2*v],t[2*v+1]);
}
}t1;
void solve(){
cin>>n>>m>>q;
mem(ans,-1);
t.init();
t1.init();
for(int i=1;i<=q;i++){
cin>>type[i];
if(type[i]==1){
cin>>l[i]>>r[i]>>c[i]>>x[i];
t1.update(1,1,n,l[i],r[i],x[i]);
t.update(1,1,n,l[i],r[i],1,x[i]);
}
else if(type[i]==2){
cin>>l[i]>>r[i]>>x[i];
t.update(1,1,n,l[i],r[i],0,x[i]);
}
else{
cin>>l[i]>>r[i];
// cout<<i<<" "<<l[i]<<" "<<r[i]<<" "<<t1.get(1,1,n,l[i],l[i]).F<<" "<<t.get(1,1,n,l[i])<<"\n";
r[i]+=t1.get(1,1,n,l[i],l[i]).F-t.get(1,1,n,l[i]);
zap[l[i]].pb({r[i],i});
// cout<<l[i]<<" "<<r[i]<<"\n";
}
}
t1.init();
for(int i=1;i<=n;i++){
sort(all(zap[i]));
reverse(all(zap[i]));
// cout<<i<<"\n";
// for(auto x:zap[i]){
// cout<<x.F<<" "<<x.S<<"\n";
// }
if(!zap[i].empty())t1.update(1,1,n,i,i,-zap[i].back().F);
else t1.update(1,1,n,i,i,-inf);
}
// for(int i=1;i<=n;i++){
// cout<<t1.get(1,1,n,i,i).F<<" ";
// }
// cout<<"\n";
for(int i=1;i<=q;i++){
if(type[i]==1){
t1.update(1,1,n,l[i],r[i],x[i]);
}
while(t1.get(1,1,n,1,n).F>=0){
int pos=t1.get(1,1,n,1,n).S;
// cout<<pos<<" "<<i<<" "<<zap[pos].back().S<<" "<<t1.get(1,1,n,1,n).F<<"\n";
if(zap[pos].back().S>i)ans[zap[pos].back().S]=c[i];
else ans[zap[pos].back().S]=0;
if(sz(zap[pos])>1){
t1.update(1,1,n,pos,pos,zap[pos].back().F-zap[pos][sz(zap[pos])-2].F);
}
else{
t1.update(1,1,n,pos,pos,-inf);
}
zap[pos].ppb();
}
}
for(int i=1;i<=n;i++){
while(!zap[i].empty()){
ans[zap[i].back().S]=0;
zap[i].ppb();
}
}
for(int i=1;i<=q;i++){
if(ans[i]!=-1)cout<<ans[i]<<"\n";
}
}
signed main(){
// freopen("triangles.in","r",stdin);
// freopen("triangles.out","w",stdout);
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
// prec();
int t=1;
// cin>>t;
while(t--)solve();
}
Compilation message
foodcourt.cpp:3: warning: ignoring '#pragma optimize ' [-Wunknown-pragmas]
3 | #pragma optimize("Ofast")
|
foodcourt.cpp:4: warning: ignoring '#pragma target ' [-Wunknown-pragmas]
4 | #pragma target("avx2")
|
foodcourt.cpp:5: warning: ignoring '#pragma optimize ' [-Wunknown-pragmas]
5 | #pragma optimize("unroll-loops")
|
foodcourt.cpp: In member function 'void segtree1::init()':
foodcourt.cpp:17:38: warning: 'void* memset(void*, int, size_t)' clearing an object of type 'struct std::pair<long long int, long long int>' with no trivial copy-assignment; use assignment instead [-Wclass-memaccess]
17 | #define mem(a,i) memset(a,i,sizeof(a))
| ^
foodcourt.cpp:149:5: note: in expansion of macro 'mem'
149 | mem(t,0);
| ^~~
In file included from /usr/include/c++/10/bits/stl_algobase.h:64,
from /usr/include/c++/10/bits/specfun.h:45,
from /usr/include/c++/10/cmath:1927,
from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:41,
from foodcourt.cpp:1:
/usr/include/c++/10/bits/stl_pair.h:211:12: note: 'struct std::pair<long long int, long long int>' declared here
211 | struct pair
| ^~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
45 ms |
98132 KB |
Output is correct |
2 |
Correct |
21 ms |
98236 KB |
Output is correct |
3 |
Correct |
19 ms |
98140 KB |
Output is correct |
4 |
Correct |
20 ms |
98184 KB |
Output is correct |
5 |
Correct |
18 ms |
98140 KB |
Output is correct |
6 |
Correct |
18 ms |
100188 KB |
Output is correct |
7 |
Correct |
20 ms |
100188 KB |
Output is correct |
8 |
Correct |
21 ms |
98356 KB |
Output is correct |
9 |
Correct |
21 ms |
98140 KB |
Output is correct |
10 |
Correct |
20 ms |
98140 KB |
Output is correct |
11 |
Correct |
20 ms |
100184 KB |
Output is correct |
12 |
Correct |
21 ms |
100292 KB |
Output is correct |
13 |
Correct |
19 ms |
98260 KB |
Output is correct |
14 |
Correct |
19 ms |
100284 KB |
Output is correct |
15 |
Correct |
20 ms |
98140 KB |
Output is correct |
16 |
Correct |
19 ms |
98168 KB |
Output is correct |
17 |
Correct |
20 ms |
98140 KB |
Output is correct |
18 |
Correct |
20 ms |
98140 KB |
Output is correct |
19 |
Correct |
20 ms |
100188 KB |
Output is correct |
20 |
Correct |
20 ms |
98140 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
45 ms |
98132 KB |
Output is correct |
2 |
Correct |
21 ms |
98236 KB |
Output is correct |
3 |
Correct |
19 ms |
98140 KB |
Output is correct |
4 |
Correct |
20 ms |
98184 KB |
Output is correct |
5 |
Correct |
18 ms |
98140 KB |
Output is correct |
6 |
Correct |
18 ms |
100188 KB |
Output is correct |
7 |
Correct |
20 ms |
100188 KB |
Output is correct |
8 |
Correct |
21 ms |
98356 KB |
Output is correct |
9 |
Correct |
21 ms |
98140 KB |
Output is correct |
10 |
Correct |
20 ms |
98140 KB |
Output is correct |
11 |
Correct |
20 ms |
100184 KB |
Output is correct |
12 |
Correct |
21 ms |
100292 KB |
Output is correct |
13 |
Correct |
19 ms |
98260 KB |
Output is correct |
14 |
Correct |
19 ms |
100284 KB |
Output is correct |
15 |
Correct |
20 ms |
98140 KB |
Output is correct |
16 |
Correct |
19 ms |
98168 KB |
Output is correct |
17 |
Correct |
20 ms |
98140 KB |
Output is correct |
18 |
Correct |
20 ms |
98140 KB |
Output is correct |
19 |
Correct |
20 ms |
100188 KB |
Output is correct |
20 |
Correct |
20 ms |
98140 KB |
Output is correct |
21 |
Runtime error |
103 ms |
203092 KB |
Execution killed with signal 11 |
22 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
91 ms |
104784 KB |
Output is correct |
2 |
Correct |
112 ms |
104532 KB |
Output is correct |
3 |
Correct |
96 ms |
104788 KB |
Output is correct |
4 |
Correct |
93 ms |
104792 KB |
Output is correct |
5 |
Correct |
101 ms |
104528 KB |
Output is correct |
6 |
Correct |
120 ms |
104532 KB |
Output is correct |
7 |
Correct |
35 ms |
103892 KB |
Output is correct |
8 |
Correct |
40 ms |
103968 KB |
Output is correct |
9 |
Correct |
112 ms |
104440 KB |
Output is correct |
10 |
Correct |
90 ms |
104532 KB |
Output is correct |
11 |
Correct |
91 ms |
104612 KB |
Output is correct |
12 |
Correct |
90 ms |
104536 KB |
Output is correct |
13 |
Correct |
90 ms |
104276 KB |
Output is correct |
14 |
Correct |
98 ms |
104640 KB |
Output is correct |
15 |
Correct |
105 ms |
105848 KB |
Output is correct |
16 |
Correct |
119 ms |
104316 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
606 ms |
222736 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
45 ms |
98132 KB |
Output is correct |
2 |
Correct |
21 ms |
98236 KB |
Output is correct |
3 |
Correct |
19 ms |
98140 KB |
Output is correct |
4 |
Correct |
20 ms |
98184 KB |
Output is correct |
5 |
Correct |
18 ms |
98140 KB |
Output is correct |
6 |
Correct |
18 ms |
100188 KB |
Output is correct |
7 |
Correct |
20 ms |
100188 KB |
Output is correct |
8 |
Correct |
21 ms |
98356 KB |
Output is correct |
9 |
Correct |
21 ms |
98140 KB |
Output is correct |
10 |
Correct |
20 ms |
98140 KB |
Output is correct |
11 |
Correct |
20 ms |
100184 KB |
Output is correct |
12 |
Correct |
21 ms |
100292 KB |
Output is correct |
13 |
Correct |
19 ms |
98260 KB |
Output is correct |
14 |
Correct |
19 ms |
100284 KB |
Output is correct |
15 |
Correct |
20 ms |
98140 KB |
Output is correct |
16 |
Correct |
19 ms |
98168 KB |
Output is correct |
17 |
Correct |
20 ms |
98140 KB |
Output is correct |
18 |
Correct |
20 ms |
98140 KB |
Output is correct |
19 |
Correct |
20 ms |
100188 KB |
Output is correct |
20 |
Correct |
20 ms |
98140 KB |
Output is correct |
21 |
Correct |
91 ms |
104784 KB |
Output is correct |
22 |
Correct |
112 ms |
104532 KB |
Output is correct |
23 |
Correct |
96 ms |
104788 KB |
Output is correct |
24 |
Correct |
93 ms |
104792 KB |
Output is correct |
25 |
Correct |
101 ms |
104528 KB |
Output is correct |
26 |
Correct |
120 ms |
104532 KB |
Output is correct |
27 |
Correct |
35 ms |
103892 KB |
Output is correct |
28 |
Correct |
40 ms |
103968 KB |
Output is correct |
29 |
Correct |
112 ms |
104440 KB |
Output is correct |
30 |
Correct |
90 ms |
104532 KB |
Output is correct |
31 |
Correct |
91 ms |
104612 KB |
Output is correct |
32 |
Correct |
90 ms |
104536 KB |
Output is correct |
33 |
Correct |
90 ms |
104276 KB |
Output is correct |
34 |
Correct |
98 ms |
104640 KB |
Output is correct |
35 |
Correct |
105 ms |
105848 KB |
Output is correct |
36 |
Correct |
119 ms |
104316 KB |
Output is correct |
37 |
Correct |
116 ms |
104296 KB |
Output is correct |
38 |
Correct |
112 ms |
103840 KB |
Output is correct |
39 |
Correct |
30 ms |
103836 KB |
Output is correct |
40 |
Correct |
34 ms |
103840 KB |
Output is correct |
41 |
Correct |
117 ms |
104528 KB |
Output is correct |
42 |
Correct |
119 ms |
104360 KB |
Output is correct |
43 |
Correct |
124 ms |
104528 KB |
Output is correct |
44 |
Correct |
124 ms |
104460 KB |
Output is correct |
45 |
Correct |
141 ms |
104528 KB |
Output is correct |
46 |
Correct |
146 ms |
104412 KB |
Output is correct |
47 |
Correct |
70 ms |
104532 KB |
Output is correct |
48 |
Correct |
114 ms |
104500 KB |
Output is correct |
49 |
Correct |
105 ms |
103760 KB |
Output is correct |
50 |
Correct |
114 ms |
104056 KB |
Output is correct |
51 |
Correct |
129 ms |
104400 KB |
Output is correct |
52 |
Correct |
134 ms |
104440 KB |
Output is correct |
53 |
Correct |
90 ms |
103792 KB |
Output is correct |
54 |
Correct |
106 ms |
104528 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
193 ms |
211180 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
45 ms |
98132 KB |
Output is correct |
2 |
Correct |
21 ms |
98236 KB |
Output is correct |
3 |
Correct |
19 ms |
98140 KB |
Output is correct |
4 |
Correct |
20 ms |
98184 KB |
Output is correct |
5 |
Correct |
18 ms |
98140 KB |
Output is correct |
6 |
Correct |
18 ms |
100188 KB |
Output is correct |
7 |
Correct |
20 ms |
100188 KB |
Output is correct |
8 |
Correct |
21 ms |
98356 KB |
Output is correct |
9 |
Correct |
21 ms |
98140 KB |
Output is correct |
10 |
Correct |
20 ms |
98140 KB |
Output is correct |
11 |
Correct |
20 ms |
100184 KB |
Output is correct |
12 |
Correct |
21 ms |
100292 KB |
Output is correct |
13 |
Correct |
19 ms |
98260 KB |
Output is correct |
14 |
Correct |
19 ms |
100284 KB |
Output is correct |
15 |
Correct |
20 ms |
98140 KB |
Output is correct |
16 |
Correct |
19 ms |
98168 KB |
Output is correct |
17 |
Correct |
20 ms |
98140 KB |
Output is correct |
18 |
Correct |
20 ms |
98140 KB |
Output is correct |
19 |
Correct |
20 ms |
100188 KB |
Output is correct |
20 |
Correct |
20 ms |
98140 KB |
Output is correct |
21 |
Runtime error |
103 ms |
203092 KB |
Execution killed with signal 11 |
22 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
45 ms |
98132 KB |
Output is correct |
2 |
Correct |
21 ms |
98236 KB |
Output is correct |
3 |
Correct |
19 ms |
98140 KB |
Output is correct |
4 |
Correct |
20 ms |
98184 KB |
Output is correct |
5 |
Correct |
18 ms |
98140 KB |
Output is correct |
6 |
Correct |
18 ms |
100188 KB |
Output is correct |
7 |
Correct |
20 ms |
100188 KB |
Output is correct |
8 |
Correct |
21 ms |
98356 KB |
Output is correct |
9 |
Correct |
21 ms |
98140 KB |
Output is correct |
10 |
Correct |
20 ms |
98140 KB |
Output is correct |
11 |
Correct |
20 ms |
100184 KB |
Output is correct |
12 |
Correct |
21 ms |
100292 KB |
Output is correct |
13 |
Correct |
19 ms |
98260 KB |
Output is correct |
14 |
Correct |
19 ms |
100284 KB |
Output is correct |
15 |
Correct |
20 ms |
98140 KB |
Output is correct |
16 |
Correct |
19 ms |
98168 KB |
Output is correct |
17 |
Correct |
20 ms |
98140 KB |
Output is correct |
18 |
Correct |
20 ms |
98140 KB |
Output is correct |
19 |
Correct |
20 ms |
100188 KB |
Output is correct |
20 |
Correct |
20 ms |
98140 KB |
Output is correct |
21 |
Runtime error |
103 ms |
203092 KB |
Execution killed with signal 11 |
22 |
Halted |
0 ms |
0 KB |
- |