답안 #1114908

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1114908 2024-11-19T18:15:16 Z vladilius Growing Trees (BOI11_grow) C++17
100 / 100
105 ms 6292 KB
#include <bits/stdc++.h>
using namespace std;
const int msz = 1e5 + 5;

vector<int> t(4 * msz), p(4 * msz, 0), a(msz);
int n;

void merge(int v){
    int vv = 2 * v;
    t[v] = max(t[vv], t[vv + 1]);
}

void push(int v, int tl, int tr){
    if (tl == tr || !p[v]){
        return;
    }
    int vv = 2 * v;
    t[vv] += p[v]; t[vv + 1] += p[v];
    p[vv] += p[v]; p[vv + 1] += p[v];
    p[v] = 0;
}

void build(int v, int tl, int tr){
    if (tl == tr){
        t[v] = a[tl];
        return;
    }
    int tm = (tl + tr) / 2, vv = 2 * v;
    build(vv, tl, tm);
    build(vv + 1, tm + 1, tr);
    merge(v);
}

void add(int v, int tl, int tr, int l, int r){
    if (l > tr || r < tl || tl > tr){
        return;
    }
    if (l <= tl && tr <= r){
        t[v]++;
        p[v]++;
        return;
    }
    push(v, tl, tr);
    int tm = (tl + tr) / 2, vv = 2 * v;
    add(vv, tl, tm, l, r);
    add(vv + 1, tm + 1, tr, l, r);
    merge(v);
}

int find(int v, int tl, int tr, int val){
    if (tl == tr){
        if (t[v] >= val){
            return tl;
        }
        return n + 1;
    }
    push(v, tl, tr);
    int tm = (tl + tr) / 2, vv = 2 * v;
    if (t[vv] >= val){
        return find(vv, tl, tm, val);
    }
    return find(vv + 1, tm + 1, tr, val);
}

int get(int v, int tl, int tr, int pos){
    if (tl == tr){
        return t[v];
    }
    push(v, tl, tr);
    int tm = (tl + tr) / 2, vv = 2 * v;
    if (pos <= tm){
        return get(vv, tl, tm, pos);
    }
    return get(vv + 1, tm + 1, tr, pos);
}

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

	int m; cin>>n>>m;
    for (int i = 1; i <= n; i++){
        cin>>a[i];
    }
    sort(a.begin() + 1, a.begin() + n + 1);
    build(1, 1, n);
    while (m--){
        char type; int x, y; cin>>type>>x>>y;
        if (type == 'F'){
            if (t[1] < y){
                continue;
            }
            int l = find(1, 1, n, y), r = min(n, l + x - 1);
            if (r == n){
                add(1, 1, n, l, n);
                continue;
            }
            int ar = get(1, 1, n, r + 1); 
            int j = find(1, 1, n, ar), rp = find(1, 1, n, ar + 1) - 1;
            add(1, 1, n, l, j - 1);
            add(1, 1, n, rp + j - x - l + 1, rp);
        }
        else {
            int l = find(1, 1, n, x), r = find(1, 1, n, y + 1);
            cout<<r - l<<"\n";
        }
    }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 55 ms 5192 KB Output is correct
2 Correct 85 ms 5704 KB Output is correct
3 Correct 46 ms 5448 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 3920 KB Output is correct
2 Correct 4 ms 3920 KB Output is correct
3 Correct 4 ms 3920 KB Output is correct
4 Correct 4 ms 3920 KB Output is correct
5 Correct 29 ms 5020 KB Output is correct
6 Correct 33 ms 5220 KB Output is correct
7 Correct 7 ms 3920 KB Output is correct
8 Correct 20 ms 4624 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 28 ms 5272 KB Output is correct
2 Correct 36 ms 5368 KB Output is correct
3 Correct 3 ms 3920 KB Output is correct
4 Correct 21 ms 4944 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 26 ms 5460 KB Output is correct
2 Correct 35 ms 5120 KB Output is correct
3 Correct 9 ms 3920 KB Output is correct
4 Correct 38 ms 5200 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 47 ms 5084 KB Output is correct
2 Correct 71 ms 5192 KB Output is correct
3 Correct 15 ms 4176 KB Output is correct
4 Correct 35 ms 5548 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 70 ms 4936 KB Output is correct
2 Correct 71 ms 5192 KB Output is correct
3 Correct 45 ms 5648 KB Output is correct
4 Correct 14 ms 4176 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 53 ms 5004 KB Output is correct
2 Correct 50 ms 5164 KB Output is correct
3 Correct 39 ms 5628 KB Output is correct
4 Correct 12 ms 4176 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 83 ms 5704 KB Output is correct
2 Correct 72 ms 5192 KB Output is correct
3 Correct 23 ms 4648 KB Output is correct
4 Correct 43 ms 4936 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 63 ms 5448 KB Output is correct
2 Correct 75 ms 5548 KB Output is correct
3 Correct 105 ms 5712 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 60 ms 6292 KB Output is correct