Submission #339133

#TimeUsernameProblemLanguageResultExecution timeMemory
339133beksultan04Monkey and Apple-trees (IZhO12_apple)C++14
0 / 100
850 ms262148 KiB
#include <bits/stdc++.h>
using namespace std;
//#define int long long
#define pii pair<int,int>
#define OK puts("OK");
#define NO puts("NO");
#define YES puts("YES");
#define fr first
#define sc second
#define ret return
#define scan1(a) scanf("%lld",&a);
#define scan2(a,b) scanf("%lld %lld",&a, &b);
#define scan3(a,b,c) scanf("%lld %lld %lld",&a,&b,&c);
#define all(s) s.begin(),s.end()
#define allr(s) s.rbegin(),s.rend()
#define pb push_back
#define sz(v) (int)v.size()
#define endi puts("");
const int N = 1e5+12,INF=1e9+7;

struct node{
    int l, r,sum;
    bool pus;
    node *bala1, *bala2;
    node(int L, int R){
        bala1 = bala2 = NULL;
        sum=pus=0;
        l = L;
        r = R;
    }
};

void push(node *root){
    if (root->pus == 0)ret ;
    if (root->bala1 != NULL) root->bala1->pus |= root->pus;
    if (root->bala2 != NULL) root->bala2->pus |= root->pus;
    root->sum = (root->r - root->l + 1);
}

void update(node *root, int &ql, int &qr){
    int mid = (root->l + root->r)>>1;
    if(root->bala1 == NULL)root->bala1 = new node(root->l,mid);
    if(root->bala2 == NULL)root->bala2 = new node(mid+1,root->r);
    push(root);

    if(root->l > qr || root->r < ql)return;
    if(root->l >= ql && root->r <= qr){
        root->pus = 1;
        push(root);
        return;
    }
    update(root->bala1,ql,qr);
    update(root->bala2,ql,qr);
    root-> sum = root->bala1->sum + root->bala2->sum;
}

int get_ans(node *root,int &ql,int &qr){
    if (ql > root->r || qr < root->l)ret 0;

    int mid = (root->l + root->r)>>1;
    if(root->bala1 == NULL)root->bala1 = new node(root->l,mid);
    if(root->bala2 == NULL)root->bala2 = new node(mid+1,root->r);
    push(root);
    if (qr >= root->r && root->l >= ql)ret root->sum;
    ret get_ans(root->bala1,ql,qr) + get_ans(root->bala2,ql,qr);
}


main(){
    int m,ans=0;
    cin>>m;
    node *root = new node(1, 1e9+1);

    while (m--){
        int l, r;
        char c;
        cin>>c>>l>>r;
        l+=ans;
        r+=ans;
        if (c == '2'){
            update(root,l,r);
        }
        else {
            ans = get_ans(root,l,r);
            cout <<ans<<"\n";

        }
    }
}

Compilation message (stderr)

apple.cpp:69:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   69 | main(){
      |      ^
#Verdict Execution timeMemoryGrader output
Fetching results...