Submission #762424

# Submission time Handle Problem Language Result Execution time Memory
762424 2023-06-21T11:45:45 Z otarius Growing Trees (BOI11_grow) C++17
0 / 100
345 ms 3284 KB
#include <bits/stdc++.h>
using namespace std;
 
#define ff first
#define sc second
#define pb push_back
#define ll long long
#define pll pair<ll, ll>
#define pii pair <int, int>
#define ull unsigned long long
 
// #define int long long
// #define int unsigned long long
 
const ll inf = 1e18 + 7;
const ll weirdMod = 998244353;

int t[400040], lazy[400040], n, m;
void prop(int v, int tl, int tr) {
    t[v] += lazy[v] * (tr - tl + 1);
    if (tl != tr) {
        lazy[2 * v] += lazy[v];
        lazy[2 * v + 1] += lazy[v];
    } lazy[v] = 0;
}
void set_val(int v, int tl, int tr, int pos, int val) {
    if (tl == tr) {
        t[v] = val;
        return;
    } int tm = (tl + tr) / 2;
    if (pos <= tm)
        set_val(2 * v, tl, tm, pos, val);
    else set_val(2 * v + 1, tm + 1, tr, pos, val);
}
int get_val(int v, int tl, int tr, int pos) {
    if (lazy[v])
        prop(v, tl, tr);
    if (tl == tr)
        return t[v];
    int tm = (tl + tr) / 2;
    if (pos <= tm)
        return get_val(2 * v, tl, tm, pos);
    else return get_val(2 * v + 1, tm + 1, tr, pos);
}
void add_one(int v, int tl, int tr, int l, int r) {
    if (lazy[v])
        prop(v, tl, tr);
    if (tr < l || r < tl)
        return;
    if (l <= tl && tr <= r) {
        t[v] += tr - tl + 1;
        if (tl != tr) {
            lazy[2 * v]++;
            lazy[2 * v + 1]++;
        } return;
    } int tm = (tl + tr) / 2;
    add_one(2 * v, tl, tm, l, min(r, tm));
    add_one(2 * v + 1, tm + 1, tr, max(l, tm + 1), r);
}
int find_first(int val) {
    int l = 1, r = n, m;
    while (l < r) {
        m = (l + r) / 2;
        if (get_val(1, 1, n, m) < val) l = m + 1;
        else r = m;
    } while (l - 1 > 0 && get_val(1, 1, n, l - 1) >= val) l--;
    return (get_val(1, 1, n, l) < val ? l + 1 : l);
}
int find_second(int val) {
    int l = 1, r = n, m;
    while (l < r) {
        m = (l + r) / 2;
        if (get_val(1, 1, n, m) < val + 1) l = m + 1;
        else r = m;
    } while (l - 1 > 0 && get_val(1, 1, n, l - 1) > val) l--;
    return (get_val(1, 1, n, l) <= val ? l : l - 1);
}
void upd_query(int c, int h) {
    int pos = find_first(h);
    int num = get_val(1, 1, n, pos + c - 1);
    int l = find_first(num), r = find_second(num);
    add_one(1, 1, n, pos, l - 1); c -= l - pos;
    add_one(1, 1, n, r - c + 1, r);
}
void ans_query(int l, int r) {
    l = find_first(l); r = find_second(r);
    cout << r - l + 1 << '\n';
}
void solve() {
    cin >> n >> m;
    vector<int> vec(n);
    for (auto &v : vec) cin >> v;
    sort(vec.begin(), vec.end());
    for (int i = 1; i <= n; i++)
        set_val(1, 1, n, i, vec[i - 1]);
    char v; int l, r;
    for (int i = 1; i <= m; i++) {
        cin >> v >> l >> r;
        if (v == 'F') upd_query(l, r);
        else ans_query(l, r);
    }
}
int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr); cout.tie(nullptr);
 
    int t = 1;
    // cin >> t;
    while (t--) {
        solve();
    } return 0;
}
# Verdict Execution time Memory Grader output
1 Incorrect 163 ms 2752 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 340 KB Output is correct
2 Correct 3 ms 340 KB Output is correct
3 Incorrect 5 ms 340 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 109 ms 680 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 120 ms 656 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 158 ms 1700 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 197 ms 2748 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 155 ms 2740 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 345 ms 2816 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 277 ms 2852 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 274 ms 3284 KB Output isn't correct
2 Halted 0 ms 0 KB -