标签:pre first return += oid color date src continue
const int N = 100005; int n, m, q, flag, cnt; int Min[4 * N], d[N]; void Pushup(int root) { Min[root] = min(Min[lson], Min[rson]); } void Build(int l, int r, int root) { if (l == r) { sc(Min[root]); return; } int mid = (l + r) >> 1; Build(l, mid, lson); Build(mid + 1, r, rson); Pushup(root); } void Update(int l, int r, int root, int x) { if (Min[root] > x) return; if (l == r) { flag = Min[root]; Min[root] = INF32; cnt++; return; } int mid = (l + r) >> 1; if (Min[lson] > x) Update(mid + 1, r, rson, x); if (Min[lson] <= x) Update(l, mid, lson, x); Pushup(root); } P ans[N]; int main() { sc(n), sc(m); Build(1, n, 1); sc(q); Rep(i, 1, q) sc(d[i]); int tp = 0; Rep(i, 1, q) { if (Min[1] == INF32) { ans[i].first = cnt; ans[i].second = tp; continue; } tp += m; while(1) { flag = 0; Update(1, n, 1, tp); if (!flag) break; tp -= flag; } ans[i].first = cnt; ans[i].second = tp; } Rep(i, 1, q) printf("%d %d\n", ans[d[i]].first, ans[d[i]].second); return 0; }
Lpl and Energy-saving Lamps - 计蒜客
标签:pre first return += oid color date src continue
原文地址:https://www.cnblogs.com/zgglj-com/p/9572226.html