#include <bits/stdc++.h>
using namespace std;
#define sf scanf
#define pf printf
#define fi first
#define se second
#define pb push_back
typedef unsigned long long ll;
typedef pair<int,ll> ii;
struct up{ int l,r,c;ll k; };
vector<up> ups;
struct qry{ int l,i;ll k; };
struct thing{
int s,e;
vector<qry> v;
};
queue<thing> qe;
int n,m,q,t,l,r,c,ans[65005];
ll k,ft[65005];
void upd(int x,int y,ll v){
while(x<=n)ft[x]+=v,x+=x&-x;
++y;
while(y<=n)ft[y]-=v,y+=y&-y;
}
ll query(int x){
ll res=0;
while(x)res+=ft[x],x-=x&-x;
return res;
}
int main(){
sf("%d%d%d",&n,&m,&q);
thing th={0,0};
for(int i=0;i<q;++i){
sf("%d",&t);
if(t==1){
sf("%d%d%d%lld",&l,&r,&c,&k);
ups.pb({l,r,c,k});
}
if(t==3){
sf("%d%lld",&l,&k);
th.v.pb({l,i,k});
}
}
memset(ans,-1,sizeof ans);
ups.pb({1,n,0,1000000000000000});
th.e=ups.size()-1;
qe.push(th);
int pv=-1;
while(!qe.empty()){
thing th=qe.front();qe.pop();
if(th.s==th.e){
for(auto qq:th.v){
ans[qq.i]=ups[th.s].c;
}
continue;
}
int m=(th.s+th.e)/2;
thing nl={th.s,m},nr={m+1,th.e};
if(m<pv){
memset(ft,0,sizeof ft);
pv=-1;
}
while(pv<m){
++pv;
upd(ups[pv].l,ups[pv].r,ups[pv].k);
}
for(auto qq:th.v){
if(qq.k<=query(qq.l))nl.v.pb(qq);
else nr.v.pb(qq);
}
if(nl.v.size()>0)qe.push(nl);
if(nr.v.size()>0)qe.push(nr);
}
for(int i=0;i<q;++i)if(ans[i]!=-1)pf("%d\n",ans[i]);
}
/*
3 5 6
1 2 3 5 2
1 1 2 2 4
3 2 3
3 1 2
1 2 3 4 2
3 3 2
3 4 7
1 1 2 1 1
1 1 3 4 1
2 2 3 1
2 1 3 1
1 1 2 2 1
3 1 1
3 3 2
*/
Compilation message
foodcourt.cpp: In function 'int main()':
foodcourt.cpp:36:4: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
36 | sf("%d%d%d",&n,&m,&q);
| ^
foodcourt.cpp:39:5: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
39 | sf("%d",&t);
| ^
foodcourt.cpp:41:6: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
41 | sf("%d%d%d%lld",&l,&r,&c,&k);
| ^
foodcourt.cpp:45:6: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
45 | sf("%d%lld",&l,&k);
| ^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
1100 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
1100 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
29 ms |
2232 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
67 ms |
6284 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
1100 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
75 ms |
3672 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
1100 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
1100 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |