답안 #1030246

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1030246 2024-07-22T00:31:40 Z ArthuroWich Growing Trees (BOI11_grow) C++17
100 / 100
687 ms 8360 KB
#include <bits/stdc++.h>
using namespace std;
#define int long long int
int arr[100005], seg[4*100005], lazy[4*100005];
void lazypropagate(int n, int l, int r) {
    if (lazy[n]) {
        seg[n] += lazy[n];
        if (l != r) {
            lazy[2*n] += lazy[n];
            lazy[2*n+1] += lazy[n];
        }
        lazy[n] = 0;
    }
}
void build(int n, int l, int r) {
    if (l == r) {
        seg[n] = arr[l];
    } else {
        int m = (l+r)/2;
        build(2*n, l, m);
        build(2*n+1, m+1, r);
        seg[n] = max(seg[2*n], seg[2*n+1]);
    }
}
void update(int n, int l, int r, int a, int b, int v) {
    lazypropagate(n, l, r);
    if (b < l || r < a) {
        return;
    } else if (a <= l && r <= b) {
        lazy[n] = v;
        lazypropagate(n, l, r);
    } else {
        int m = (l+r)/2;
        update(2*n, l, m, a, b, v);
        update(2*n+1, m+1, r, a, b, v);
        seg[n] = max(seg[2*n], seg[2*n+1]);
    }
}
int query(int n, int l, int r, int a, int b) {
    if (b < l || r < a) {
        return 0;
    }
    lazypropagate(n, l, r);
    if (a <= l && r <= b) {
        return seg[n];
    } else {
        int m = (l+r)/2;
        return max(query(2*n, l, m, a, b), query(2*n+1, m+1, r, a, b));
    }
}
int search(int n, int h) {
    int l = 0, r = n-1;
    while(l < r) {
        int m = (l+r)/2, v;
        v = query(1, 0, n-1, m, m);
        if (v >= h) {
            r = m;
        } else {
            l = m+1;
        }
    }
    if (query(1, 0, n-1, l, l) < h) {
        return n;
    }
    return l;
}
void solve() {
    int n, m;
    cin >> n >> m;
    vector<int> a(n);
    for (int &x : a) {
        cin >> x;
    }
    sort(a.begin(), a.end());
    for (int i = 0; i < n; i++) {
        arr[i] = a[i];
    }
    build(1, 0, n-1);
    while(m--) {
        char ch;
        cin >> ch;
        if (ch == 'F') {
            int c, h, ind1, ind2, ind3, hm;
            cin >> c >> h;
            ind1 = search(n, h);
            if (ind1 == n) {
                continue;
            }
            if (ind1+c >= n) {
                update(1, 0, n-1, ind1, n-1, 1);
                continue;
            }
            hm = query(1, 0, n-1, ind1+c-1, ind1+c-1);
            ind2 = search(n, hm);
            if (ind1 == ind2) {
                ind3 = search(n, hm+1);
                update(1, 0, n-1, ind3-c, ind3-1, 1);
                continue;
            }
            update(1, 0, n-1, ind1, ind2-1, 1);
            c -= ind2-ind1;
            ind3 = search(n, hm+1);
            update(1, 0, n-1, ind3-c, ind3-1, 1);
        } else {
            int mn, mx;
            cin >> mn >> mx;
            cout << search(n, mx+1)-search(n, mn) << endl;
        }
    }
}
int32_t main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    int t;
    t = 1;
    while(t--) {
        solve();
    }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 475 ms 7156 KB Output is correct
2 Correct 687 ms 7444 KB Output is correct
3 Correct 235 ms 7508 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 584 KB Output is correct
2 Correct 14 ms 612 KB Output is correct
3 Correct 11 ms 604 KB Output is correct
4 Correct 9 ms 588 KB Output is correct
5 Correct 312 ms 1772 KB Output is correct
6 Correct 404 ms 1944 KB Output is correct
7 Correct 19 ms 860 KB Output is correct
8 Correct 299 ms 1424 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 383 ms 1956 KB Output is correct
2 Correct 389 ms 2116 KB Output is correct
3 Correct 7 ms 600 KB Output is correct
4 Correct 357 ms 1764 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 387 ms 2116 KB Output is correct
2 Correct 438 ms 2128 KB Output is correct
3 Correct 34 ms 888 KB Output is correct
4 Correct 378 ms 2136 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 489 ms 4556 KB Output is correct
2 Correct 620 ms 6904 KB Output is correct
3 Correct 100 ms 2004 KB Output is correct
4 Correct 191 ms 7064 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 529 ms 6740 KB Output is correct
2 Correct 647 ms 7076 KB Output is correct
3 Correct 224 ms 7248 KB Output is correct
4 Correct 112 ms 2132 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 535 ms 6952 KB Output is correct
2 Correct 488 ms 7136 KB Output is correct
3 Correct 222 ms 7508 KB Output is correct
4 Correct 113 ms 1948 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 619 ms 7396 KB Output is correct
2 Correct 676 ms 6944 KB Output is correct
3 Correct 74 ms 6988 KB Output is correct
4 Correct 485 ms 7104 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 537 ms 7504 KB Output is correct
2 Correct 508 ms 7504 KB Output is correct
3 Correct 657 ms 7920 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 528 ms 8360 KB Output is correct