Submission #410262

#TimeUsernameProblemLanguageResultExecution timeMemory
410262jhwest2IOI Fever (JOI21_fever)C++14
6 / 100
1 ms332 KiB
#include <bits/stdc++.h> #define va first #define vb second using namespace std; typedef long long lint; typedef pair<int, int> pint; typedef pair<lint, lint> plint; const int MAX = 1e5 + 10; int n; pint A[MAX]; set<pair<pint, int>> X[4], Y[4], Z[4], W[4]; int get_dir(int x) { if (x == 1) return 2; int a = (A[x].vb - A[x].va >= A[1].vb - A[1].va); int b = (A[x].vb + A[x].va <= A[1].vb + A[1].va); if (!a && b) return 3; return a + b; } int main() { cin.tie(0); ios_base::sync_with_stdio(0); cin >> n; for (int i = 1; i <= n; i++) cin >> A[i].va >> A[i].vb, A[i].va *= 2, A[i].vb *= 2; for (int i = n; i >= 1; i--) A[i].va -= A[1].va, A[i].vb -= A[1].vb; int ans = 0; for (int d = 0; d < 4; d++) { int k = 0; for (int i = 2; i <= n; i++) { X[get_dir(i)].insert({ {A[i].vb, A[i].va}, i }); Y[get_dir(i)].insert({ {A[i].va, A[i].vb}, i }); Z[get_dir(i)].insert({ {A[i].va - A[i].vb, A[i].va}, i }); W[get_dir(i)].insert({ {A[i].va + A[i].vb, A[i].va}, i }); } priority_queue<pint, vector<pint>, greater<pint>> V; V.emplace(0, 1); while (!V.empty()) { int x = V.top().vb, r = V.top().va; V.pop(); int dir = get_dir(x); ++k; pair<pint, int> a, b, c; if (dir & 1) a = { {A[x].va, A[x].vb + (2 - (dir + 2) % 4) * r}, 0 }; else a = { {A[x].vb, A[x].va + (1 - (dir + 2) % 4) * r}, 0 }; b = { {A[x].va - A[x].vb, A[x].va + (1 - (dir + 2) % 4 / 2 * 2) * r}, 0 }; c = { {A[x].va + A[x].vb, A[x].va + (1 - (1 + (dir + 2) % 4) % 4 / 2) * r}, 0 }; vector<int> Upd; if (dir == 2) { for (auto it = X[0].lower_bound(a); it != X[0].end() && it->va.va == A[x].vb; it = next(it)) Upd.push_back(it->vb); } if (dir == 3) { for (auto it = Y[1].lower_bound(a); it != Y[1].end() && it->va.va == A[x].va; it = next(it)) Upd.push_back(it->vb); } if (dir == 0) { for (auto it = X[2].lower_bound(a); it != X[2].begin() && prev(it)->va.va == A[x].vb; it = prev(it)) Upd.push_back(prev(it)->vb); } if (dir == 1) { for (auto it = Y[3].lower_bound(a); it != Y[3].begin() && prev(it)->va.va == A[x].va; it = prev(it)) Upd.push_back(prev(it)->vb); } if (dir > 1) { for (auto it = Z[(7 - dir) % 4].lower_bound(b); it != Z[(7 - dir) % 4].end() && it->va.va == A[x].va - A[x].vb; it = next(it)) Upd.push_back(it->vb); } else { for (auto it = Z[(7 - dir) % 4].lower_bound(b); it != Z[(7 - dir) % 4].begin() && prev(it)->va.va == A[x].va - A[x].vb; it = prev(it)) Upd.push_back(prev(it)->vb); } if ((1 + dir) % 4 > 1) { for (auto it = W[(5 - dir) % 4].lower_bound(c); it != W[(5 - dir) % 4].end() && it->va.va == A[x].va + A[x].vb; it = next(it)) Upd.push_back(it->vb); } else { for (auto it = W[(5 - dir) % 4].lower_bound(c); it != W[(5 - dir) % 4].begin() && prev(it)->va.va == A[x].va + A[x].vb; it = prev(it)) Upd.push_back(prev(it)->vb); } for (int k : Upd) { int z = A[k].va, y = A[k].vb; for (int i = 0; i < 4; i++) { X[i].erase({ {y, z}, k }); Y[i].erase({ {z, y}, k }); Z[i].erase({ {z - y, z}, k }); W[i].erase({ {z + y, z}, k }); } if (A[x].va == A[k].va) V.emplace(abs(A[k].vb - A[x].vb) / 2, k); else if (A[x].vb == A[k].vb) V.emplace(abs(A[k].va - A[x].va) / 2, k); else V.emplace(abs(A[k].va - A[x].va), k); } } ans = max(ans, k); for (int i = 1; i <= n; i++) { swap(A[i].va, A[i].vb); A[i].va = -A[i].va; } for (int i = 0; i < 4; i++) { X[i].clear(); Y[i].clear(); Z[i].clear(); W[i].clear(); } } cout << ans; }
#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...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...