답안 #476462

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
476462 2021-09-27T08:13:12 Z Shin Growing Trees (BOI11_grow) C++14
0 / 100
118 ms 1920 KB
#include <bits/stdc++.h>
#define fi first
#define se second
#define mp make_pair
#define TASK "task"
#define all(x) x.begin(), x.end()

using namespace std;
const int N = 2e5 + 7;
const int MOD = 1e9 + 7; // 998244353;
const int INF = 1e9 + 7;
const long long INFLL = 1e18 + 7;

typedef long long ll;
template <class X, class Y> bool minimize(X &a, Y b) {
    if (a > b) return a = b, true;
    return false;
}
template <class X, class Y> bool maximize(X &a, Y b) {
    if (a < b) return a = b, true;
    return false;
}

struct FenwickTree {
    vector<ll> bit;
    int n;

    FenwickTree(int n = 0) {
        this->n = n;
        bit.resize(n + 7);
    }
    
    ll get(int i) {
        ll res = 0;
        for (; i > 0; i -= i & -i) res += bit[i];
        return res;
    }

    ll getRange(int l, int r) {
        if (r > l) return 0LL;
        return get(r) - get(l - 1);
    }
    
    void modify(int i, int v) {
        for (; i <= n; i += i & -i) bit[i] += v;
    }
    
    void modifyRange(int l, int r, int v) {
        if (r < l) return;
        modify(l, v);
        modify(r + 1, -v);
    }
} f;

int n, q;
int a[N];

void solve(void) {
    cin >> n >> q;
    f = FenwickTree(n + 1);
    for (int i = 1; i <= n; i ++) cin >> a[i];
    sort(a + 1, a + n + 1);
    for (int i = 1; i <= n; i ++) f.modifyRange(i, i, a[i]);

    auto lowerBound = [&](int lo, int hi, int val) -> int {
        assert(lo <= hi); hi ++;
        while (lo < hi) {
            int mid = (lo + hi) >> 1;
            if (f.get(mid) >= val) hi = mid;
            else
                lo = mid + 1;
        }
        return lo;
    }; 

    auto upperBound = [&](int lo, int hi, int val) -> int {
        assert(lo <= hi); hi ++;
        while (lo < hi) {
            int mid = (lo + hi) >> 1;
            if (f.get(mid) > val) hi = mid;
            else
                lo = mid + 1;
        }
        return lo;
    };

    while (q --) {
        char type; cin >> type;
        if (type == 'C') {
            int mn, mx; cin >> mn >> mx;
            cout << upperBound(1, n, mx) - lowerBound(1, n, mn) << '\n';
        } else {
            int number, height; cin >> number >> height;
            int l = lowerBound(1, n, height);
            int r = l + number - 1;

            if (l > n) continue;
            if (r >= n) {
                f.modifyRange(l, n, 1);
                continue;
            }
            
            int val = f.get(r);
            int ll = lowerBound(l, n, val);
            int rr = upperBound(r, n, val) - 1;
            f.modifyRange(l, ll - 1, 1);
            f.modifyRange(rr - (number - ll), rr, 1);
        }
    }
}

int main(void) {
    cin.tie(0)->sync_with_stdio(0); 
    int test = 1;
    // cin >> test;
    while (test --) {
        solve();
    }
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 54 ms 1356 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 332 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 59 ms 512 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 43 ms 524 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 58 ms 1152 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 72 ms 1216 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 55 ms 1276 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 116 ms 1392 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 72 ms 1416 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 118 ms 1920 KB Output isn't correct