From 81ca5cbf37b34dc8bf659d1dbeded7cf4da32f51 Mon Sep 17 00:00:00 2001 From: Baoshuo Date: Fri, 4 Nov 2022 21:52:19 +0800 Subject: [PATCH] I - Incoming Asteroids https://codeforces.com/gym/102452/submission/179188452 --- Gym/102452/I/I.cpp | 88 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 88 insertions(+) create mode 100644 Gym/102452/I/I.cpp diff --git a/Gym/102452/I/I.cpp b/Gym/102452/I/I.cpp new file mode 100644 index 00000000..92ed0755 --- /dev/null +++ b/Gym/102452/I/I.cpp @@ -0,0 +1,88 @@ +#include +#include +#include +#include +#include +#include +#include + +using std::cin; +using std::cout; +const char endl = '\n'; + +const int N = 2e5 + 5; + +int n, m, lst, cnt; +long long a[N], b[N]; +std::priority_queue< + std::pair, + std::vector>, + std::greater>> + q[N]; +std::vector ids[N]; + +int main() { + std::ios::sync_with_stdio(false); + cin.tie(nullptr); + + cin >> n >> m; + + while (m--) { + int op; + + cin >> op; + + if (op == 1) { + int y, k; + + cin >> y >> k; + + a[++cnt] = y ^= lst; + int v = std::ceil(static_cast(y) / k); + + for (int i = 1, x; i <= k; i++) { + cin >> x; + + ids[cnt].emplace_back(x ^= lst); + a[cnt] += b[x]; + q[x].emplace(b[x] + v, cnt); + } + } else { // op == 2 + int x, y; + std::set ans; + + cin >> x >> y; + + b[x ^= lst] += y ^= lst; + + while (!q[x].empty() && q[x].top().first <= b[x]) { + int id = q[x].top().second; + q[x].pop(); + + if (!a[id]) continue; + + long long rest = a[id]; + for (int p : ids[id]) { + rest -= b[p]; + } + + if (rest <= 0) { + ans.emplace(id); + a[id] = 0; + } else { + int v = std::ceil(static_cast(rest) / ids[id].size()); + + for (int p : ids[id]) { + q[p].emplace(b[p] + v, id); + } + } + } + + cout << (lst = ans.size()); + for (int x : ans) cout << ' ' << x; + cout << endl; + } + } + + return 0; +}