제출 #337243

#제출 시각아이디문제언어결과실행 시간메모리
337243nvmdavaMonkey and Apple-trees (IZhO12_apple)C++17
100 / 100
49 ms1004 KiB
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ff first
#define ss second
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const int N = 200'005;
const ll MOD = 1'000'000'007;
const int INF = 0x3f3f3f3f;

struct Node{
    int s = 0;
    Node *l, *r;
} *seg = new Node();

void update(Node *v, int l, int r, int L, int R){
    if(l > R || r < L || v -> s == r - l + 1)
        return;
    if(L <= l && r <= R){
        v -> s = r - l + 1;
        return;
    }
    int m = (l + r) >> 1;
    if(!v -> l)
        v -> l = new Node();
    if(!v -> r)
        v -> r = new Node();
    update(v -> l, l, m, L, R);
    update(v -> r, m + 1, r, L, R);

    v -> s = v -> l -> s + v -> r -> s;
}

int query(Node *v, int l, int r, int L, int R){
    if(l > R || r < L || v -> s == 0)
        return 0;
    if(v -> s == r - l + 1)
        return min(r, R) - max(l, L) + 1;
    if(L <= l && r <= R)
        return v -> s;
    int m = (l + r) >> 1;
    return query(v -> l, l, m, L, R) + query(v -> r, m + 1, r, L, R);
}

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    int c = 0;
    int n;
    cin>>n;
    while(n--){
        int q, l, r;
        cin>>q>>l>>r;

        if(q == 1)
            cout<< (c = query(seg, 1, 1'000'000'000, l + c, r + c))<<'\n';
        else
            update(seg, 1, 1'000'000'000, l + c, r + c);
    }
}
#Verdict Execution timeMemoryGrader output
Fetching results...