Submission #473578

# Submission time Handle Problem Language Result Execution time Memory
473578 2021-09-15T16:50:20 Z Haidara Monkey and Apple-trees (IZhO12_apple) C++17
0 / 100
117 ms 262148 KB
/** * * * * * * * * * * * * * **\
 *                             *
 *   Author: Haidara Nassour   *
 * Coded in: YYYY\M\D HH:MM:SS *
 *          Lang: C++          *
 *                             *
\** * * * * * * * * * * * * * **/
#include<bits/stdc++.h>
#pragma GCC optimize("O3")
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define int long long
#define rep(i,x,n) for(int i=(x);i<(n);i++)
#define FOR(i,n) rep(i,0,n)
using namespace std;
const int mod=1e9+7;
const int maxn=10000001;
struct node
{
    int sum,lazy,lc,rc,l,r;
    node():sum(0),lazy(0),rc(-1),lc(-1),l(0),r(1e9) {}
} st[maxn];
int nodecnt=2;
void create(int inx,int child)
{
    int mid=(st[inx].l+st[inx].r)/2;
    if(child==1)
    {
        st[inx].lc=nodecnt++;
        st[st[inx].lc].l=st[inx].l;
        st[st[inx].lc].r=mid;
    }
    else
    {
        st[inx].rc=nodecnt++;
        st[st[inx].rc].l=mid+1;
        st[st[inx].rc].r=st[inx].r;
    }
}
void pull(int inx)
{
    if(st[inx].lazy)
    {
        st[inx].sum=st[inx].r-st[inx].l+1;
        if(st[inx].l!=st[inx].r)
        {
            int mid=(st[inx].l+st[inx].r)/2;
            if(st[inx].lc==-1)
                create(inx,1);
            if(st[inx].rc==-1)
                create(inx,2);
            st[st[inx].lc].lazy=1;
            st[st[inx].rc].lazy=1;
        }
    }
    st[inx].lazy=0;
}
int push_up(int inx)
{
    return st[st[inx].lc].sum+st[st[inx].rc].sum;
}
void update(int ul,int ur,int inx)
{
    pull(inx);
    if(ul<=st[inx].l&&st[inx].r<=ur)
    {
        st[inx].lazy=1;
        pull(inx);
        return ;
    }
    if(st[inx].l>ur||ul>st[inx].r)
        return ;
    if(st[inx].lc==-1)
        create(inx,1);
    if(st[inx].rc==-1)
        create(inx,2);
    update(ul,ur,st[inx].lc);
    update(ul,ur,st[inx].rc);
    st[inx].sum=push_up(inx);
}
int query(int ql,int qr,int inx)
{
    pull(inx);
    if(ql<=st[inx].l&&st[inx].r<=qr)
        return st[inx].sum;
    if(ql>st[inx].r||st[inx].l>qr)
        return 0;
    if(st[inx].lc==-1)
        create(inx,1);
    if(st[inx].rc==-1)
        create(inx,2);
    int res=query(ql,qr,st[inx].lc)+query(ql,qr,st[inx].rc);
    st[inx].sum=push_up(inx);
    return res;
}
signed main()
{
    fast;
    int q;
    cin>>q;
    int c=0;
    while(q--)
    {
        int t;
        cin>>t;
        if(t==1)
        {
            int j,k;
            cin>>j>>k;
            c=query(j+c,k+c,1);
            cout<<c<<endl;
        }
        else
        {
            int j,k;
            cin>>j>>k;
            update(j+c,k+c,1);
        }
    }
}

Compilation message

apple.cpp: In constructor 'node::node()':
apple.cpp:19:21: warning: 'node::rc' will be initialized after [-Wreorder]
   19 |     int sum,lazy,lc,rc,l,r;
      |                     ^~
apple.cpp:19:18: warning:   'long long int node::lc' [-Wreorder]
   19 |     int sum,lazy,lc,rc,l,r;
      |                  ^~
apple.cpp:20:5: warning:   when initialized here [-Wreorder]
   20 |     node():sum(0),lazy(0),rc(-1),lc(-1),l(0),r(1e9) {}
      |     ^~~~
apple.cpp: In function 'void pull(long long int)':
apple.cpp:46:17: warning: unused variable 'mid' [-Wunused-variable]
   46 |             int mid=(st[inx].l+st[inx].r)/2;
      |                 ^~~
# Verdict Execution time Memory Grader output
1 Runtime error 117 ms 262148 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -