#include <bits/stdc++.h>
#pragma optimize("Ofast")
#pragma target("avx2")
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
const int MAX=1e5+15;
const int B=300;
const int N=104;
const int block=400;
const int maxB=MAX/B+10;
const ll inf=1e18;
const int mod=998244353;
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;
}
int n,m,q;
struct node{
int t,l,r;
node(){
t=0,l=0,r=0;
}
node(int tl,int tr,int s){
t=s;
l=tl;
r=tr;
}
};
struct segtree{
vector<pii> roots;
node t[20*MAX];
int cur;
void build(int v,int tl,int tr){
if(tl==tr){
return;
}
int tm=(tl+tr)/2;
t[v].l=++cur;
t[v].r=++cur;
build(t[v].l,tl,tm);
build(t[v].r,tm+1,tr);
}
void update(int v,int tl,int tr,int pos,int x){
if(tl==tr){
t[v].t+=x;
// cout<<v<<" "<<tl<<" "<<tr<<" "<<t[v].t<<"\n";
return;
}
int tm=(tl+tr)/2;
if(pos<=tm){
cur++;
t[cur]=node(t[t[v].l].l,t[t[v].l].r,t[t[v].l].t);
t[v].l=cur;
update(t[v].l,tl,tm,pos,x);
}
else{
cur++;
// cout<<v<<" "<<cur<<" "<<t[v].r<<"\n";
t[cur]=node(t[t[v].r].l,t[t[v].r].r,t[t[v].r].t);
t[v].r=cur;
update(t[v].r,tm+1,tr,pos,x);
}
// cout<<v<<" "<<tl<<" "<<tr<<" "<<t[v].t<<" "<<t[v].l<<" "<<t[v].r<<"\n";
t[v].t=t[t[v].l].t+t[t[v].r].t;
// cout<<v<<" "<<tl<<" "<<tr<<" "<<t[v].t<<" "<<t[v].l<<" "<<t[v].r<<"\n";
}
int get(int v,int tl,int tr,int l,int r){
if(l>r||tl>r||l>tr)return 0;
if(l<=tl&&tr<=r){
return t[v].t;
}
int tm=(tl+tr)/2;
return get(t[v].l,tl,tm,l,r)+get(t[v].r,tm+1,tr,l,r);
}
}t;
int z[MAX];
int f[MAX];
void solve(){
cin>>n>>m>>q;
t.roots.pb({1,0});
t.cur=1;
t.build(1,1,n);
for(int i=1;i<=q;i++){
// cout<<"!!! "<<i<<"\n";
// for(int i=1;i<=n;i++){
// cout<<t.get(t.roots.back().F,1,n,i,i)<<" ";
// }
// cout<<"\n";
int type;
cin>>type;
if(type==1){
int l,r,x;
cin>>l>>r>>z[i]>>x;
int nroot=++t.cur;
int lroot=t.roots.back().F;
t.t[nroot]=node(t.t[lroot].l,t.t[lroot].r,t.t[lroot].t);
// cout<<x<<"\n";
t.update(nroot,1,n,l,x);
if(r+1<=n)t.update(nroot,1,n,r+1,-x);
t.roots.pb({nroot,i});
}
else if(type==2){
int l,r,x;
cin>>l>>r>>x;
for(int i=l;i<=r;i++){
f[i]=min(f[i]+x,t.get(t.roots.back().F,1,n,1,i));
}
}
else{
int v,pos;
cin>>v>>pos;
pos+=f[v];
int l=0,r=sz(t.roots)-1,res=sz(t.roots)-1;
// cout<<f[v]<<" "<<t.get(t.roots.back().F,1,n,1,v)<<" "<<pos<<"\n";
if(t.get(t.roots.back().F,1,n,1,v)<pos){
cout<<0<<"\n";
continue;
}
while(l<=r){
int m=(l+r)/2;
if(t.get(t.roots[m].F,1,n,1,v)<pos){
l=m+1;
}
else{
r=m-1;
res=m;
}
}
cout<<z[t.roots[res].S]<<"\n";
}
}
}
signed main(){
// freopen("help.in","r",stdin);
// freopen("help.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")
|
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
28 ms |
48732 KB |
Output is correct |
2 |
Correct |
33 ms |
48868 KB |
Output is correct |
3 |
Correct |
18 ms |
48728 KB |
Output is correct |
4 |
Correct |
26 ms |
48732 KB |
Output is correct |
5 |
Correct |
9 ms |
48728 KB |
Output is correct |
6 |
Correct |
8 ms |
48732 KB |
Output is correct |
7 |
Correct |
47 ms |
48872 KB |
Output is correct |
8 |
Correct |
52 ms |
48904 KB |
Output is correct |
9 |
Correct |
47 ms |
48868 KB |
Output is correct |
10 |
Correct |
49 ms |
48904 KB |
Output is correct |
11 |
Correct |
53 ms |
48836 KB |
Output is correct |
12 |
Correct |
46 ms |
48884 KB |
Output is correct |
13 |
Correct |
58 ms |
48860 KB |
Output is correct |
14 |
Correct |
76 ms |
48728 KB |
Output is correct |
15 |
Correct |
52 ms |
48872 KB |
Output is correct |
16 |
Correct |
79 ms |
48732 KB |
Output is correct |
17 |
Correct |
26 ms |
48732 KB |
Output is correct |
18 |
Correct |
42 ms |
48732 KB |
Output is correct |
19 |
Correct |
10 ms |
48732 KB |
Output is correct |
20 |
Correct |
10 ms |
48728 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
28 ms |
48732 KB |
Output is correct |
2 |
Correct |
33 ms |
48868 KB |
Output is correct |
3 |
Correct |
18 ms |
48728 KB |
Output is correct |
4 |
Correct |
26 ms |
48732 KB |
Output is correct |
5 |
Correct |
9 ms |
48728 KB |
Output is correct |
6 |
Correct |
8 ms |
48732 KB |
Output is correct |
7 |
Correct |
47 ms |
48872 KB |
Output is correct |
8 |
Correct |
52 ms |
48904 KB |
Output is correct |
9 |
Correct |
47 ms |
48868 KB |
Output is correct |
10 |
Correct |
49 ms |
48904 KB |
Output is correct |
11 |
Correct |
53 ms |
48836 KB |
Output is correct |
12 |
Correct |
46 ms |
48884 KB |
Output is correct |
13 |
Correct |
58 ms |
48860 KB |
Output is correct |
14 |
Correct |
76 ms |
48728 KB |
Output is correct |
15 |
Correct |
52 ms |
48872 KB |
Output is correct |
16 |
Correct |
79 ms |
48732 KB |
Output is correct |
17 |
Correct |
26 ms |
48732 KB |
Output is correct |
18 |
Correct |
42 ms |
48732 KB |
Output is correct |
19 |
Correct |
10 ms |
48732 KB |
Output is correct |
20 |
Correct |
10 ms |
48728 KB |
Output is correct |
21 |
Correct |
28 ms |
48732 KB |
Output is correct |
22 |
Correct |
33 ms |
48980 KB |
Output is correct |
23 |
Correct |
20 ms |
48732 KB |
Output is correct |
24 |
Correct |
25 ms |
48900 KB |
Output is correct |
25 |
Correct |
9 ms |
48732 KB |
Output is correct |
26 |
Correct |
8 ms |
48732 KB |
Output is correct |
27 |
Correct |
43 ms |
48836 KB |
Output is correct |
28 |
Correct |
46 ms |
48732 KB |
Output is correct |
29 |
Correct |
43 ms |
48848 KB |
Output is correct |
30 |
Correct |
43 ms |
48728 KB |
Output is correct |
31 |
Correct |
47 ms |
48892 KB |
Output is correct |
32 |
Correct |
47 ms |
48896 KB |
Output is correct |
33 |
Correct |
62 ms |
48732 KB |
Output is correct |
34 |
Correct |
78 ms |
48896 KB |
Output is correct |
35 |
Correct |
54 ms |
48728 KB |
Output is correct |
36 |
Correct |
83 ms |
48728 KB |
Output is correct |
37 |
Correct |
9 ms |
48728 KB |
Output is correct |
38 |
Correct |
9 ms |
48732 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1045 ms |
48988 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
59 ms |
98656 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
28 ms |
48732 KB |
Output is correct |
2 |
Correct |
33 ms |
48868 KB |
Output is correct |
3 |
Correct |
18 ms |
48728 KB |
Output is correct |
4 |
Correct |
26 ms |
48732 KB |
Output is correct |
5 |
Correct |
9 ms |
48728 KB |
Output is correct |
6 |
Correct |
8 ms |
48732 KB |
Output is correct |
7 |
Correct |
47 ms |
48872 KB |
Output is correct |
8 |
Correct |
52 ms |
48904 KB |
Output is correct |
9 |
Correct |
47 ms |
48868 KB |
Output is correct |
10 |
Correct |
49 ms |
48904 KB |
Output is correct |
11 |
Correct |
53 ms |
48836 KB |
Output is correct |
12 |
Correct |
46 ms |
48884 KB |
Output is correct |
13 |
Correct |
58 ms |
48860 KB |
Output is correct |
14 |
Correct |
76 ms |
48728 KB |
Output is correct |
15 |
Correct |
52 ms |
48872 KB |
Output is correct |
16 |
Correct |
79 ms |
48732 KB |
Output is correct |
17 |
Correct |
26 ms |
48732 KB |
Output is correct |
18 |
Correct |
42 ms |
48732 KB |
Output is correct |
19 |
Correct |
10 ms |
48732 KB |
Output is correct |
20 |
Correct |
10 ms |
48728 KB |
Output is correct |
21 |
Execution timed out |
1045 ms |
48988 KB |
Time limit exceeded |
22 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
117 ms |
49756 KB |
Output is correct |
2 |
Correct |
115 ms |
51412 KB |
Output is correct |
3 |
Correct |
131 ms |
51332 KB |
Output is correct |
4 |
Correct |
78 ms |
50392 KB |
Output is correct |
5 |
Correct |
93 ms |
50904 KB |
Output is correct |
6 |
Correct |
111 ms |
51172 KB |
Output is correct |
7 |
Correct |
33 ms |
50440 KB |
Output is correct |
8 |
Correct |
26 ms |
50400 KB |
Output is correct |
9 |
Correct |
72 ms |
51124 KB |
Output is correct |
10 |
Correct |
53 ms |
50388 KB |
Output is correct |
11 |
Correct |
82 ms |
51004 KB |
Output is correct |
12 |
Correct |
79 ms |
50992 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
28 ms |
48732 KB |
Output is correct |
2 |
Correct |
33 ms |
48868 KB |
Output is correct |
3 |
Correct |
18 ms |
48728 KB |
Output is correct |
4 |
Correct |
26 ms |
48732 KB |
Output is correct |
5 |
Correct |
9 ms |
48728 KB |
Output is correct |
6 |
Correct |
8 ms |
48732 KB |
Output is correct |
7 |
Correct |
47 ms |
48872 KB |
Output is correct |
8 |
Correct |
52 ms |
48904 KB |
Output is correct |
9 |
Correct |
47 ms |
48868 KB |
Output is correct |
10 |
Correct |
49 ms |
48904 KB |
Output is correct |
11 |
Correct |
53 ms |
48836 KB |
Output is correct |
12 |
Correct |
46 ms |
48884 KB |
Output is correct |
13 |
Correct |
58 ms |
48860 KB |
Output is correct |
14 |
Correct |
76 ms |
48728 KB |
Output is correct |
15 |
Correct |
52 ms |
48872 KB |
Output is correct |
16 |
Correct |
79 ms |
48732 KB |
Output is correct |
17 |
Correct |
26 ms |
48732 KB |
Output is correct |
18 |
Correct |
42 ms |
48732 KB |
Output is correct |
19 |
Correct |
10 ms |
48732 KB |
Output is correct |
20 |
Correct |
10 ms |
48728 KB |
Output is correct |
21 |
Correct |
28 ms |
48732 KB |
Output is correct |
22 |
Correct |
33 ms |
48980 KB |
Output is correct |
23 |
Correct |
20 ms |
48732 KB |
Output is correct |
24 |
Correct |
25 ms |
48900 KB |
Output is correct |
25 |
Correct |
9 ms |
48732 KB |
Output is correct |
26 |
Correct |
8 ms |
48732 KB |
Output is correct |
27 |
Correct |
43 ms |
48836 KB |
Output is correct |
28 |
Correct |
46 ms |
48732 KB |
Output is correct |
29 |
Correct |
43 ms |
48848 KB |
Output is correct |
30 |
Correct |
43 ms |
48728 KB |
Output is correct |
31 |
Correct |
47 ms |
48892 KB |
Output is correct |
32 |
Correct |
47 ms |
48896 KB |
Output is correct |
33 |
Correct |
62 ms |
48732 KB |
Output is correct |
34 |
Correct |
78 ms |
48896 KB |
Output is correct |
35 |
Correct |
54 ms |
48728 KB |
Output is correct |
36 |
Correct |
83 ms |
48728 KB |
Output is correct |
37 |
Correct |
9 ms |
48728 KB |
Output is correct |
38 |
Correct |
9 ms |
48732 KB |
Output is correct |
39 |
Execution timed out |
1045 ms |
48988 KB |
Time limit exceeded |
40 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
28 ms |
48732 KB |
Output is correct |
2 |
Correct |
33 ms |
48868 KB |
Output is correct |
3 |
Correct |
18 ms |
48728 KB |
Output is correct |
4 |
Correct |
26 ms |
48732 KB |
Output is correct |
5 |
Correct |
9 ms |
48728 KB |
Output is correct |
6 |
Correct |
8 ms |
48732 KB |
Output is correct |
7 |
Correct |
47 ms |
48872 KB |
Output is correct |
8 |
Correct |
52 ms |
48904 KB |
Output is correct |
9 |
Correct |
47 ms |
48868 KB |
Output is correct |
10 |
Correct |
49 ms |
48904 KB |
Output is correct |
11 |
Correct |
53 ms |
48836 KB |
Output is correct |
12 |
Correct |
46 ms |
48884 KB |
Output is correct |
13 |
Correct |
58 ms |
48860 KB |
Output is correct |
14 |
Correct |
76 ms |
48728 KB |
Output is correct |
15 |
Correct |
52 ms |
48872 KB |
Output is correct |
16 |
Correct |
79 ms |
48732 KB |
Output is correct |
17 |
Correct |
26 ms |
48732 KB |
Output is correct |
18 |
Correct |
42 ms |
48732 KB |
Output is correct |
19 |
Correct |
10 ms |
48732 KB |
Output is correct |
20 |
Correct |
10 ms |
48728 KB |
Output is correct |
21 |
Correct |
28 ms |
48732 KB |
Output is correct |
22 |
Correct |
33 ms |
48980 KB |
Output is correct |
23 |
Correct |
20 ms |
48732 KB |
Output is correct |
24 |
Correct |
25 ms |
48900 KB |
Output is correct |
25 |
Correct |
9 ms |
48732 KB |
Output is correct |
26 |
Correct |
8 ms |
48732 KB |
Output is correct |
27 |
Correct |
43 ms |
48836 KB |
Output is correct |
28 |
Correct |
46 ms |
48732 KB |
Output is correct |
29 |
Correct |
43 ms |
48848 KB |
Output is correct |
30 |
Correct |
43 ms |
48728 KB |
Output is correct |
31 |
Correct |
47 ms |
48892 KB |
Output is correct |
32 |
Correct |
47 ms |
48896 KB |
Output is correct |
33 |
Correct |
62 ms |
48732 KB |
Output is correct |
34 |
Correct |
78 ms |
48896 KB |
Output is correct |
35 |
Correct |
54 ms |
48728 KB |
Output is correct |
36 |
Correct |
83 ms |
48728 KB |
Output is correct |
37 |
Correct |
9 ms |
48728 KB |
Output is correct |
38 |
Correct |
9 ms |
48732 KB |
Output is correct |
39 |
Execution timed out |
1045 ms |
48988 KB |
Time limit exceeded |
40 |
Halted |
0 ms |
0 KB |
- |