Submission #499271

#TimeUsernameProblemLanguageResultExecution timeMemory
499271_martynasCircle selection (APIO18_circle_selection)C++14
87 / 100
3080 ms656396 KiB
#include <bits/stdc++.h> using namespace std; using namespace std::chrono; using ll = long long; const ll MOD = 1e9+7; const int MAX_N = 3e5+5; int n; ll X[MAX_N], Y[MAX_N], R[MAX_N]; int P[MAX_N]; bool visited[MAX_N]; int Inh[MAX_N]; struct LLNode { int idx; LLNode* next = nullptr; LLNode() { } LLNode(int val) : idx(val) { } } LLNodes[MAX_N]; int llcounter = 0; inline LLNode* getLLNode() { return &LLNodes[llcounter++]; } int dup; struct Quad { ll l, r, bot, top; array<Quad*, 4> childs = {}; LLNode* llnode = nullptr; int sz; Quad() { } Quad(ll _l, ll _r, ll _bot, ll _top) : l(_l), r(_r), bot(_bot), top(_top) { sz = 0; } void add(ll x, ll y, int idx) { if(x < l || x > r || y < bot || y > top) { return; } sz++; // cerr << "l = " << l << ", r = " << r << ", " // << "bot = " << bot << ", top = " << top << "\n"; if(l == r && bot == top) { if(llnode == nullptr) { llnode = getLLNode(); llnode->idx = idx; } else { dup++; LLNode* temp = getLLNode(); temp->idx = idx; temp->next = llnode; llnode = temp; } } else { ll midH, midV; midH = l+(r-l)/2; midV = bot+(top-bot)/2; if(l != r && top != bot) { if(childs[0] == nullptr && !(x < l || x > midH || y < bot || y > midV)) { childs[0] = new Quad(l, midH, bot, midV); } else if(childs[1] == nullptr && !(x < midH+1 || x > r || y < bot || y > midV)) { childs[1] = new Quad(midH+1, r, bot, midV); } else if(childs[2] == nullptr && !(x < l || x > midH || y < midV+1 || y > top)) { childs[2] = new Quad(l, midH, midV+1, top); } else if(childs[3] == nullptr && !(x < midH+1 || x > r || y < midV+1 || y > top)) { childs[3] = new Quad(midH+1, r, midV+1, top); } } else if(l != r) { if(childs[0] == nullptr && !(x < l || x > midH || y < bot || y > top)) { childs[0] = new Quad(l, midH, bot, midV); } else if(childs[1] == nullptr && !(x < midH+1 || x > r || y < bot || y > top)) { childs[1] = new Quad(midH+1, r, bot, top); } } else if(top != bot) { if(childs[0] == nullptr && !(x < l || x > r || y < bot || y > midV)) { childs[0] = new Quad(l, r, bot, midV); } else if(childs[1] == nullptr && !(x < l || x > r || y < midV+1 || y > top)) { childs[1] = new Quad(l, r, midV+1, top); } } for(int k = 0; k < 4; k++) { if(childs[k] != nullptr) { childs[k]->add(x, y, idx); } } } } void setInRange(ll x, ll y, ll radius, int idx) { if(x+2*radius < l || x-2*radius > r || y+2*radius < bot || y-2*radius > top || sz == 0) { return; } // cerr << "l = " << l << ", r = " << r << ", " // << "bot = " << bot << ", top = " << top << "\n"; if(l == r && bot == top) { while(llnode != nullptr && (R[idx]+R[llnode->idx])*(R[idx]+R[llnode->idx]) >= llabs(X[idx]-X[llnode->idx])*llabs(X[idx]-X[llnode->idx]) +llabs(Y[idx]-Y[llnode->idx])*llabs(Y[idx]-Y[llnode->idx])) { P[llnode->idx] = idx; visited[llnode->idx] = true; sz--; llnode = llnode->next; } return; } int cnt = 0; for(int k = 0; k < 4; k++) { if(childs[k] != nullptr) { childs[k]->setInRange(x, y, radius, idx); cnt += childs[k]->sz; } } sz = cnt; } }; Quad Q(-1000000000, 1000000000, -1000000000, 1000000000); int main() { auto stop = steady_clock::now(); cin >> n; for(int i = 0; i < n; i++) { cin >> X[i] >> Y[i] >> R[i]; } iota(P, P+n, 0); // cerr << "Exec: " << duration_cast<milliseconds>(steady_clock::now()-stop).count() << " ms\n"; vector<int> I(n); iota(I.begin(), I.end(), 0); sort(I.begin(), I.end(), [&](int a, int b) { return R[a] > R[b] || (R[a] == R[b] && a < b); }); for(int i = n-1; i >= 0; i--) { int idx = I[i]; //cerr << i << " started\n"; Q.add(X[idx], Y[idx], idx); //cerr << i << " finished\n"; } for(int i = 0; i < n; i++) { int idx = I[i]; if(visited[idx]) continue; Q.setInRange(X[idx], Y[idx], R[idx], idx); } for(int i = 0; i < n; i++) { cout << 1+P[i] << " "; } cout << "\n"; // cerr << "Dupe: " << dup << "\n"; // cerr << "Exec: " << duration_cast<milliseconds>(steady_clock::now()-stop).count() << " ms\n"; return 0; } /* 11 9 9 2 13 2 1 11 8 2 3 3 2 3 12 1 12 14 1 9 8 5 2 8 2 5 2 1 14 4 2 14 14 1 */

Compilation message (stderr)

circle_selection.cpp: In function 'int main()':
circle_selection.cpp:159:10: warning: variable 'stop' set but not used [-Wunused-but-set-variable]
  159 |     auto stop = steady_clock::now();
      |          ^~~~
#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...