Submission #1000247

# Submission time Handle Problem Language Result Execution time Memory
1000247 2024-06-17T07:11:16 Z vjudge1 Growing Trees (BOI11_grow) C++17
0 / 100
51 ms 4688 KB
#include <bits/stdc++.h>

using namespace std;
using ll = long long;

#define int long long
#define FOR(i, a, b) for (int i = (a); i <= (b); i++)
#define FORD(i, a, b) for (int i = (b); i >= (a); i --)
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define REPD(i, n) for (int i = (n) - 1; i >= 0; --i)

#define MASK(i) (1LL << (i))
#define BIT(x, i) (((x) >> (i)) & 1)


constexpr ll LINF = (1ll << 60);
constexpr int INF = (1ll << 30);
constexpr int Mod = 1e9 + 7;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

/*
    Phu Trong from Nguyen Tat Thanh High School for gifted student
*/

template <class X, class Y>
    bool minimize(X &x, const Y &y){
        X eps = 1e-9;
        if (x > y + eps) {x = y; return 1;}
        return 0;
    }

template <class X, class Y>
    bool maximize(X &x, const Y &y){
        X eps = 1e-9;
        if (x + eps < y) {x = y; return 1;}
        return 0;
    }
#define MAX_TREE        100005
int numTree, numQuery;
int h[MAX_TREE];
void init(void){
    cin >> numTree >> numQuery;
    for (int i = 1; i <= numTree; ++i) cin >> h[i];
    sort(h + 1, h + numTree + 1);
}

template<class T = int> struct FenwickTree{
    T *F = nullptr;
    int n;
    FenwickTree(int _n = 0){
        resize(_n);
    }
    void resize(int _n = 0){
        this -> n = _n;
        if (F != nullptr) delete[] F;
        F = new T[n + 5];
        clear();
    }
    void clear(void){
        fill(F, F + 1 + n, 0);
    }

    void upd(int p, T val){
        for (; p <= n; p += p & (-p)) F[p] += val;
    }
    T query(int p){
        T res = 0;
        for (; p > 0; p -= p & (-p)) res += F[p];
        return res;
    }

    int lower_bound(int val){
        int res = 0;
        for (int i = __lg(n); i >= 0; --i){
            if ((res | MASK(i)) <= n && val > F[res | MASK(i)]){
                val -= F[res | MASK(i)];
                res |= MASK(i);
            }
        }
        return res + 1;
    }
    int upper_bound(T val){
        int res = 0;
        for (int i = __lg(n); i >= 0; --i){
            if ((res | MASK(i)) <= n && val >= F[res | MASK(i)]){
                val -= F[res | MASK(i)];
                res |= MASK(i);
            }
        }
        return res + 1;
    }
};

int sub[MAX_TREE];
void process(void){
    FenwickTree <int> fen(numTree);
    for (int i = 1; i <= numTree; ++i){
        sub[i] = h[i] - h[i - 1];
        fen.upd(i, sub[i]);
    }

    for (int i = 1; i <= numQuery; ++i){
        char c; cin >> c;
        if(c == 'F'){
            int k, lim; cin >> k >> lim;
            int l = fen.lower_bound(lim);
            int r = min(l + k - 1, numTree);

            if (r == numTree) fen.upd(l, 1);
            else{
                int last = fen.query(r);

                int last_pos = fen.upper_bound(last) - 1;
                int first_pos = fen.lower_bound(last);

                if (last_pos == r){
                    fen.upd(l, 1); fen.upd(r + 1, -1);
                }
                else{
                    fen.upd(l, 1); fen.upd(r, -1);
                    int nw_pos = last_pos - (first_pos - l - 1);
                    fen.upd(nw_pos, 1); fen.upd(min(last_pos + 1, numTree), -1);
                }
            }
        }
        else{
            int l, r; cin >> l >> r;
            l = fen.lower_bound(l);
            r = fen.upper_bound(r);
            cout << r - l << '\n';
        }
    }
}

signed main(){
    #define name "Whisper"
    cin.tie(nullptr) -> sync_with_stdio(false);
    //freopen(name".inp", "r", stdin);
    //freopen(name".out", "w", stdout);
    init();
    process();
}



# Verdict Execution time Memory Grader output
1 Incorrect 23 ms 3676 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 16 ms 1372 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 17 ms 1372 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 25 ms 2908 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 23 ms 3164 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 25 ms 3408 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 51 ms 4044 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 26 ms 3668 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 50 ms 4688 KB Output isn't correct
2 Halted 0 ms 0 KB -