# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
339939 | 2020-12-26T11:46:02 Z | fixikmila | Monkey and Apple-trees (IZhO12_apple) | C++14 | 52 ms | 33900 KB |
#include <bits/stdc++.h> using namespace std; #define MOD 1000000007 typedef long long ll; typedef pair<ll,ll>pll; typedef long double ld; ll bin_pow(ll a,ll b){ if(b==0)return 1; if(b%2==0){ ll t=bin_pow(a,b/2); return t*t%MOD; } else return a*bin_pow(a,b-1)%MOD; } struct cat{ ll a,b,c,d,x,y,z;}; cat tree[300001]; ll node=1; void push(int v,int tl,int tr){ if(tree[v].c==0)return; /*if(tree[v].a==0){ node++; tree[v].a=node; } if(tree[v].b==0){ node++; tree[v].b=node; }*/ int tm=(tl+tr)/2; tree[tree[v].a].c=tree[tree[v].b].c=1; tree[tree[v].a].d=tm-tl+1; tree[tree[v].b].d=tr-(tm+1)+1; tree[v].c=0; } void update(int l,int r,int v,int tl,int tr){ if(tl>=l&&tr<=r){ tree[v].c=1; tree[v].d=tr-tl+1; return; } else if(tl>r||tr<l)return; if(tree[v].a==0){ node++; tree[v].a=node; } if(tree[v].b==0){ node++; tree[v].b=node; } int tm=(tl+tr)/2; push(v,tl,tr); update(l,r,tree[v].a,tl,tm),update(l,r,tree[v].b,tm+1,tr); tree[v].d=tree[tree[v].a].d+tree[tree[v].b].d; } ll get(int l,int r,int v,int tl,int tr){ if(tl>=l&&tr<=r){ return tree[v].d; } else if(tl>r||tr<l)return 0; int tm=(tl+tr)/2; if(tree[v].a==0){ node++; tree[v].a=node; } if(tree[v].b==0){ node++; tree[v].b=node; } push(v,tl,tr); return get(l,r,tree[v].a,tl,tm)+get(l,r,tree[v].b,tm+1,tr); } int main() { //freopen("b.in","r",stdin); //freopen("b.out","w",stdout); ios::sync_with_stdio(false); cin.tie(0); ll t=1,n,m,k=0,sum=0 ,x=0,y=0,z=0,ans=0,mn=LLONG_MAX,mx=LLONG_MIN; cin>>n; for(int i=0;i<n;i++){ cin>>z>>x>>y; x+=ans; y+=ans; if(z==1){ ans=get(x,y,1,1,1e9); cout<<ans; cout<<"\n"; } else update(x,y,1,1,1e9); } return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 364 KB | Output is correct |
2 | Correct | 1 ms | 364 KB | Output is correct |
3 | Correct | 1 ms | 364 KB | Output is correct |
4 | Correct | 14 ms | 5748 KB | Output is correct |
5 | Correct | 17 ms | 6892 KB | Output is correct |
6 | Correct | 17 ms | 6636 KB | Output is correct |
7 | Correct | 17 ms | 6892 KB | Output is correct |
8 | Runtime error | 52 ms | 33900 KB | Execution killed with signal 11 (could be triggered by violating memory limits) |
9 | Halted | 0 ms | 0 KB | - |