# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
339967 | scales | Monkey and Apple-trees (IZhO12_apple) | C++17 | 501 ms | 72176 KiB |
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>
/*#ifndef LOCAL_RUN
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("fast-math")
#pragma GCC target("avx2,tune=native")
#endif*/
using namespace std;
int kol,w;
int prav[12000000],lev[12000000],sum[12000000],z[12000000];
void zam(int x, int y,int m,int l,int r)
{
// cout<<"x="<<x<<" y="<<y<<" l="<<l<<" r="<<r<<" m="<<m<<endl;
if(prav[m]==0)
{
prav[m]=w;
w++;
z[w]=0;
sum[w]=0;
}
if(lev[m]==0)
{
lev[m]=w;
w++;
z[w]=0;
sum[w]=0;
}
if(z[m]!=0)
{
sum[m]=r-l+1;
z[m]=0;
z[lev[m]]=1;
z[prav[m]]=1;
}
if(x<=l && y>=r)
{
//cout<<" obrab"<<endl;
z[m]=1;
sum[m]=r-l+1;
}
else
{
if(x>r || y<l)
{
return;
}
else
{
zam(x,y,lev[m],l,(l+r)/2);
zam(x,y,prav[m],(l+r)/2+1,r);
sum[m]=sum[prav[m]]+sum[lev[m]];
}
}
}
void viv(int x, int y,int m,int l,int r)
{
//cout<<"x="<<x<<" y="<<y<<" l="<<l<<" r="<<r<<" kol="<<kol<<endl;
if(prav[m]==0)
{
prav[m]=w;
w++;
z[w]=0;
sum[w]=0;
}
if(lev[m]==0)
{
lev[m]=w;
w++;
z[w]=0;
sum[w]=0;
}
if(z[m]!=0)
{
//cout<<"aaaaaaa"<<endl;
sum[m]=r-l+1;
z[m]=0;
z[lev[m]]=1;
z[prav[m]]=1;
}
if(x<=l && y>=r)
{
kol=kol+sum[m];
//cout<<"sum[m]="<<sum[m]<<endl;
}
else
{
if(x>r || y<l)
{
}
else
{
viv(x,y,lev[m],l,(l+r)/2);
viv(x,y,prav[m],(l+r)/2+1,r);
sum[m]=sum[prav[m]]+sum[lev[m]];
}
}
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
// freopen("input.txt","r",stdin);
// freopen("output.txt","w",stdout);
int t,i,j,dno,mini,x,y,q,m,k,v,n,x1,tip,g,maxi,p,l,r;
cin>>m;
vector<int> st(31);
st[0]=1;
for(i=1;i<=30;i++)
{
st[i]=st[i-1]*2;
}
kol=0;
for(i=0;i<m;i++)
{
cin>>tip;
cin>>x;
cin>>y;
x=x+kol;
y=y+kol;
x--;
y--;
l=0;
r=st[30]-1;
if(tip==2)
{
zam(x,y,0,l,r);
}
else
{
//cout<<"kol="<<kol<<endl;
kol=0;
viv(x,y,0,l,r);
cout<<kol<<endl;
}
}
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |