Submission #397486

#TimeUsernameProblemLanguageResultExecution timeMemory
397486parsabahrami원 고르기 (APIO18_circle_selection)C++14
87 / 100
3099 ms340956 KiB
/* There's someone in my head but it's not me */ #include <bits/stdc++.h> #pragma comment(linker, "/stack:200000000") #pragma GCC optimize("Ofast") #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx") using namespace std; typedef long long int ll; typedef pair<int, int> pii; #define SZ(x) (int) x.size() #define F first #define S second #define lc id << 1 #define rc lc | 1 const int N = 3e5 + 4, MOD = 1e9 + 7; int n, X[N], Y[N], R[N], ord[N], xord[N], pos[N], ret[N]; ll base[N]; set<pii> seg[N << 2]; int intersect(int i, int j) { return (base[i] + base[j] + 2ll * (1ll * X[i] * X[j] + 1ll * Y[i] * Y[j] + 1ll * R[i] * R[j])) >= 0; } void build(int id = 1, int l = 1, int r = n + 1) { for (int i = l; i < r; i++) { seg[id].insert({Y[xord[i]], xord[i]}); } if (r - l < 2) return; int md = (l + r) >> 1; build(lc, l, md), build(rc, md, r); } void get(ll xl, ll xr, ll yl, ll yr, int &p, int id = 1, int l = 1, int r = n + 1) { if (xr <= X[xord[l]] || X[xord[r - 1]] + 1 <= xl || seg[id].empty()) return; if (xl <= X[xord[l]] && X[xord[r - 1]] + 1 <= xr) { for (auto it = seg[id].lower_bound({yl, -1e9}); it != seg[id].end() && it->F <= yr; ) { auto x = *it; if (ret[x.S]) seg[id].erase(x); else if (intersect(p, x.S)) ret[x.S] = p; it = seg[id].upper_bound(x); } return; } int md = (l + r) >> 1; get(xl, xr, yl, yr, p, lc, l, md), get(xl, xr, yl, yr, p, rc, md, r); } int main() { scanf("%d", &n); for (int i = 1; i <= n; i++) scanf("%d%d%d", &X[i], &Y[i], &R[i]), base[i] = 1ll * R[i] * R[i] - 1ll * X[i] * X[i] - 1ll * Y[i] * Y[i]; iota(ord + 1, ord + n + 1, 1); iota(xord + 1, xord + n + 1, 1); sort(ord + 1, ord + n + 1, [&] (int i, int j) { return R[i] == R[j] ? i < j : R[i] > R[j]; }); sort(xord + 1, xord + n + 1, [&] (int i, int j) { return X[i] < X[j]; }); build(); for (int i = 1; i <= n; i++) pos[xord[i]] = i; for (int _ = 1; _ <= n; _++) { int i = ord[_]; if (ret[i]) continue; get(X[i] - 2ll * R[i], X[i] + 2ll * R[i] + 1, Y[i] - 2ll * R[i], Y[i] + 2ll * R[i], i); } for (int i = 1; i <= n; i++) printf("%d ", ret[i]); printf("\n"); return 0; }

Compilation message (stderr)

circle_selection.cpp:3: warning: ignoring #pragma comment  [-Wunknown-pragmas]
    3 | #pragma comment(linker, "/stack:200000000")
      | 
circle_selection.cpp: In function 'int main()':
circle_selection.cpp:51:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   51 |     scanf("%d", &n);
      |     ~~~~~^~~~~~~~~~
circle_selection.cpp:53:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   53 |         scanf("%d%d%d", &X[i], &Y[i], &R[i]), base[i] = 1ll * R[i] * R[i] - 1ll * X[i] * X[i] - 1ll * Y[i] * Y[i];
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#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...