제출 #976456

#제출 시각아이디문제언어결과실행 시간메모리
976456LOLOLOGrowing Trees (BOI11_grow)C++17
0 / 100
91 ms9300 KiB
#include <bits/stdc++.h> #define ll long long using namespace std; #define f first #define s second #define pb push_back #define ep emplace #define eb emplace_back #define lb lower_bound #define ub upper_bound #define all(x) x.begin(), x.end() #define rall(x) x.rbegin(), x.rend() #define uniquev(v) sort(all(v)), (v).resize(unique(all(v)) - (v).begin()) #define mem(f,x) memset(f , x , sizeof(f)) #define sz(x) (int)(x).size() #define __lcm(a, b) (1ll * ((a) / __gcd((a), (b))) * (b)) #define mxx *max_element #define mnn *min_element #define cntbit(x) __builtin_popcountll(x) #define len(x) (int)(x.length()) const int N = 2e5 + 100; int a[N], seg[N * 4], laz[N * 4]; void push(int id) { int &t = laz[id]; laz[id * 2] += t; laz[id * 2 + 1] += t; seg[id * 2] += t; seg[id * 2 + 1] += t; t = 0; } void upd(int id, int l, int r, int u, int v, int c) { if (l > v || r < u || u > v) return; if (l >= u && r <= v) { seg[id] += c; laz[id] += c; return; } push(id); int m = (l + r) / 2; upd(id * 2, l, m, u, v, c); upd(id * 2 + 1, m + 1, r, u, v, c); seg[id] = max(seg[id * 2], seg[id * 2 + 1]); } int get(int id, int l, int r, int p) { if (l == r) return seg[id]; push(id); int m = (l + r) / 2; if (m >= p) return get(id * 2, l, m, p); return get(id * 2 + 1, m + 1, r, p); } int n; int find(int id, int l, int r, int k) { if (seg[id] < k) return n + 1; if (l == r) return l; int m = (l + r) / 2; push(id); if (seg[id * 2] >= k) return find(id * 2, l, m, k); return find(id * 2 + 1, m + 1, r, k); } int num(int l, int r) { return find(1, 1, n, r + 1) - find(1, 1, n, l); } int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); int m; cin >> n >> m; for (int i = 1; i <= n; i++) { cin >> a[i]; } sort(a + 1, a + 1 + n); for (int i = 1; i <= n; i++) { upd(1, 1, n, i, i, a[i]); } for (int i = 1; i <= m; i++) { char c; cin >> c; if (c == 'F') { int c, h; cin >> c >> h; int l = find(1, 1, n, h); if (l + c - 1 >= n) { upd(1, 1, n, l, n, 1); } else { int r = l + c - 1; int val = get(1, 1, n, r); int lst = find(1, 1, n, val + 1) - 1; int f = get(1, 1, n, val); upd(1, 1, n, l, f - 1, 1); int remain = (c - (f - l)); upd(1, 1, n, lst - remain + 1, lst, 1); } } else { int l, r; cin >> l >> r; cout << num(l, r) << '\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...