# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
257633 | 2020-08-04T13:47:14 Z | Bruteforceman | 청소 (JOI20_sweeping) | C++11 | 18000 ms | 293296 KB |
#include <bits/stdc++.h> using namespace std; const int maxm = 1.5e6 + 10; int X[maxm], Y[maxm]; pair <int, int> ans[maxm]; int n; struct info { int t, p, q; int idx; info () {} }; info index(int i) { info x; x.t = 4; x.idx = i; return x; } struct ds { map <int, vector <int>> coord; map <int, int> value, par; ds () {} int root(int x) { if(par.find(x) == par.end() || par[x] == x) return x; return par[x] = root(par[x]); } void joinIdx(int x, int y) { x = root(x); y = root(y); if(x != y) { par[y] = x; } } void add(int pos, int idx) { coord[pos].push_back(idx); value[idx] = pos; int parent = root(coord[pos].front()); par[idx] = parent; } void join(int x, int y) { if(x == y || coord[y].empty()) return ; if(coord[x].size()) { joinIdx(coord[x].front(), coord[y].front()); } if(coord[x].size() < coord[y].size()) { coord[x].swap(coord[y]); } for(int i : coord[y]) { coord[x].push_back(i); } value[root(coord[x].front())] = x; coord.erase(y); } int getPos(int idx) { return value[root(idx)]; } vector <int> getIndex(int pos) { vector <int> ans; vector <int> del; for(auto i : coord) { if(i.first <= pos) { for(auto j : i.second) ans.push_back(j); del.push_back(i.first); } } for(auto i : del) { coord.erase(i); } return ans; } void move(int pos) { vector <int> del; for(auto i : coord) { if(i.first <= pos) { del.push_back(i.first); } } for(auto i : del) { join(pos, i); } } }; void solve(int xa, int ya, vector <info> &v) { if(v.empty()) return ; int midX = (xa + n - ya) / 2; int midY = n - midX; vector <info> left, right; map <int, int> side; ds contX, contY; for(auto i : v) { if(i.t == 1) { if(side.find(i.p) == side.end()) { ans[i.idx] = make_pair(contX.getPos(i.p), contY.getPos(i.p)); } else { if(side[i.p]) right.push_back(i); else left.push_back(i); } } else if (i.t == 2) { if(i.p < midY) { auto u = contY.getIndex(i.p); for(auto j : u) { if(side.find(j) != side.end()) continue; X[j] = n - i.p; Y[j] = contY.getPos(j); right.push_back(index(j)); side[j] = 1; } right.push_back(i); } else { contX.move(n - i.p); left.push_back(i); } } else if (i.t == 3) { if(i.p < midX) { auto u = contX.getIndex(i.p); for(auto j : u) { if(side.find(j) != side.end()) continue; X[j] = contX.getPos(j); Y[j] = n - i.p; left.push_back(index(j)); side[j] = 0; } left.push_back(i); } else { contY.move(n - i.p); right.push_back(i); } } else { if(X[i.idx] <= midX && Y[i.idx] <= midY) { contX.add(X[i.idx], i.idx); contY.add(Y[i.idx], i.idx); } else if (midX < X[i.idx]) { side[i.idx] = 1; right.push_back(i); } else { side[i.idx] = 0; left.push_back(i); } } } v.clear(); if(ya <= midY + 1 && midY + 1 <= n - xa) { solve(xa, midY + 1, left); } if(xa <= midX + 1 && midX + 1 <= n - ya) { solve(midX + 1, ya, right); } } int main() { int m, q; scanf("%d %d %d", &n, &m, &q); vector <info> v; for(int i = 1; i <= m; i++) { info add; add.t = 4; add.idx = i; scanf("%d %d", &X[i], &Y[i]); v.push_back(add); } for(int i = 1; i <= q; i++) { info add; scanf("%d", &add.t); if(add.t == 1) { scanf("%d", &add.p); add.idx = i; } else if (add.t == 2) scanf("%d", &add.p); else if (add.t == 3) scanf("%d", &add.p); else { add.idx = ++m; scanf("%d %d", &X[m], &Y[m]); } v.push_back(add); } auto u = v; solve(0, 0, u); for(auto i : v) { if(i.t == 1) printf("%d %d\n", ans[i.idx].first, ans[i.idx].second); } return 0; }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 41 ms | 2048 KB | Output is correct |
2 | Correct | 19 ms | 1172 KB | Output is correct |
3 | Correct | 12 ms | 2048 KB | Output is correct |
4 | Correct | 37 ms | 2176 KB | Output is correct |
5 | Correct | 38 ms | 2432 KB | Output is correct |
6 | Correct | 11 ms | 1664 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 15289 ms | 199152 KB | Output is correct |
2 | Correct | 14886 ms | 199296 KB | Output is correct |
3 | Correct | 15551 ms | 199344 KB | Output is correct |
4 | Execution timed out | 18083 ms | 169528 KB | Time limit exceeded |
5 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 13907 ms | 280328 KB | Output is correct |
2 | Correct | 14685 ms | 293296 KB | Output is correct |
3 | Execution timed out | 18024 ms | 168732 KB | Time limit exceeded |
4 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 13907 ms | 280328 KB | Output is correct |
2 | Correct | 14685 ms | 293296 KB | Output is correct |
3 | Execution timed out | 18024 ms | 168732 KB | Time limit exceeded |
4 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 41 ms | 2048 KB | Output is correct |
2 | Correct | 19 ms | 1172 KB | Output is correct |
3 | Correct | 12 ms | 2048 KB | Output is correct |
4 | Correct | 37 ms | 2176 KB | Output is correct |
5 | Correct | 38 ms | 2432 KB | Output is correct |
6 | Correct | 11 ms | 1664 KB | Output is correct |
7 | Correct | 15289 ms | 199152 KB | Output is correct |
8 | Correct | 14886 ms | 199296 KB | Output is correct |
9 | Correct | 15551 ms | 199344 KB | Output is correct |
10 | Execution timed out | 18083 ms | 169528 KB | Time limit exceeded |
11 | Halted | 0 ms | 0 KB | - |