This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
using namespace std;
#define int long long
int drzewo[2000000][2];
int drzewo2[2000000];
int lazy[2000000];
int t[300000];
int l[300000];
int r[300000];
int c[300000];
int k[300000];
int a[300000];
int b[300000];
int wynik[300000];
vector<pair<int,int> > dodaaj[300000],usun[300000],essa[300000];
int pot=1;
void dodaj(int x,int co,int gdzie)
{
x++;
for(;x<2*1e5;x+=x&-x)
drzewo[x][gdzie]+=co;
}
int zap(int x,int gdzie)
{
x++;
int wynik=0;
for(;x;x&=(x-1))
wynik+=drzewo[x][gdzie];
return wynik;
}
int szukaj(int x,int gdziee)
{
int gdzie=0;
for(int i=19;i>=0;i--)
{
if((gdzie|(1<<i))<2*1e5 && drzewo[(gdzie|(1<<i))][gdziee]<x)
{
gdzie|=(1<<i);
x-=drzewo[gdzie][gdziee];
}
}
return gdzie;
}
void propaguj(int x)
{
drzewo2[x*2]+=lazy[x];
drzewo2[x*2+1]+=lazy[x];
lazy[x*2]+=lazy[x];
lazy[x*2+1]+=lazy[x];
lazy[x]=0;
}
void dodaj2(int x,int l,int r,int L,int R,int ile)
{
if(R<l || L>r)
return;
if(L<=l && r<=R)
{
drzewo2[x]+=ile;
lazy[x]+=ile;
return;
}
propaguj(x);
int mid=(l+r)/2;
dodaj2(x*2,l,mid,L,R,ile);
dodaj2(x*2+1,mid+1,r,L,R,ile);
drzewo2[x]=min(drzewo2[x*2],drzewo2[x*2+1]);
}
int zap2(int x,int l,int r,int L,int R)
{
if(R<l || l>r)
return 0;
if(L<=l && r<=R)
return drzewo2[x];
propaguj(x);
int mid=(l+r)/2;
int wynik=min(zap2(x*2,l,mid,L,R),zap2(x*2+1,mid+1,r,L,R));
drzewo2[x]=min(drzewo2[x*2],drzewo2[x*2+1]);
return wynik;
}
int32_t main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n,m,q;
cin>>n>>m>>q;
while(pot<=q)
pot*=2;
pot--;
for(int i=1;i<=q;i++)
{
cin>>t[i];
if(t[i]==1)
{
cin>>l[i]>>r[i]>>c[i]>>k[i];
dodaaj[l[i]].push_back({i,k[i]});
dodaaj[r[i]+1].push_back({i,-k[i]});
}
else if(t[i]==2)
{
cin>>l[i]>>r[i]>>k[i];
usun[l[i]].push_back({i,k[i]});
usun[r[i]+1].push_back({i,-k[i]});
}
else{
cin>>a[i]>>b[i];
essa[a[i]].push_back({i,b[i]});
}
}
for(int i=1;i<=n;i++)
{
for(int j=0;j<usun[i].size();j++)
{
//cout<<"dodaje "<<usun[i][j].first<<" "<<-usun[i][j].second<<"\n";
dodaj(usun[i][j].first,-usun[i][j].second,0);
dodaj2(1,pot+1,q+pot,usun[i][j].first+pot,q+pot,-usun[i][j].second);
}
for(int j=0;j<dodaaj[i].size();j++)
{
//cout<<"dodaje 2 "<<dodaaj[i][j].first<<" "<<dodaaj[i][j].second<<"\n";
dodaj(dodaaj[i][j].first,dodaaj[i][j].second,0);
dodaj(dodaaj[i][j].first,dodaaj[i][j].second,1);
dodaj2(1,pot+1,q+pot,dodaaj[i][j].first+pot,q+pot,dodaaj[i][j].second);
}
for(int j=0;j<essa[i].size();j++)
{
int gdzie=essa[i][j].first;
int ile=essa[i][j].second;
//cout<<ile<<"\n";
//cout<<zap(gdzie,1)<<" "<<zap(gdzie,0)<<" "<<zap2(1,0,q,0,gdzie+1)<<"\n";
ile+=zap(gdzie,1)-zap(gdzie,0)+min(zap2(1,pot+1,q+pot,pot+1,gdzie+pot),0LL);
//cout<<"mam teraz "<<ile<<"\n";
if(ile>zap(gdzie,1))
wynik[gdzie]=-1;
else wynik[gdzie]=szukaj(ile,1);
if(wynik[gdzie]==0)
while(true)
gdzie++;
//cout<<gdzie<<": "<<wynik[gdzie]<<"\n";
}
}
for(int i=1;i<=q;i++)
{
if(t[i]==3)
{
if(wynik[i]==-1)
cout<<"0\n";
else cout<<c[wynik[i]]<<"\n";
}
}
}
Compilation message (stderr)
foodcourt.cpp: In function 'int32_t main()':
foodcourt.cpp:112:22: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
112 | for(int j=0;j<usun[i].size();j++)
| ~^~~~~~~~~~~~~~~
foodcourt.cpp:118:22: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
118 | for(int j=0;j<dodaaj[i].size();j++)
| ~^~~~~~~~~~~~~~~~~
foodcourt.cpp:125:22: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
125 | for(int j=0;j<essa[i].size();j++)
| ~^~~~~~~~~~~~~~~
# | 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... |