답안 #476459

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
476459 2021-09-27T08:04:11 Z Shin Growing Trees (BOI11_grow) C++14
0 / 100
118 ms 3800 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 0;
        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 upperBound(int lo, int hi, int val) {
} 

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 hi;
    }; 

    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 hi;
    };

    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 (r >= n) {
                f.modifyRange(1, 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;
}

Compilation message

grow.cpp: In function 'int upperBound(int, int, int)':
grow.cpp:57:1: warning: no return statement in function returning non-void [-Wreturn-type]
   57 | }
      | ^
# 결과 실행 시간 메모리 Grader output
1 Incorrect 65 ms 2500 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 336 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 47 ms 1536 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 51 ms 1564 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 71 ms 2164 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 75 ms 2256 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 57 ms 2300 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 114 ms 2976 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 85 ms 2716 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 118 ms 3800 KB Output isn't correct