This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
/* code by the cute PixelCat owo */
/* as cute as nyachoneko chan! */
#pragma GCC optimize("O4,unroll-loops,no-stack-protector")
#include <bits/stdc++.h>
#define int ll //__int128
#define double long double
using namespace std;
using ll=long long;
using ull=unsigned long long;
using pii=pair<int,int>;
#define For(i,a,b) for(int i=a;i<=b;i++)
#define Fors(i,a,b,s) for(int i=a;i<=b;i+=s)
#define Forr(i,a,b) for(int i=a;i>=b;i--)
#define F first
#define S second
#define L(id) (id*2+1)
#define R(id) (id*2+2)
#define LO(x) (x&(-x))
#define eb emplace_back
#define all(x) x.begin(),x.end()
#define sz(x) ((int)x.size())
#define mkp make_pair
#define MOD (int)(1000000007)
#define INF (int)(1e17)
#define EPS (1e-6)
#ifdef NYAOWO
#define debug(...) do{\
cerr << __LINE__ <<\
" : ("#__VA_ARGS__ << ") = ";\
_OUT(__VA_ARGS__);\
cerr << flush;\
}while(0)
template<typename T> void _OUT(T _X) { cerr << _X << "\n"; }
template<typename T,typename...I>
void _OUT(T _X,I ...tail) { cerr << _X << ", "; _OUT(tail...); }
inline void USACO(const string &s) { cerr<<"USACO: "<<s<<"\n"; }
#else
#define debug(...)
inline void USACO(const string &s){
freopen((s+".in").c_str(),"r",stdin);
freopen((s+".out").c_str(),"w",stdout);
}
#endif
inline void NYA(){ ios::sync_with_stdio(false); cin.tie(0); }
inline int gcd(int a,int b) { return __gcd(a,b); }
inline int lcm(int a,int b) { return a/gcd(a,b)*b; }
int fpow(int b,int p,const int &mod){
int ans=1;
while(p){
if(p&1) ans=ans*b%mod;
p/=2; b=b*b%mod;
}
return ans;
}
int fpow(int b,int p) { return fpow(b,p,MOD); }
template<typename T> inline void chmin(T &_a,const T &_b) { if(_b<_a) _a=_b; }
template<typename T> inline void chmax(T &_a,const T &_b) { if(_b>_a) _a=_b; }
template<typename T1,typename T2>
ostream& operator<<(ostream &os,pair<T1,T2> p){
os<<"("<<p.F<<","<<p.S<<")";
return os;
}
template<typename T>
ostream& operator<<(ostream &os,const vector<T> &v){
os<<"[";
for(auto &i:v)
os<<" "<<i<<",";
os<<"]";
return os;
}
template<typename T>
ostream& operator<<(ostream &os,const deque<T> &v){
os<<"[";
for(auto &i:v)
os<<" "<<i<<",";
os<<"]";
return os;
}
//mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
#define MAXN 250000
struct SegTree{
int sum[MAXN*4+10];
int mn[MAXN*4+10];
void pull(int id){
sum[id]=sum[L(id)]+sum[R(id)];
mn[id]=min(mn[L(id)],sum[L(id)]+mn[R(id)]);
}
void upd(int p,int x,int id=0,int l=0,int r=MAXN){
if(l==r){
sum[id]=mn[id]=x;
return;
}
int m=(l+r)/2;
if(p<=m) upd(p,x,L(id),l,m);
else upd(p,x,R(id),m+1,r);
pull(id);
}
int qrymin(int L,int R,int id=0,int l=0,int r=MAXN){
if(l>=L && r<=R) return mn[id];
int m=(l+r)/2;
if(R<=m) return qrymin(L,R,L(id),l,m);
else if(L>m) return sum[L(id)]+qrymin(L,R,R(id),m+1,r);
return min(qrymin(L,R,L(id),l,m),sum[L(id)]+qrymin(L,R,R(id),m+1,r));
}
int find(int x,int id=0,int l=0,int r=MAXN){
if(l==r) return l;
int m=(l+r)/2;
if(sum[L(id)]>=x) return find(x,L(id),l,m);
return find(x-sum[L(id)],R(id),m+1,r);
}
}cnt,pos;
vector<pii> op[MAXN+10]; //pair(pos,value)
int grp[MAXN+10];
vector<pii> qry[MAXN+10]; //pair(pos,value)
int ans[MAXN+10];
int32_t main(){
NYA();
//nyaacho >/////<
int N,M,Q; cin>>N>>M>>Q;
For(i,1,Q){
int o; cin>>o;
if(o==1){
int l,r,c,k; cin>>l>>r>>c>>k;
grp[i]=c;
op[l].eb(i,k);
op[r+1].eb(i,0);
}else if(o==2){
int l,r,k; cin>>l>>r>>k;
op[l].eb(i,-k);
op[r+1].eb(i,0);
}else{
int a,b; cin>>a>>b;
qry[a].eb(i,b);
}
}
memset(ans,-1,sizeof(ans));
For(i,1,N){
for(auto &o:op[i]){
cnt.upd(o.F,o.S);
if(o.S>=0) pos.upd(o.F,o.S);
}
//For(j,0,Q) cerr<<mkp(cnt.qrymin(j,j),pos.qrymin(j,j))<<" \n"[j==Q];
for(auto &q:qry[i]){
int now=cnt.qrymin(q.F,q.F)-cnt.qrymin(0,q.F);
if(q.S>now){
ans[q.F]=0;
}else{
q.S=now-q.S+1;
q.S=pos.qrymin(q.F,q.F)-q.S+1;
ans[q.F]=grp[pos.find(q.S)];
}
}
}
For(i,1,Q) if(ans[i]!=-1) cout<<ans[i]<<"\n";
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |