0
1
mirror of https://git.sb/baoshuo/OI-codes.git synced 2024-11-27 13:16:26 +00:00

I - Incoming Asteroids

https://codeforces.com/gym/102452/submission/179196387
This commit is contained in:
Baoshuo Ren 2022-11-04 22:09:53 +08:00
parent 81ca5cbf37
commit eeb0d03fa3
Signed by: baoshuo
GPG Key ID: 00CB9680AB29F51A

View File

@ -1,7 +1,6 @@
#include <iostream> #include <iostream>
#include <cmath> #include <cmath>
#include <functional> #include <functional>
#include <queue>
#include <set> #include <set>
#include <utility> #include <utility>
#include <vector> #include <vector>
@ -14,12 +13,8 @@ const int N = 2e5 + 5;
int n, m, lst, cnt; int n, m, lst, cnt;
long long a[N], b[N]; long long a[N], b[N];
std::priority_queue< std::set<std::pair<long long, int>> q[N];
std::pair<long long, int>, std::vector<std::pair<int, std::set<std::pair<long long, int>>::iterator>> ids[N];
std::vector<std::pair<long long, int>>,
std::greater<std::pair<long long, int>>>
q[N];
std::vector<int> ids[N];
int main() { int main() {
std::ios::sync_with_stdio(false); std::ios::sync_with_stdio(false);
@ -43,9 +38,9 @@ int main() {
for (int i = 1, x; i <= k; i++) { for (int i = 1, x; i <= k; i++) {
cin >> x; cin >> x;
ids[cnt].emplace_back(x ^= lst); x ^= lst;
ids[cnt].emplace_back(x, q[x].emplace(b[x] + v, cnt).first);
a[cnt] += b[x]; a[cnt] += b[x];
q[x].emplace(b[x] + v, cnt);
} }
} else { // op == 2 } else { // op == 2
int x, y; int x, y;
@ -55,25 +50,23 @@ int main() {
b[x ^= lst] += y ^= lst; b[x ^= lst] += y ^= lst;
while (!q[x].empty() && q[x].top().first <= b[x]) { while (!q[x].empty() && q[x].begin()->first <= b[x]) {
int id = q[x].top().second; int id = q[x].begin()->second;
q[x].pop();
if (!a[id]) continue;
long long rest = a[id]; long long rest = a[id];
for (int p : ids[id]) { for (auto o : ids[id]) {
rest -= b[p]; rest -= b[o.first];
q[o.first].erase(o.second);
} }
if (rest <= 0) { if (rest <= 0) {
ans.emplace(id); ans.emplace(id);
a[id] = 0; ids[id].clear();
} else { } else {
int v = std::ceil(static_cast<double>(rest) / ids[id].size()); int v = std::ceil(static_cast<double>(rest) / ids[id].size());
for (int p : ids[id]) { for (auto &o : ids[id]) {
q[p].emplace(b[p] + v, id); o.second = q[o.first].emplace(b[o.first] + v, id).first;
} }
} }
} }