Submission #339946

# Submission time Handle Problem Language Result Execution time Memory
339946 2020-12-26T11:50:43 Z fixikmila Monkey and Apple-trees (IZhO12_apple) C++14
100 / 100
268 ms 71360 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{
int a,b,c,d;};
cat tree[12000001];
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

apple.cpp: In function 'int main()':
apple.cpp:78:8: warning: unused variable 't' [-Wunused-variable]
   78 |     ll t=1,n,m,k=0,sum=0 ,x=0,y=0,z=0,ans=0,mn=LLONG_MAX,mx=LLONG_MIN;
      |        ^
apple.cpp:78:14: warning: unused variable 'm' [-Wunused-variable]
   78 |     ll t=1,n,m,k=0,sum=0 ,x=0,y=0,z=0,ans=0,mn=LLONG_MAX,mx=LLONG_MIN;
      |              ^
apple.cpp:78:16: warning: unused variable 'k' [-Wunused-variable]
   78 |     ll t=1,n,m,k=0,sum=0 ,x=0,y=0,z=0,ans=0,mn=LLONG_MAX,mx=LLONG_MIN;
      |                ^
apple.cpp:78:20: warning: unused variable 'sum' [-Wunused-variable]
   78 |     ll t=1,n,m,k=0,sum=0 ,x=0,y=0,z=0,ans=0,mn=LLONG_MAX,mx=LLONG_MIN;
      |                    ^~~
apple.cpp:78:45: warning: unused variable 'mn' [-Wunused-variable]
   78 |     ll t=1,n,m,k=0,sum=0 ,x=0,y=0,z=0,ans=0,mn=LLONG_MAX,mx=LLONG_MIN;
      |                                             ^~
apple.cpp:78:58: warning: unused variable 'mx' [-Wunused-variable]
   78 |     ll t=1,n,m,k=0,sum=0 ,x=0,y=0,z=0,ans=0,mn=LLONG_MAX,mx=LLONG_MIN;
      |                                                          ^~
# 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 10 ms 1900 KB Output is correct
5 Correct 13 ms 2284 KB Output is correct
6 Correct 13 ms 2156 KB Output is correct
7 Correct 13 ms 2284 KB Output is correct
8 Correct 91 ms 14956 KB Output is correct
9 Correct 193 ms 25708 KB Output is correct
10 Correct 196 ms 28396 KB Output is correct
11 Correct 204 ms 30572 KB Output is correct
12 Correct 218 ms 31728 KB Output is correct
13 Correct 183 ms 36588 KB Output is correct
14 Correct 185 ms 36972 KB Output is correct
15 Correct 255 ms 67664 KB Output is correct
16 Correct 268 ms 69996 KB Output is correct
17 Correct 183 ms 40200 KB Output is correct
18 Correct 183 ms 40300 KB Output is correct
19 Correct 261 ms 71276 KB Output is correct
20 Correct 264 ms 71360 KB Output is correct