text: We produce up to 1 thimble a day currently and will produce up to 2 thimbles a day after repairs.Repairs take 2 days.For the first question, we are able to fill 1 order on day 1, no orders on days 2 and 3 since we are repairing, no orders on day 4 since no thimbles have been ordered for that day, and 2 orders for day 5 since we are limited to our production capacity, for a total of 3 orders filled.For the third question, we are able to fill 1 order on day 1, 1 order on day 2, and 2 orders on day 5, for a total of 4 orders.# Solution #include <bits/stdc++.h> using namespace std; long long tree[1000000][2]; long long ar[1000000]; int a, b; long long query(int x, int l, int r, int s, int e, bool k) { if (l > e || r < s || s > e) return 0; if (l >= s && r <= e) return tree[x][k]; else { return query(x * 2, l, (l + r) / 2, s, e, k) + query(x * 2 + 1, (l + r) / 2 + 1, r, s, e, k); } } void upd(int x, int l, int r, int v) { if (v > r || v < l) return; if (l == r && v == l) { tree[x][0] = min(ar[v], b + 0LL); tree[x][1] = min(ar[v], a + 0LL); } else { upd(x * 2, l, (l + r) / 2, v); upd(x * 2 + 1, (l + r) / 2 + 1, r, v); tree[x][0] = tree[x * 2][0] + tree[x * 2 + 1][0]; tree[x][1] = tree[x * 2][1] + tree[x * 2 + 1][1]; } } int main() { int n, k, q; cin >> n >> k >> a >> b >> q; while (q--) { int typ; scanf("%d", &typ); if (typ == 1) { int d, x; scanf("%d%d", &d, &x); ar[d] += x; upd(1, 1, n, d); } else { int p; scanf("%d", &p); printf("%I64d\n", query(1, 1, n, 1, p - 1, 0) + query(1, 1, n, p + k, n, 1)); } } }