# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
706413 | damwuan | Monkey and Apple-trees (IZhO12_apple) | C++14 | 275 ms | 203540 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>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define bit(n,i) ((n>>i)&1)
#define all(x) x.begin(),x.end()
#pragma GCC optimize("O2,unroll-loops")
#pragma GCC target("avx,avx2,bmi,bmi2,sse,sse2,sse3,ssse3,sse4,popcnt")
#define int long long
typedef long long ll;
typedef pair<int,int> pii;
typedef double ld;
typedef pair<ld,ld> pdd;
typedef pair<ll,ll> pll;
const ll maxn=1e5+69;
const ll inf=1e18;
const ll mod=1e9+7;
int n;
struct Tnode
{
int l,r,val,lazy;
Tnode(): l(-1),r(-1),val(0),lazy(0){};
}st[maxn*64];
int CntNode=1;
void addchild(int id)
{
st[id].l=++CntNode;
st[id].r=++CntNode;
}
void push(int id,int l,int mid,int r)
{
int& t=st[id].lazy;
if (t==0) return;
st[st[id].l].lazy=t;
st[st[id].r].lazy=t;
st[st[id].l].val=t*(mid-l+1);
st[st[id].r].val=t*(r-mid);
t=0;
}
void Update(int id,int l,int r,int u,int v,int val)
{
if (l>v || r<u)
{
return;
}
if (u<=l && r<=v)
{
st[id].val=(r-l+1)*val;
st[id].lazy=val;
return;
}
if (st[id].l==-1) addchild(id);
int mid = l+r>>1;
push(id,l,mid,r);
Update(st[id].l,l,mid,u,v,val);
Update(st[id].r,mid+1,r,u,v,val);
st[id].val=st[st[id].l].val + st[st[id].r].val;
}
ll Get(int id,int l,int r,int u,int v)
{
if (l>v || r<u)
{
return 0;
}
if (u<=l && r<=v)
{
return st[id].val;
}
if (st[id].l==-1) addchild(id);
int mid = l+r>>1;
push(id,l,mid,r);
return Get(st[id].l,l,mid,u,v) + Get(st[id].r,mid+1,r,u,v);
}
void sol()
{
cin >> n;
int c=0;
for (int i=1;i<=n;i++)
{
int type,l,r;cin >> type>>l>>r;
l+=c;
r+=c;
if (type ==2) Update(1,1,1e9,l,r,1);
else cout << (c=Get(1,1,1e9,l,r))<<'\n';
}
}
int32_t main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
sol();
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |