이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#pragma GCC optimize("O2")
#include <bits/stdc++.h>
#ifdef DEBUG
#include "debug.hpp"
#endif
using namespace std;
#define all(c)              (c).begin(), (c).end()
#define rall(c)             (c).rbegin(), (c).rend()
#define traverse(c, it)     for(auto it = (c).begin(); it != (c).end(); ++it)
#define rep(i, N)           for(int i = 0; i < (N); ++i)
#define rrep(i, N)          for(int i = (N) - 1; i >= 0; --i)
#define rep1(i, N)          for(int i = 1; i <= (N); ++i)
#define rep2(i, s, e)       for(int i = (s); i <= (e); ++i)
#define rep3(i, s, e, d)    for(int i = (s); (d) >= 0 ? i <= (e) : i >= (e); i += (d))
#ifdef DEBUG
#define debug(x...)         { \
                            ++dbg::depth; \
                            string dbg_vals = dbg::to_string(x); \
                            --dbg::depth; \
                            dbg::fprint(__func__, __LINE__, #x, dbg_vals); \
                            }
#define light_debug(x)      { \
                            dbg::light = true; \
                            dbg::dout << __func__ << ":" << __LINE__; \
                            dbg::dout << "  " << #x << " = " << x << endl; \
                            dbg::light = false; \
                            }
#else
#define debug(x...)         42
#define light_debug(x)      42
#endif
using ll = long long;
template<typename T>
inline T& ckmin(T& a, T b) { return a = a > b ? b : a; }
template<typename T>
inline T& ckmax(T& a, T b) { return a = a < b ? b : a; }
template<typename T>
class fenwick_tree {
    int n;
    vector<T> a;
public:
    fenwick_tree(int n_) : n{n_}, a(n + 1) {}
    void update(int i, T v) {
        for(++i; i <= n; i += i & -i) a[i] += v;
    }
    T query(int i) const {
        T s{};
        for(++i; i > 0; i -= i & -i) s += a[i];
        return s;
    }
};
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    
    #ifdef DEBUG
    freopen("debug", "w", stderr);
    #endif
    int N, M; cin >> N >> M;
    fenwick_tree<int> bit(N);
    {
        vector<int> h(N); for(int& x : h) cin >> x;
        sort(all(h));
        rep(i, N) bit.update(i, h[i]), bit.update(i + 1, -h[i]); 
    }
    auto lower_b = [&](int h) -> int {
        int i{-1};
        for(int k{1 << __lg(N)}; k; k >>= 1)
            if(i + k < N && bit.query(i + k) < h)
                i += k;
        return i += 1;
    };
    auto upd = [&](int l, int r) -> void {
        bit.update(l, 1), bit.update(r + 1, -1);
    };
    rep(_, M) {
        char t; cin >> t;
        if(t == 'F') {
            int c, h; cin >> c >> h;
            int i{lower_b(h)};
            if(i + c >= N)
                upd(i, N - 1);
            else {
                int x = bit.query(i + c - 1);
                int j{lower_b(x)}, k{lower_b(x + 1) - 1};
                upd(i, j - 1);
                upd(k - (c - (j - i)) + 1, k);
            }
        } else if(t == 'C') {
            int mn, mx; cin >> mn >> mx;
            cout << lower_b(mx + 1) - lower_b(mn) << '\n';
        }
    }
    
    #ifdef DEBUG
    dbg::dout << "\nExecution time: " << clock() * 1000 / CLOCKS_PER_SEC  << "ms" << endl;
    #endif
    return 0;
}
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... |