제출 #1287661

#제출 시각아이디문제언어결과실행 시간메모리
1287661HiepVu217Growing Trees (BOI11_grow)C++17
0 / 100
1097 ms2900 KiB
//Proud of You// #include <bits/stdc++.h> #pragma GCC optimization ("O3") #pragma GCC optimization ("unroll-loops") using namespace std; const int N = 1e5 + 17; int n, m, a[N], st[4 * N], lz[4 * N]; inline void build (int id, int l, int r) { if (l == r) { st[id] = a[l]; return; } int mid = l + r >> 1; build (id * 2, l, mid); build (id * 2 + 1, mid + 1, r); st[id] = max (st[id * 2], st[id * 2 + 1]); } inline void down (int id) { st[id * 2] += lz[id]; lz[id * 2] += lz[id]; st[id * 2 + 1] += lz[id]; lz[id * 2 + 1] += lz[id]; lz[id] = 0; } inline void update (int id, int l, int r, int u, int v) { if (v < l || r < u) { return; } if (u <= l && r <= v) { ++lz[id], ++st[id]; return; } int mid = l + r >> 1; down(id); update (id * 2, l, mid, u, v); update (id * 2 + 1, mid + 1, r, u, v); st[id] = max (st[id * 2], st[id * 2 + 1]); } inline int get (int id, int l, int r, int u) { if (u < l || r < u) { return 0; } if (l == r) { return st[id]; } int mid = l + r >> 1; down(id); return get (id * 2, l, mid, u) + get (id * 2 + 1, mid + 1, r, u); } inline int walk (int id, int l, int r, int z) { if (st[id] < z) { return n + 1; } if (l == r) { return l; } int mid = l + r >> 1; down(id); return min (walk (id * 2, l, mid, z), walk (id * 2 + 1, mid + 1, r, z)); } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n >> m; for (int i = 1; i <= n; i++) { cin >> a[i]; } sort (a + 1, a + n + 1); build (1, 1, n); while (m--) { char t; int x, y; cin >> t >> x >> y; if (t == 'F') { int i = walk (1, 1, n, y), j = walk (1, 1, n, y + 1); if (j - i > x) { update (1, 1, n, j - x, j - 1); continue; } if (n - i + 1 <= x) { update (1, 1, n, i, n); continue; } int l = get (1, 1, n, i), r = get (1, 1, n, n); while (l < r) { int mid = l + r + 1 >> 1; if (walk (1, 1, n, mid + 1) - i <= x) { l = mid; continue; } r = mid - 1; } j = walk (1, 1, n, l + 1), x -= j - i; update (1, 1, n, i, j - 1); i = get (1, 1, n, j), j = walk (1, 1, n, i + 1); update (1, 1, n, j - x, j - 1); } else { int l = walk (1, 1, n, x); int r = walk (1, 1, n, y + 1); cout << r - l << "\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...