Submission #75660

#TimeUsernameProblemLanguageResultExecution timeMemory
75660tmwilliamlin168Circle selection (APIO18_circle_selection)C++14
87 / 100
3043 ms253684 KiB
#include <bits/stdc++.h> using namespace std; #define ll long long const int mxN=3e5; int n, p[mxN], p2[mxN], a[mxN]; ll x[mxN], y[mxN], r[mxN]; unordered_map<int, vector<array<int, 2>>> mp; void rs(int k) { mp.clear(); for(int i=0; i<n; ++i) if(a[p2[i]]==-1) mp[x[p2[i]]>>k].push_back({y[p2[i]]>>k, p2[i]}); } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cin >> n; for(int i=0; i<n; ++i) { cin >> x[i] >> y[i] >> r[i]; p[i]=p2[i]=i; } sort(p, p+n, [&](const int &a, const int &b) { return r[a]==r[b]?a<b:r[a]>r[b]; }); sort(p2, p2+n, [&](const int &a, const int &b) { return y[a]<y[b]; }); memset(a, -1, 4*n); for(int i=-1, k=30; i+1<n; --i, --k) { rs(k); while(++i<n&&r[p[i]]>=1<<(k-1)) { if(a[p[i]]!=-1) continue; for(ll b=(x[p[i]]>>k)-2; b<=(x[p[i]]>>k)+2; ++b) { auto mf=mp.find(b); if(mf==mp.end()) continue; vector<array<int, 2>> &v=mf->second; for(int j=lower_bound(v.begin(), v.end(), array<int, 2>{(y[p[i]]>>k)-2, 0})-v.begin(); j<v.size()&&v[j][0]<=(y[p[i]]>>k)+2; ++j) { ll dx=x[p[i]]-x[v[j][1]], dy=y[p[i]]-y[v[j][1]], rs=r[p[i]]+r[v[j][1]]; if(dx*dx+dy*dy<=rs*rs&&a[v[j][1]]==-1) a[v[j][1]]=p[i]; } } } } for(int i=0; i<n; ++i) cout << a[i]+1 << " "; }

Compilation message (stderr)

circle_selection.cpp: In function 'void rs(int)':
circle_selection.cpp:15:39: warning: narrowing conversion of '(y[p2[i]] >> k)' from 'long long int' to 'int' inside { } [-Wnarrowing]
    mp[x[p2[i]]>>k].push_back({y[p2[i]]>>k, p2[i]});
                               ~~~~~~~~^~~
circle_selection.cpp: In function 'int main()':
circle_selection.cpp:44:73: warning: narrowing conversion of '((y[p[i]] >> k) - 2)' from 'long long int' to 'int' inside { } [-Wnarrowing]
     for(int j=lower_bound(v.begin(), v.end(), array<int, 2>{(y[p[i]]>>k)-2, 0})-v.begin(); j<v.size()&&v[j][0]<=(y[p[i]]>>k)+2; ++j) {
                                                             ~~~~~~~~~~~~^~
circle_selection.cpp:44:93: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int j=lower_bound(v.begin(), v.end(), array<int, 2>{(y[p[i]]>>k)-2, 0})-v.begin(); j<v.size()&&v[j][0]<=(y[p[i]]>>k)+2; ++j) {
                                                                                            ~^~~~~~~~~
#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...