| # | Time | Username | Problem | Language | Result | Execution time | Memory | 
|---|---|---|---|---|---|---|---|
| 955824 | ZoTH | Monkey and Apple-trees (IZhO12_apple) | C++14 | 323 ms | 157260 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;
typedef unsigned long long ull;
typedef long long ll;
#define N "\n"
#define all(object) object.begin(), object.end()
#define sz(object) (int)object.size()
#define ph push_back
#define pp pop_back
#define ss second
#define ff first
inline void ZoTH(string name = "")
{
    ios_base::sync_with_stdio(false),
        cin.tie(nullptr),
        cout.tie(nullptr);
    if (sz(name))
    {
        freopen((name + ".in").c_str(), "r", stdin);
        freopen((name + ".out").c_str(), "w", stdout);
    }
}
struct node
{
    int sum , lft , rgt ; 
    bool lazy ;   
    node * left , * right ;
    node (int s,int _lft,int _rgt,node * l=nullptr, node* r=nullptr)
    {
        sum= s ;
        lft = _lft;
        rgt = _rgt ;
        left = l  ;
        right = r ;
        lazy=0;
    }
    void mrg()
    {
        if(!lazy)
        sum =(left?left->sum:0)+(right?right->sum:0);
        else sum = rgt-lft+1;
        if(left) left->lazy |=lazy;
        if(right) right->lazy |=lazy ;
    }
};
void update(node * at  , ll lq,ll rq)
{     
     if(lq<=at->lft&&at->rgt<=rq)
     {
         at->lazy=1; 
         at->mrg();                           
     }
     else
     {
         int m =(at->lft+at->rgt)/2;
         int l = at->lft ;
         int r= at->rgt;
         if(lq<=m)
         {
             if(!at->left)at->left=new node(0,l,m);
             at->mrg();
             update(at->left,lq,rq);
         }
         if(m+1<=rq)
         {
             if(!at->right)at->right=new node(0,m+1,r);
             at->mrg();
             update(at->right,lq,rq) ;          
         }
         at->mrg();         
     }
}
int take(node*at,int lq,int rq)
{
     if(lq<=at->lft&&at->rgt<=rq)
     {
          at->mrg();
          return at->sum;
     }
     int m =(at->lft+at->rgt)/2;     
     int l = at->lft ;
     int r= at->rgt;     
     int ret =0  ;
     if(lq<=m)
     {
         if(!at->left)at->left=new node(0,l,m);
         at->mrg();
         ret+=take(at->left,lq,rq) ;               
     }
     if(m+1<=rq)
     {
         if(!at->right)at->right=new node(0,m+1,r);
         at->mrg();         
         ret+=take(at->right,lq,rq) ;     
     }
     at->mrg();     
     return ret ;
}
void solve(int t)
{
    // Goooo
    const int n = (int)1e9+2;
    int m ;
    cin>>m  ;
    node *root = new node (0,1,n);
    int c=0  ;
    
    while(m--)
    {
        int x ,t,  y ;
        cin>>t>> x >> y ; 
        if(t==1)
        {
            c = take(root,x+c,y+c);
            cout << c << N  ;
        }else{
            update(root,x+c,y+c);
        }
    }
    // stooo
}
int main()
{
    ZoTH("");
    // T_BEGIN
    int t = 1;
    //    cin >> t;
    for (int i = 1; i <= t; i++)
    {
        //        cout << "Case " << i << ": ";
        solve(i);
        cout << N;
    }
}
Compilation message (stderr)
| # | Verdict | Execution time | Memory | Grader output | 
|---|---|---|---|---|
| Fetching results... | ||||
