제출 #1369217

#제출 시각아이디문제언어결과실행 시간메모리
1369217JungPS원숭이와 사과 나무 (IZhO12_apple)C++20
100 / 100
322 ms260416 KiB
#include<bits/stdc++.h>
using namespace std;

#define int long long
int L[40000007],R[40000007],lazy[40000007],seg[40000007],timer=2;
void push(int l,int r,int node){
    if(lazy[node]){
        seg[node]=(r-l+1);
        if(l!=r){
            if(!L[node]) L[node]=timer++;
            if(!R[node]) R[node]=timer++;
            lazy[L[node]]=true;
            lazy[R[node]]=true;
        }
        lazy[node]=false;
    }
}
void update(int cl,int cr,int l,int r,int node){
    push(cl,cr,node);
    if(cl>r || cr<l) return ;
    if(cl>=l && cr<=r){
        lazy[node]=true;
        push(cl,cr,node);
        return ;
    }
    int mid=(cl+cr)>>1;
    if(!L[node]) L[node]=timer++;
    if(!R[node]) R[node]=timer++;
    update(cl,mid,l,r,L[node]);
    update(mid+1,cr,l,r,R[node]);
    seg[node]=seg[L[node]]+seg[R[node]];
}

int query(int cl,int cr,int l,int r,int node){
    if(!node) return 0;
    push(cl,cr,node);
    if(cl>r || cr<l) return 0;
    if(cl>=l && cr<=r){
        return seg[node];
    }
    int mid=(cl+cr)>>1;
    return query(cl,mid,l,r,L[node])+query(mid+1,cr,l,r,R[node]);
}
signed main(){
    ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
    int m; cin >> m;
    int C=0;
    while(m--){
        int t1,t2,t3; cin >> t1 >> t2 >> t3;
        if(t1==1){
            C=query(1,1e9,t2+C,t3+C,1);
            cout << C << '\n';
        }
        else{
            update(1,1e9,t2+C,t3+C,1);
        }
    }
}
#결과 실행 시간메모리채점기 출력
결과를 불러오는 중입니다…