This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
/*
Author of all code: Pedro BIGMAN Dias
Last edit: 15/02/2021
*/
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <string>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <queue>
#include <deque>
#include <list>
#include <iomanip>
#include <stdlib.h>
#include <time.h>
#include <cstring>
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;
#define REP(i,a,b) for(ll i=(ll) a; i<(ll) b; i++)
#define pb push_back
#define mp make_pair
#define pl pair<ll,ll>
#define ff first
#define ss second
#define whole(x) x.begin(),x.end()
#define DEBUG(i) cout<<"Pedro Is The Master "<<i<<endl
#define INF 500000000LL
#define EPS 0.00000001
#define pi 3.14159
ll mod=1000000007LL;
template<class A=ll>
void Out(vector<A> a) {REP(i,0,a.size()) {cout<<a[i]<<" ";} cout<<endl;}
template<class A=ll>
void In(vector<A> &a, ll N) {A cur; REP(i,0,N) {cin>>cur; a.pb(cur);}}
class ST
{
public:
ll N;
class SV //seg value
{
public:
ll a;
SV() {a=-1LL;}
SV(ll x) {a=x;}
SV operator & (SV X) {SV ANS(max(a,X.a)); return ANS;}
};
class LV //lazy value
{
public:
pl a;
LV() {a=mp(0LL,0LL);}
LV(pl x) {a=x;}
LV operator & (LV X)
{
LV ANS(mp(max(a.ff,X.a.ff+a.ss),a.ss+X.a.ss));
return ANS;
}
};
SV upval(ll c) //how lazy values modify a seg value inside a node, c=current node
{
SV X(max(p[c].a+lazy[c].a.ss,lazy[c].a.ff));
return X;
}
SV neuts; LV neutl;
vector<SV> p;
vector<LV> lazy;
vector<pl> range;
ST() {N=0LL;}
ST(vector<ll> arr)
{
N = (ll) 1<<(ll) ceil(log2(arr.size()));
REP(i,0,2*N) {range.pb(mp(0LL,0LL));}
REP(i,0,N) {p.pb(neuts);}
REP(i,0,arr.size()) {SV X(arr[i]); p.pb(X); range[i+N]=mp(i,i);}
REP(i,arr.size(),N) {p.pb(neuts); range[i+N]=mp(i,i);}
ll cur = N-1;
while(cur>0)
{
p[cur]=p[2*cur]&p[2*cur+1];
range[cur]=mp(range[2*cur].ff,range[2*cur+1].ss);
cur--;
}
REP(i,0,2*N) {lazy.pb(neutl);}
}
void prop(ll c) //how lazy values propagate
{
p[c]=upval(c);
lazy[2*c]=lazy[c]&lazy[2*c]; lazy[2*c+1]=lazy[c]&lazy[2*c+1];
lazy[c]=neutl;
}
SV query(ll a,ll b, ll c=1LL) //range [a,b], current node. initially: query(a,b)
{
ll x=range[c].ff; ll y=range[c].ss;
if(y<a || x>b) {return neuts;}
if(x>=a && y<=b) {return upval(c);}
prop(c);
SV ans = query(a,b,2*c)&query(a,b,2*c+1);
return ans;
}
void update(LV s, ll a, ll b, ll c=1LL) //update LV, range [a,b], current node, current range. initially: update(s,a,b)
{
ll x=range[c].ff; ll y=range[c].ss;
if(y<a || x>b) {return ;}
if(x>=a && y<=b)
{
lazy[c]=s&lazy[c];
return;
}
lazy[2*c]=lazy[c]&lazy[2*c]; lazy[2*c+1]=lazy[c]&lazy[2*c+1]; lazy[c]=neutl;
update(s,a,b,2*c); update(s,a,b,2*c+1);
p[c]=upval(2*c)&upval(2*c+1);
}
};
class ST2
{
public:
ll N;
class SV //seg value
{
public:
ll a;
SV() {a=0LL;}
SV(ll x) {a=x;}
SV operator & (SV X) {SV ANS(a+X.a); return ANS;}
};
SV neuts;
vector<SV> p;
vector<pl> range;
ST2() {N=0LL;}
ST2(vector<ll> arr)
{
N = (ll) 1<<(ll) ceil(log2(arr.size()));
REP(i,0,2*N) {range.pb(mp(0LL,0LL));}
REP(i,0,N) {p.pb(neuts);}
REP(i,0,arr.size()) {SV X(arr[i]); p.pb(X); range[i+N]=mp(i,i);}
REP(i,arr.size(),N) {p.pb(neuts); range[i+N]=mp(i,i);}
ll cur = N-1;
while(cur>0)
{
p[cur]=p[2*cur]&p[2*cur+1];
range[cur]=mp(range[2*cur].ff,range[2*cur+1].ss);
cur--;
}
}
SV query(ll a,ll b, ll c=1LL) //range [a,b], current node. initially: query(a,b)
{
ll x=range[c].ff; ll y=range[c].ss;
if(y<a || x>b) {return neuts;}
if(x>=a && y<=b) {return p[c];}
SV ans = query(a,b,2*c)&query(a,b,2*c+1);
return ans;
}
void update(SV s, ll a, ll b, ll c=1LL) //update LV, range [a,b], current node, current range. initially: update(s,a,b)
{
ll x=range[c].ff; ll y=range[c].ss;
if(y<a || x>b) {return ;}
if(x>=a && y<=b)
{
p[c]=s&p[c];
return;
}
update(s,a,b,2*c); update(s,a,b,2*c+1);
p[c]=p[2*c]&p[2*c+1];
}
};
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
ll N,M,Q; cin>>N>>M>>Q;
vector<vector<ll> > que;
ll type;
vector<ll> xx; REP(i,0,N) {xx.pb(0);}
ST CUR(xx); ST TOT(xx); //CURsize, TOTsize
vector<vector<pl> > stall_query; //each stall query is {time,position}, position ignores removes
vector<pl> xxx; REP(i,0,N) {stall_query.pb(xxx);}
REP(q,0,Q)
{
cin>>type; vector<ll> toadd;
if(type==1)
{
In(toadd,4); toadd[0]--; toadd[1]--;
CUR.update((pl){0LL,toadd[3]},toadd[0],toadd[1]);
TOT.update((pl){0LL,toadd[3]},toadd[0],toadd[1]);
}
else if(type==2)
{
In(toadd,3); toadd[0]--; toadd[1]--;
CUR.update((pl) {0LL,-toadd[2]},toadd[0],toadd[1]);
}
else
{
In(toadd,2); toadd[0]--;
ll cursize = CUR.query(toadd[0],toadd[0]).a;
ll totalsize = TOT.query(toadd[0],toadd[0]).a;
ll ind;
if(cursize<toadd[1]) {ind=-1;}
else {ind = totalsize-cursize+toadd[1]-1LL;}
stall_query[toadd[0]].pb(mp(q,ind));
}
que.pb(toadd);
}
vector<vector<ll> > beg,end; vector<ll> xxxx; REP(i,0,N) {beg.pb(xxxx); end.pb(xxxx);}
REP(q,0,Q)
{
if(que[q].size()==4) {beg[que[q][0]].pb(q); end[que[q][1]].pb(q);}
}
vector<pl> ans;
xx.clear(); REP(i,0,Q) {xx.pb(0LL);}
ST2 S(xx); ll ind;
REP(i,0,N)
{
REP(j,0,beg[i].size())
{
ind=beg[i][j];
S.update(que[ind][3],ind,ind);
}
REP(j,0,stall_query[i].size())
{
ind = stall_query[i][j].ss;
ll t = stall_query[i][j].ff;
if(ind==-1) {ans.pb({t,0LL}); continue;}
ll lo=0LL,hi=Q-1LL;
while(lo<hi)
{
ll mid = (lo+hi)/2LL;
if(S.query(0LL,mid).a>=ind+1) {hi=mid;} else {lo=mid+1;}
}
ans.pb({t,que[lo][2]});
}
REP(j,0,end[i].size())
{
ind=end[i][j];
S.update(-que[ind][3],ind,ind);
}
}
sort(whole(ans));
REP(i,0,ans.size()) {cout<<ans[i].ss<<endl;}
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... |