Submission #563564

#TimeUsernameProblemLanguageResultExecution timeMemory
563564hoanghq2004Sweeping (JOI20_sweeping)C++14
64 / 100
5423 ms520680 KiB
#include <bits/stdc++.h> #pragma GCC optimize ("O3") #pragma GCC optimize ("unroll-loops") #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace __gnu_pbds; using namespace std; template <typename T> using ordered_set = tree <T, null_type, less <T>, rb_tree_tag, tree_order_statistics_node_update>; const int N = 1e6 + 10; int n, m, q; int X[N], Y[N]; pair <int, int> P[N]; int block[N]; map <int, int> range; ordered_set <pair <int, int> > bX[N], bY[N]; void add(int i, int b) { int _b = block[i]; bX[_b].erase({P[i].first, i}); bY[_b].erase({P[i].second, i}); block[i] = b; bX[b].insert({P[i].first, i}); bY[b].insert({P[i].second, i}); } int main() { ios :: sync_with_stdio(0); cin.tie(0); cin >> m >> n >> q; for (int i = 1; i <= n; ++i) { int x, y; cin >> x >> y; P[i] = {x, y}; bX[0].insert({x, i}); bY[0].insert({y, i}); } range[0] = 0; for (int i = 1; i <= q; ++i) { int cmd; cin >> cmd; if (cmd == 1) { int id; cin >> id; cout << max(P[id].first, X[block[id]]) << ' ' << max(P[id].second, Y[block[id]]) << '\n'; } else if (cmd == 2) { int L; cin >> L; if (range.find(m - L) == range.end()) { int j = (--range.lower_bound(m - L)) -> second; range[m - L] = i; X[i] = m - L, Y[i] = Y[j], Y[j] = L + 1; if (bY[j].order_of_key({L + 1, 0}) <= bY[j].size() / 2) { while (bY[j].size() && bY[j].begin() -> first <= L) { add(bY[j].begin() -> second, i); } } else { while (bY[j].size() && (--bY[j].end()) -> first > L) { add((--bY[j].end()) -> second, i); } swap(X[i], X[j]), swap(Y[i], Y[j]), swap(range[X[i]], range[X[j]]); } } } else if (cmd == 3) { int L; cin >> L; if (range.find(L + 1) == range.end()) { int j = (--range.lower_bound(L + 1)) -> second; range[L + 1] = i; X[i] = L + 1, Y[i] = Y[j], Y[j] = m - L; if (bX[j].order_of_key({L + 1, 0}) <= bX[j].size() / 2) { while (bX[j].size() && bX[j].begin() -> first <= L) { add(bX[j].begin() -> second, i); } swap(X[i], X[j]), swap(Y[i], Y[j]), swap(range[X[i]], range[X[j]]); } else { while (bX[j].size() && (--bX[j].end()) -> first > L) { add((--bX[j].end()) -> second, i); } } } } else { assert(0); } } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...