Submission #1000260

#TimeUsernameProblemLanguageResultExecution timeMemory
1000260vjudge1Growing Trees (BOI11_grow)C++17
100 / 100
54 ms4948 KiB
#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(first_pos, -1); int nw_pos = last_pos - (k - (first_pos - l)) + 1; fen.upd(nw_pos, 1); fen.upd(last_pos + 1, -1); } } // FOR(j, 1, numTree) cout << fen.query(j) << " \n"[j == numTree]; } 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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...