diff --git a/Gym/102452/I/I.cpp b/Gym/102452/I/I.cpp index 92ed0755..0c8bffe5 100644 --- a/Gym/102452/I/I.cpp +++ b/Gym/102452/I/I.cpp @@ -1,7 +1,6 @@ #include #include #include -#include #include #include #include @@ -14,12 +13,8 @@ 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]; +std::set> q[N]; +std::vector>::iterator>> ids[N]; int main() { std::ios::sync_with_stdio(false); @@ -43,9 +38,9 @@ int main() { for (int i = 1, x; i <= k; i++) { 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]; - q[x].emplace(b[x] + v, cnt); } } else { // op == 2 int x, y; @@ -55,25 +50,23 @@ int main() { 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; + while (!q[x].empty() && q[x].begin()->first <= b[x]) { + int id = q[x].begin()->second; long long rest = a[id]; - for (int p : ids[id]) { - rest -= b[p]; + for (auto o : ids[id]) { + rest -= b[o.first]; + q[o.first].erase(o.second); } if (rest <= 0) { ans.emplace(id); - a[id] = 0; + ids[id].clear(); } else { int v = std::ceil(static_cast(rest) / ids[id].size()); - for (int p : ids[id]) { - q[p].emplace(b[p] + v, id); + for (auto &o : ids[id]) { + o.second = q[o.first].emplace(b[o.first] + v, id).first; } } }