#include<bits/stdc++.h>
#pragma GCC optimize("O3")
#pragma GCC target("avx2")
#define ll long long
#define pii pair<ll,ll>
#define pll pair<ll,ll>
#define plx pair<ll,int>
#define f first
#define s second
#define pb push_back
#define all(x) x.begin(),x.end()
#define vi vector<int>
#define vl vector<ll>
#define vvi vector<vi>
using namespace std;
const int mxn=250005;
struct fenw{
ll a[mxn]{0};
void add(int i,ll amt){
for(;i<mxn;i+=i&-i)a[i]+=amt;
}
ll qr(int l,int r,ll res=0){
for(;r;r-=r&-r)res+=a[r];
for(l--;l;l-=l&-l)res-=a[l];
return res;
}
}fw[2];
struct lazy{
pll t[4*mxn];ll lz[4*mxn]{0};
void build(int i,int l,int r){
if(l==r)return void(t[i]={0,l});
int m=(l+r)>>1;
build(2*i,l,m);build(2*i+1,m+1,r);
t[i]=min(t[2*i],t[2*i+1]);
}
void push(int i,int l,int r){
t[i].f+=lz[i];
if(l<r)lz[2*i]+=lz[i],lz[2*i+1]+=lz[i];
lz[i]=0;
}
void upd(int i,int l,int r,int tl,int tr,ll v){
push(i,l,r);
if(r<tl||l>tr)return;
if(r<=tr&&l>=tl){
lz[i]+=v;push(i,l,r);return;
}int m=(l+r)>>1;upd(2*i,l,m,tl,tr,v);upd(2*i+1,m+1,r,tl,tr,v);
t[i]=min(t[2*i],t[2*i+1]);
}
pll qr(int i,int l,int r,int tl,int tr){
push(i,l,r);
if(r<tl||l>tr)return {1e9,1e9};
if(r<=tr&&l>=tl)return t[i];
int m=(l+r)>>1;
return min(qr(2*i,l,m,tl,tr),qr(2*i+1,m+1,r,tl,tr));
}
}sg;
int main(){
ios_base::sync_with_stdio(0);cin.tie(0);
int n,m,q;cin>>n>>m>>q;int g[q+1];
vector<pair<int,pii>>vec[n+2];vector<pii>ask[n+1];
for(int i=1;i<=q;i++){
int t;cin>>t;
if(t==1){int l,r,k;cin>>l>>r>>g[i]>>k;vec[l].pb({0,{i,k}}),vec[r+1].pb({0,{i,-k}});}
else if(t==2){int l,r,k;cin>>l>>r>>k;vec[l].pb({1,{i,k}}),vec[r+1].pb({1,{i,-k}});}
else {int a,b;cin>>a>>b;ask[a].pb({b,i});}
}sg.build(1,0,q);
int ans[q+1];for(int i=1;i<=q;i++)ans[i]=-1;
for(int i=1;i<=n;i++){
for(auto it : vec[i]){
if(it.f==0){sg.upd(1,0,q,it.s.f,q,it.s.s);fw[0].add(it.s.f,it.s.s);}
else {sg.upd(1,0,q,it.s.f,q,-it.s.s);fw[1].add(it.s.f,it.s.s);}
}
for(auto it : ask[i]){
int st=sg.qr(1,0,q,0,it.s).s;st++;ll tt=it.f+fw[1].qr(st,it.s);
if(fw[0].qr(st,it.s)<tt){ans[it.s]=0;continue;}
int l=st,r=it.s;
while(l<r){
int md=(l+r)>>1;
if(fw[0].qr(st,md)>=tt)r=md;
else l=md+1;
}ans[it.s]=g[l];
}
}
for(int i=1;i<=q;i++)if(ans[i]!=-1)cout<<ans[i]<<'\n';
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
604 KB |
Output is correct |
2 |
Correct |
2 ms |
728 KB |
Output is correct |
3 |
Correct |
2 ms |
736 KB |
Output is correct |
4 |
Correct |
2 ms |
860 KB |
Output is correct |
5 |
Correct |
1 ms |
640 KB |
Output is correct |
6 |
Correct |
1 ms |
604 KB |
Output is correct |
7 |
Correct |
2 ms |
860 KB |
Output is correct |
8 |
Correct |
2 ms |
736 KB |
Output is correct |
9 |
Correct |
2 ms |
908 KB |
Output is correct |
10 |
Correct |
1 ms |
732 KB |
Output is correct |
11 |
Correct |
2 ms |
860 KB |
Output is correct |
12 |
Correct |
2 ms |
1116 KB |
Output is correct |
13 |
Correct |
1 ms |
904 KB |
Output is correct |
14 |
Correct |
2 ms |
860 KB |
Output is correct |
15 |
Correct |
2 ms |
860 KB |
Output is correct |
16 |
Correct |
2 ms |
728 KB |
Output is correct |
17 |
Correct |
2 ms |
860 KB |
Output is correct |
18 |
Correct |
2 ms |
860 KB |
Output is correct |
19 |
Correct |
2 ms |
884 KB |
Output is correct |
20 |
Correct |
1 ms |
860 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
604 KB |
Output is correct |
2 |
Correct |
2 ms |
728 KB |
Output is correct |
3 |
Correct |
2 ms |
736 KB |
Output is correct |
4 |
Correct |
2 ms |
860 KB |
Output is correct |
5 |
Correct |
1 ms |
640 KB |
Output is correct |
6 |
Correct |
1 ms |
604 KB |
Output is correct |
7 |
Correct |
2 ms |
860 KB |
Output is correct |
8 |
Correct |
2 ms |
736 KB |
Output is correct |
9 |
Correct |
2 ms |
908 KB |
Output is correct |
10 |
Correct |
1 ms |
732 KB |
Output is correct |
11 |
Correct |
2 ms |
860 KB |
Output is correct |
12 |
Correct |
2 ms |
1116 KB |
Output is correct |
13 |
Correct |
1 ms |
904 KB |
Output is correct |
14 |
Correct |
2 ms |
860 KB |
Output is correct |
15 |
Correct |
2 ms |
860 KB |
Output is correct |
16 |
Correct |
2 ms |
728 KB |
Output is correct |
17 |
Correct |
2 ms |
860 KB |
Output is correct |
18 |
Correct |
2 ms |
860 KB |
Output is correct |
19 |
Correct |
2 ms |
884 KB |
Output is correct |
20 |
Correct |
1 ms |
860 KB |
Output is correct |
21 |
Incorrect |
1 ms |
604 KB |
Output isn't correct |
22 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
54 ms |
11604 KB |
Output is correct |
2 |
Correct |
78 ms |
12996 KB |
Output is correct |
3 |
Correct |
60 ms |
12760 KB |
Output is correct |
4 |
Correct |
63 ms |
12776 KB |
Output is correct |
5 |
Correct |
59 ms |
12880 KB |
Output is correct |
6 |
Correct |
58 ms |
13028 KB |
Output is correct |
7 |
Correct |
30 ms |
8284 KB |
Output is correct |
8 |
Correct |
31 ms |
8512 KB |
Output is correct |
9 |
Correct |
66 ms |
12732 KB |
Output is correct |
10 |
Correct |
57 ms |
13048 KB |
Output is correct |
11 |
Correct |
65 ms |
12892 KB |
Output is correct |
12 |
Correct |
59 ms |
13048 KB |
Output is correct |
13 |
Correct |
42 ms |
10984 KB |
Output is correct |
14 |
Correct |
57 ms |
12636 KB |
Output is correct |
15 |
Correct |
53 ms |
12416 KB |
Output is correct |
16 |
Correct |
62 ms |
13144 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
59 ms |
29160 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
604 KB |
Output is correct |
2 |
Correct |
2 ms |
728 KB |
Output is correct |
3 |
Correct |
2 ms |
736 KB |
Output is correct |
4 |
Correct |
2 ms |
860 KB |
Output is correct |
5 |
Correct |
1 ms |
640 KB |
Output is correct |
6 |
Correct |
1 ms |
604 KB |
Output is correct |
7 |
Correct |
2 ms |
860 KB |
Output is correct |
8 |
Correct |
2 ms |
736 KB |
Output is correct |
9 |
Correct |
2 ms |
908 KB |
Output is correct |
10 |
Correct |
1 ms |
732 KB |
Output is correct |
11 |
Correct |
2 ms |
860 KB |
Output is correct |
12 |
Correct |
2 ms |
1116 KB |
Output is correct |
13 |
Correct |
1 ms |
904 KB |
Output is correct |
14 |
Correct |
2 ms |
860 KB |
Output is correct |
15 |
Correct |
2 ms |
860 KB |
Output is correct |
16 |
Correct |
2 ms |
728 KB |
Output is correct |
17 |
Correct |
2 ms |
860 KB |
Output is correct |
18 |
Correct |
2 ms |
860 KB |
Output is correct |
19 |
Correct |
2 ms |
884 KB |
Output is correct |
20 |
Correct |
1 ms |
860 KB |
Output is correct |
21 |
Correct |
54 ms |
11604 KB |
Output is correct |
22 |
Correct |
78 ms |
12996 KB |
Output is correct |
23 |
Correct |
60 ms |
12760 KB |
Output is correct |
24 |
Correct |
63 ms |
12776 KB |
Output is correct |
25 |
Correct |
59 ms |
12880 KB |
Output is correct |
26 |
Correct |
58 ms |
13028 KB |
Output is correct |
27 |
Correct |
30 ms |
8284 KB |
Output is correct |
28 |
Correct |
31 ms |
8512 KB |
Output is correct |
29 |
Correct |
66 ms |
12732 KB |
Output is correct |
30 |
Correct |
57 ms |
13048 KB |
Output is correct |
31 |
Correct |
65 ms |
12892 KB |
Output is correct |
32 |
Correct |
59 ms |
13048 KB |
Output is correct |
33 |
Correct |
42 ms |
10984 KB |
Output is correct |
34 |
Correct |
57 ms |
12636 KB |
Output is correct |
35 |
Correct |
53 ms |
12416 KB |
Output is correct |
36 |
Correct |
62 ms |
13144 KB |
Output is correct |
37 |
Correct |
53 ms |
11808 KB |
Output is correct |
38 |
Correct |
47 ms |
11356 KB |
Output is correct |
39 |
Correct |
26 ms |
7660 KB |
Output is correct |
40 |
Correct |
36 ms |
7964 KB |
Output is correct |
41 |
Correct |
52 ms |
12380 KB |
Output is correct |
42 |
Correct |
48 ms |
12904 KB |
Output is correct |
43 |
Correct |
61 ms |
12724 KB |
Output is correct |
44 |
Correct |
53 ms |
12632 KB |
Output is correct |
45 |
Correct |
64 ms |
12892 KB |
Output is correct |
46 |
Correct |
60 ms |
12884 KB |
Output is correct |
47 |
Correct |
38 ms |
11644 KB |
Output is correct |
48 |
Correct |
50 ms |
13288 KB |
Output is correct |
49 |
Correct |
48 ms |
10072 KB |
Output is correct |
50 |
Correct |
51 ms |
11968 KB |
Output is correct |
51 |
Correct |
82 ms |
12868 KB |
Output is correct |
52 |
Correct |
52 ms |
12884 KB |
Output is correct |
53 |
Correct |
38 ms |
11492 KB |
Output is correct |
54 |
Correct |
44 ms |
13144 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
15 ms |
8148 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
604 KB |
Output is correct |
2 |
Correct |
2 ms |
728 KB |
Output is correct |
3 |
Correct |
2 ms |
736 KB |
Output is correct |
4 |
Correct |
2 ms |
860 KB |
Output is correct |
5 |
Correct |
1 ms |
640 KB |
Output is correct |
6 |
Correct |
1 ms |
604 KB |
Output is correct |
7 |
Correct |
2 ms |
860 KB |
Output is correct |
8 |
Correct |
2 ms |
736 KB |
Output is correct |
9 |
Correct |
2 ms |
908 KB |
Output is correct |
10 |
Correct |
1 ms |
732 KB |
Output is correct |
11 |
Correct |
2 ms |
860 KB |
Output is correct |
12 |
Correct |
2 ms |
1116 KB |
Output is correct |
13 |
Correct |
1 ms |
904 KB |
Output is correct |
14 |
Correct |
2 ms |
860 KB |
Output is correct |
15 |
Correct |
2 ms |
860 KB |
Output is correct |
16 |
Correct |
2 ms |
728 KB |
Output is correct |
17 |
Correct |
2 ms |
860 KB |
Output is correct |
18 |
Correct |
2 ms |
860 KB |
Output is correct |
19 |
Correct |
2 ms |
884 KB |
Output is correct |
20 |
Correct |
1 ms |
860 KB |
Output is correct |
21 |
Incorrect |
1 ms |
604 KB |
Output isn't correct |
22 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
604 KB |
Output is correct |
2 |
Correct |
2 ms |
728 KB |
Output is correct |
3 |
Correct |
2 ms |
736 KB |
Output is correct |
4 |
Correct |
2 ms |
860 KB |
Output is correct |
5 |
Correct |
1 ms |
640 KB |
Output is correct |
6 |
Correct |
1 ms |
604 KB |
Output is correct |
7 |
Correct |
2 ms |
860 KB |
Output is correct |
8 |
Correct |
2 ms |
736 KB |
Output is correct |
9 |
Correct |
2 ms |
908 KB |
Output is correct |
10 |
Correct |
1 ms |
732 KB |
Output is correct |
11 |
Correct |
2 ms |
860 KB |
Output is correct |
12 |
Correct |
2 ms |
1116 KB |
Output is correct |
13 |
Correct |
1 ms |
904 KB |
Output is correct |
14 |
Correct |
2 ms |
860 KB |
Output is correct |
15 |
Correct |
2 ms |
860 KB |
Output is correct |
16 |
Correct |
2 ms |
728 KB |
Output is correct |
17 |
Correct |
2 ms |
860 KB |
Output is correct |
18 |
Correct |
2 ms |
860 KB |
Output is correct |
19 |
Correct |
2 ms |
884 KB |
Output is correct |
20 |
Correct |
1 ms |
860 KB |
Output is correct |
21 |
Incorrect |
1 ms |
604 KB |
Output isn't correct |
22 |
Halted |
0 ms |
0 KB |
- |