Submission #83724

# Submission time Handle Problem Language Result Execution time Memory
83724 2018-11-10T07:30:27 Z mra2322001 Monkey and Apple-trees (IZhO12_apple) C++14
0 / 100
3 ms 668 KB
#include <bits/stdc++.h>
#define f0(i, n) for(int i(0); i < (n); i++)
#define f1(i, n) for(int i(1); i <= n; i++)

using namespace std;
typedef long long ll;
const int N = 100002;

struct data{
    int l, r, ln, lazy;
    data() {}
    data(int l_, int r_, int ln_) : l(l_), r(r_), ln(ln_) {}
} t[8000000];

int cnt = 1;
int n = 1000000000;

void push(int k, int l, int r){
    int x = t[k].lazy;
    if(x==0) return ;
    t[k].ln = (r - l + 1);
    if(l != r){
        if(t[k].l==0) t[k].l = ++cnt;
        if(t[k].r==0) t[k].r = ++cnt;
        t[t[k].l].lazy = 1;
        t[t[k].r].lazy = 1;
    }
}

void up(int k, int l, int r, int i, int j){
    if(r < i || l > j) return ;
    if(t[k].lazy) return ;
    if(l >= i && r <= j){
        t[k].lazy = 1;
        push(k, l, r);
        return ;
    }
    int m = (l + r)/2;
    if(t[k].l==0) t[k].l = ++cnt;
    if(t[k].r==0) t[k].r = ++cnt;
    up(t[k].l, l, m, i, j);
    up(t[k].r, m + 1, r, i, j);
    t[k].ln = t[t[k].l].ln + t[t[k].r].ln;
}

int get1(int k, int l, int r, int i, int j){
    if(r < i || l > j) return 0;
    push(k, l, r);
    if(l >= i && r <= j){
        return t[k].ln;
    }
    int res = 0;
    int m = (l + r)/2;
    if(t[k].l==0) t[k].l = ++cnt;
    if(t[k].r==0) t[k].r = ++cnt;
    res = get1(t[k].l, l, m, i, j) + get1(t[k].r, m + 1, r, i, j);
    return res;
}

int main(){
    ios_base::sync_with_stdio(0);

    int q; cin >> q;
    int c = 0;
    while(q--){
        int type, l, r; cin >> type >> l >> r;
        if(type==2) up(1, 1, n, l + c, r + c);
        else{
            int x = get1(1, 1, n, l + c, r + c);
            cout << x << endl;
            c += x;
        }
    }
}

# Verdict Execution time Memory Grader output
1 Correct 2 ms 504 KB Output is correct
2 Incorrect 3 ms 668 KB Output isn't correct
3 Halted 0 ms 0 KB -