답안 #355625

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
355625 2021-01-22T21:23:44 Z AmineTrabelsi 원숭이와 사과 나무 (IZhO12_apple) C++14
0 / 100
1 ms 364 KB
#include "bits/stdc++.h"
using namespace std;
// Hi 
const int M = 1e6;
int a[M+5],tree[M*4],mark[M*4];
void push(int v){
    if(mark[v]){
        tree[v*2] = tree[v*2+1] = tree[v];
        mark[v*2] = mark[v*2+1] = 1;
        mark[v] = 0;
    }
}
void range_update(int v,int tl,int tr,int ql,int qr){
    if(ql > qr)return;
    if(ql == tl && qr == tr){
        tree[v] = 1;
        mark[v] = 1;
    }else{
        push(v);
        int mid = (tl+tr)/2;
        range_update(v*2,tl,mid,ql,min(qr,mid));
        range_update(v*2+1,mid+1,tr,max(mid+1,ql),qr);
    }
}
int range_query(int v,int tl,int tr,int ql,int qr){
    if(tl > qr || tr < ql)return 0;
    if(tl >= ql && tr <= qr && mark[v]){
        return tr-tl+1;
    }
    if(tl == tr)return mark[v];
    push(v);
    int mid = (tl+tr)/2;
    return range_query(v*2,tl,mid,ql,min(qr,mid))+
            range_query(v*2+1,mid+1,tr,max(ql,mid+1),qr);
}
int main(){
    ios::sync_with_stdio(0);cin.tie(0);
    int q;
    cin>>q;
    int c =  0;
    while(q--){
        int t;
        cin>>t;
        if(t == 1){
            int x,y;
            cin>>x>>y;
            x += c-1;
            y += c-1;
            int ans = range_query(1,0,M-1,x,y);
            c += ans;
            cout << ans << '\n';
        }else{
            int x,y;
            cin>>x>>y;
            x += c-1;
            y += c-1;
            range_update(1,0,M-1,x,y);
        }
    }
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Incorrect 1 ms 364 KB Output isn't correct
3 Halted 0 ms 0 KB -