Submission #976456

# Submission time Handle Problem Language Result Execution time Memory
976456 2024-05-06T15:03:23 Z LOLOLO Growing Trees (BOI11_grow) C++17
0 / 100
91 ms 9300 KB
#include <bits/stdc++.h>
#define ll long long
using namespace std;
 
#define           f     first
#define           s     second
#define           pb    push_back
#define           ep    emplace
#define           eb    emplace_back
#define           lb    lower_bound
#define           ub    upper_bound
#define       all(x)    x.begin(), x.end()
#define      rall(x)    x.rbegin(), x.rend()
#define   uniquev(v)    sort(all(v)), (v).resize(unique(all(v)) - (v).begin())
#define     mem(f,x)    memset(f , x , sizeof(f))
#define        sz(x)    (int)(x).size()
#define  __lcm(a, b)    (1ll * ((a) / __gcd((a), (b))) * (b))
#define          mxx    *max_element
#define          mnn    *min_element
#define    cntbit(x)    __builtin_popcountll(x)
#define       len(x)    (int)(x.length())
 
const int N = 2e5 + 100;
int a[N], seg[N * 4], laz[N * 4];

void push(int id) {
    int &t = laz[id];
    laz[id * 2] += t;
    laz[id * 2 + 1] += t;
    seg[id * 2] += t;
    seg[id * 2 + 1] += t;
    t = 0;
}

void upd(int id, int l, int r, int u, int v, int c) {
    if (l > v || r < u || u > v)
        return;

    if (l >= u && r <= v) {
        seg[id] += c;
        laz[id] += c;
        return;
    }

    push(id);
    int m = (l + r) / 2;
    upd(id * 2, l, m, u, v, c);
    upd(id * 2 + 1, m + 1, r, u, v, c);
    seg[id] = max(seg[id * 2], seg[id * 2 + 1]);
}

int get(int id, int l, int r, int p) {
    if (l == r)
        return seg[id];

    push(id);
    int m = (l + r) / 2;
    if (m >= p)
        return get(id * 2, l, m, p);

    return get(id * 2 + 1, m + 1, r, p);
}

int n;

int find(int id, int l, int r, int k) {
    if (seg[id] < k)
        return n + 1;

    if (l == r)
        return l;

    int m = (l + r) / 2;
    push(id);

    if (seg[id * 2] >= k)
        return find(id * 2, l, m, k);

    return find(id * 2 + 1, m + 1, r, k);
}

int num(int l, int r) {
    return find(1, 1, n, r + 1) - find(1, 1, n, l); 
}

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

    int m;
    cin >> n >> m;

    for (int i = 1; i <= n; i++) {
        cin >> a[i];
    }

    sort(a + 1, a + 1 + n);
    for (int i = 1; i <= n; i++) {
        upd(1, 1, n, i, i, a[i]);
    }

    for (int i = 1; i <= m; i++) {
        char c;
        cin >> c;

        if (c == 'F') {
            int c, h;
            cin >> c >> h;
            int l = find(1, 1, n, h);
            if (l + c - 1 >= n) {
                upd(1, 1, n, l, n, 1);
            } else {
                int r = l + c - 1;
                int val = get(1, 1, n, r);
                int lst = find(1, 1, n, val + 1) - 1;
                int f = get(1, 1, n, val);
                upd(1, 1, n, l, f - 1, 1);
                int remain = (c - (f - l));
                upd(1, 1, n, lst - remain + 1, lst, 1);
            }
        } else {
            int l, r;
            cin >> l >> r;
            cout << num(l, r) << '\n';
        }
    }

    return 0;
}
# Verdict Execution time Memory Grader output
1 Incorrect 56 ms 8272 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 4440 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 28 ms 5596 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 29 ms 5720 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 48 ms 8016 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 60 ms 8036 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 52 ms 8064 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 91 ms 8712 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 63 ms 8304 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 74 ms 9300 KB Output isn't correct
2 Halted 0 ms 0 KB -