답안 #478771

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
478771 2021-10-08T10:57:58 Z MohammadAghil Growing Trees (BOI11_grow) C++14
10 / 100
265 ms 5052 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

ll const mod = 1e9 + 7, maxn = 1e5 + 5, inf = 1e18 + 5;

int seg[maxn << 2], n, h[maxn], lazy[maxn << 2];

void pull(int x, int k){
    seg[x] += k;
    lazy[x] += k;
}

void shift(int x){
    pull(x << 1, lazy[x]);
    pull(x << 1 | 1, lazy[x]);
    lazy[x] = 0;
}

void upd(int l, int r, int x = 1, int lx = 0, int rx = n){
    if(l <= lx && r >= rx){
        pull(x, 1);
        return;
    } if(l >= rx || r <= lx) return;
    shift(x);
    int mid = (lx + rx) >> 1;
    upd(l, r, x << 1, lx, mid);
    upd(l, r, x << 1 | 1, mid, rx);
    seg[x] = max(seg[x << 1], seg[x << 1 | 1]);
}

int query(int k, int x = 1, int lx = 0, int rx = n){
    if(lx + 1 == rx) {
        if(seg[x] > k) return lx;
        else return rx;
    }
    shift(x);
    int mid = (lx + rx) >> 1;
    if(seg[x << 1] > k) return query(k, x << 1, lx, mid);
    return query(k, x << 1 | 1, mid, rx);
}

int get(int i, int x = 1, int lx = 0, int rx = n){
    if(lx + 1 == rx) return seg[x];
    shift(x);
    int mid = (lx + rx) >> 1;
    if(i < mid) return get(i, x << 1, lx, mid);
    return get(i, x << 1 | 1, mid, rx);
}

void build(int x = 1, int lx = 0, int rx = n){
    if(lx + 1 == rx){
        seg[x] = h[lx];
        return;
    }
    int mid = (lx + rx) >> 1;
    build(x << 1, lx, mid);
    build(x << 1 | 1, mid, rx);
    seg[x] = seg[x << 1 | 1];
}

int main(){
    int q; cin >> n >> q;
    for(int i = 0; i < n; i++) cin >> h[i];
    sort(h, h + n);
    build();
    while(q--){
        char c; cin >> c;
        if(c == 'F'){
            int c, h; cin >> c >> h;
            int fst = query(h - 1);
            int en = min(fst + c - 1, n - 1);
            int val = get(en);
            int l_val = query(val-1), r_val = query(val);
            if(fst < l_val) upd(fst, l_val);
            int k = en - l_val + 1;
            upd(r_val - k, r_val);
        }else{
            int l, r; cin >> l >> r;
            cout << query(r) - query(l - 1) << '\n';
        }
    }
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 175 ms 3828 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 336 KB Output is correct
2 Correct 8 ms 336 KB Output is correct
3 Correct 9 ms 336 KB Output is correct
4 Correct 6 ms 336 KB Output is correct
5 Correct 173 ms 1468 KB Output is correct
6 Incorrect 210 ms 1696 KB Output isn't correct
7 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 231 ms 1672 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 201 ms 1748 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 188 ms 2644 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 182 ms 3820 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 158 ms 3732 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 240 ms 4344 KB Output is correct
2 Incorrect 205 ms 4164 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 256 ms 4072 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 265 ms 5052 KB Output is correct