Submission #1122613

#TimeUsernameProblemLanguageResultExecution timeMemory
1122613steveonalexGrowing Trees (BOI11_grow)C++17
100 / 100
48 ms1608 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef unsigned long long ull; #define MASK(i) (1LL << (i)) #define GETBIT(mask, i) (((mask) >> (i)) & 1) #define ALL(v) (v).begin(), (v).end() ll max(ll a, ll b){return (a > b) ? a : b;} ll min(ll a, ll b){return (a < b) ? a : b;} ll gcd(ll a, ll b){return __gcd(a, b);} ll LASTBIT(ll mask){return (mask) & (-mask);} int pop_cnt(ll mask){return __builtin_popcountll(mask);} int ctz(ll mask){return __builtin_ctzll(mask);} int logOf(ll mask){return __lg(mask);} mt19937_64 rng(chrono::high_resolution_clock::now().time_since_epoch().count()); ll rngesus(ll l, ll r){return l + (ull) rng() % (r - l + 1);} template <class T1, class T2> bool maximize(T1 &a, T2 b){ if (a < b) {a = b; return true;} return false; } template <class T1, class T2> bool minimize(T1 &a, T2 b){ if (a > b) {a = b; return true;} return false; } template <class T> void printArr(T& container, string separator = " ", string finish = "\n"){ for(auto item: container) cout << item << separator; cout << finish; } template <class T> void remove_dup(vector<T> &a){ sort(ALL(a)); a.resize(unique(ALL(a)) - a.begin()); } struct FenwickTree{ int n; vector<int> a; FenwickTree(int _n){ n = _n; a.resize(n+1); } void update(int i, int v){ while(i <= n){ a[i] += v; i += LASTBIT(i); } } int get(int i){ int ans = 0; while(i > 0){ ans += a[i]; i -= LASTBIT(i); } return ans; } int binary_lift(int v){ int idx = 0, p = MASK(logOf(n)); while(p > 0){ if (idx + p <= n && v - a[idx + p] > 0){ idx += p; v -= a[idx]; } p >>= 1; } return idx + 1; } }; void solve(){ int n, q; cin >> n >> q; vector<int> a(n+1); for(int i = 1; i<=n; ++i) cin >> a[i]; sort(ALL(a)); FenwickTree bit(n); for(int i = 1; i <= n; ++i) bit.update(i, a[i] - a[i-1]); while(q--){ char type; cin >> type; if (type == 'F'){ int c, h; cin >> c >> h; int idx1 = bit.binary_lift(h); if (idx1 + c > n) bit.update(idx1, 1); else{ int cu = bit.get(idx1 + c); int idx2 = bit.binary_lift(cu), idx3 = bit.binary_lift(cu + 1); bit.update(idx1, 1); bit.update(idx2, -1); c -= idx2 - idx1; bit.update(idx3 - c, 1); bit.update(idx3, -1); } } if (type == 'C'){ int l, r; cin >> l >> r; cout << bit.binary_lift(r + 1) - bit.binary_lift(l) << "\n"; } } } int main(void){ ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); clock_t start = clock(); solve(); cerr << "Time elapsed: " << clock() - start << "ms!\n"; return 0; }
#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...