Submission #1084533

#TimeUsernameProblemLanguageResultExecution timeMemory
1084533BLOBVISGODGrowing Trees (BOI11_grow)C++17
100 / 100
83 ms3284 KiB
#include "bits/stdc++.h" #pragma GCC optimize("O3") using namespace std; #define rep(i,a,b) for(int i=(a); i<(b); ++i) #define all(x) x.begin(),x.end() #define sz(x) int(x.size()) typedef long long ll; typedef vector<int> vi; typedef vector<vi> vvi; struct fentree{ vi a; void add(int at, int val){ for(at++; at<sz(a); at+=at&(-at)) a[at] += val; }void addrange(int l, int r, int val){ // [ ) add(r,-val); add(l,val); } fentree(vi b){ a.resize(sz(b)+1); rep(i,0,sz(b)) addrange(i,i+1,b[i]); }int get(int at){ int ans = 0; for(at++; at>0; at-=at&(-at)) ans += a[at]; return ans; } }; int main(){ cin.tie(NULL),cin.sync_with_stdio(false); int n,m; cin >> n >> m; vi a(n); rep(i,0,n) cin >> a[i]; sort(all(a)); fentree fen(a); auto lowerbound = [&](int v) -> int { int lo = 0, hi = sz(a); while (lo<hi){ int mid = (lo+hi)/2; if (fen.get(mid) < v) lo = mid+1; else hi = mid; }return lo; }; auto update = [&](int c, int h) -> void { int L = lowerbound(h); if (sz(a)-L <= c) fen.addrange(L,sz(a),1); else{ int col = fen.get(L+c-1); // find first index of this col int R1 = lowerbound(col); int numleft = c - (R1-L); // get first index larger than col int R = lowerbound(col+1); int L1 = R - numleft; // update everything fen.addrange(L,R1,1); fen.addrange(L1,R,1); } }; auto query = [&](int lo, int hi) -> int { return lowerbound(hi+1)-lowerbound(lo); }; while(m--){ char t; cin >> t; if (t=='F'){ int c,h; cin>> c >> h; update(c,h); }else{ int lo,hi; cin >> lo >> hi; cout << query(lo,hi) << '\n'; } } }
#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...