답안 #471141

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
471141 2021-09-07T14:25:00 Z MohammadAghil 원숭이와 사과 나무 (IZhO12_apple) C++14
0 / 100
479 ms 262144 KB
#include <bits/stdc++.h> 
using namespace std;
typedef long long ll;
#define rep(i,l,r) for(int i = (l); i < r; i++)
#define per(i,r,l) for(int i = (r); i >= l; i--)
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x).size()
#define pb push_back
#define ff first
#define ss second 
 
const ll mod = 1e9 + 7, maxn = 1e5 + 5, inf = 1e9 + 5;

struct node{
    int lx, rx, sum = 0, lazy = 0, l = 0, r = 0;
    node(){}
    node(int sum, int lazy, int lx, int rx, int l = 0, int r = 0):
        sum(sum), lazy(lazy), lx(lx), rx(rx), l(l), r(r){}
};

struct seg{
    vector<node> a;
    int cnt = 1;
    seg(int n){
        a.resize(n);
        a[1] = node(0, 0, 1, 1e9 + 1);
    }
    void build(int x){
        if(!a[x].l){
            int mid = (a[x].lx + a[x].rx) >> 1;
            a[++cnt] = node(0, 0, a[x].lx, mid);
            a[x].l = cnt;
            a[++cnt] = node(0, 0, mid, a[x].rx);
            a[x].r = cnt;
        }
    }
    void shift(int x){
        if(a[x].lazy){
            a[x].sum = a[x].rx - a[x].lx;
            build(x);
            a[a[x].l].lazy = a[a[x].r].lazy = 1;
            a[x].lazy = 0;
        }
    }
    void set(int l, int r, int x){
        shift(x);
        if(l == a[x].lx && r == a[x].rx){
            a[x].lazy = 1;
            shift(x);
            return;
        }
        build(x);
        int mid = (a[x].lx + a[x].rx) >> 1;
        if(l >= mid) set(l, r, a[x].r);
        else if(r <= mid) set(l, r, a[x].l);
        else{
            set(l, mid, a[x].l);
            set(mid, r, a[x].r);
        }
        shift(a[x].l);
        shift(a[x].r);
        a[x].sum = a[a[x].l].sum + a[a[x].r].sum;
    }
    int get(int l, int r, int x){
        shift(x);
        if(l == a[x].lx && r == a[x].rx) return a[x].sum;
        int mid = (a[x].lx + a[x].rx) >> 1;
        build(x);
        if(r <= mid) return get(l, r, a[x].l);
        else if(l >= mid) return get(l, r, a[x].r);
        else return get(l, mid, a[x].l) + get(mid, r, a[x].r);
    }
};


int main(){
    cin.tie(0) -> sync_with_stdio(0);
    int q; cin >> q;
    seg st(maxn*60);
    int c = 0;
    while(q--){
        int d, l, r; cin >> d >> l >> r;
        if(d == 2){
            st.set(c + l, c + r + 1, 1);
        }else{
            c = st.get(c + l, c + r + 1, 1);
            cout << c << '\n';
        }
    }
    return 0;
}

Compilation message

apple.cpp: In constructor 'node::node(int, int, int, int, int, int)':
apple.cpp:15:26: warning: 'node::lazy' will be initialized after [-Wreorder]
   15 |     int lx, rx, sum = 0, lazy = 0, l = 0, r = 0;
      |                          ^~~~
apple.cpp:15:9: warning:   'int node::lx' [-Wreorder]
   15 |     int lx, rx, sum = 0, lazy = 0, l = 0, r = 0;
      |         ^~
apple.cpp:17:5: warning:   when initialized here [-Wreorder]
   17 |     node(int sum, int lazy, int lx, int rx, int l = 0, int r = 0):
      |     ^~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 67 ms 141172 KB Output is correct
2 Correct 65 ms 141120 KB Output is correct
3 Correct 65 ms 141100 KB Output is correct
4 Correct 77 ms 141256 KB Output is correct
5 Correct 82 ms 141396 KB Output is correct
6 Correct 82 ms 141384 KB Output is correct
7 Correct 79 ms 141308 KB Output is correct
8 Correct 174 ms 142268 KB Output is correct
9 Correct 319 ms 143292 KB Output is correct
10 Correct 329 ms 143428 KB Output is correct
11 Correct 339 ms 143316 KB Output is correct
12 Correct 314 ms 143300 KB Output is correct
13 Correct 293 ms 143756 KB Output is correct
14 Correct 284 ms 143772 KB Output is correct
15 Runtime error 479 ms 262144 KB Execution killed with signal 11
16 Halted 0 ms 0 KB -