답안 #710105

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
710105 2023-03-15T04:42:16 Z lam 원 고르기 (APIO18_circle_selection) C++14
7 / 100
3000 ms 615160 KB
#include <bits/stdc++.h>
#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")
#define int long long
using namespace std;
const int maxn = 3e5 + 10;
typedef pair<int,int> ii;
typedef pair<ii,int> iii;
typedef pair<ii,ii> iiii;
#define ff first
#define ss second
inline int calc(ii x, ii y)
{
    return (x.ff-y.ff)*(x.ff-y.ff) + (x.ss-y.ss)*(x.ss-y.ss);
}
bool dau[maxn];
int res[maxn];
int n,m;
iii a[maxn];
int id[maxn];
iiii hcn[maxn];
multiset<ii> f[8*maxn];
vector <int> tmp;
bool cmp(int x, int y)
{
    if (a[x].ss!=a[y].ss) return a[x].ss>a[y].ss;
    return x<y;
}
void update(int x, int lx, int rx, int idx, ii val)
{
//    if (x==1)
//    {
////        cout<<"+ "<<idx<<' '<<val.ff<<','<<val.ss<<'\n';
//    }
    f[x].insert(val);
    if (lx==rx) return;
    int mid=(lx+rx)/2;
    if (idx<=mid) update(2*x,lx,mid,idx,val);
    else update(2*x+1,mid+1,rx,idx,val);
}
void xoa(int x, int lx, int rx, int idx, ii val)
{
    f[x].erase(f[x].find(val));
    if (lx==rx) return;
    int mid=(lx+rx)/2;
    if (idx<=mid) xoa(2*x,lx,mid,idx,val);
    else xoa(2*x+1,mid+1,rx,idx,val);
}
void qry(int x, int lx, int rx, int l, int r, int l2, int r2, int idx)
{
    if (lx>r||rx<l) return;
    if (lx>=l&&rx<=r)
    {
        ii temp = {l2,-1};
        auto j = f[x].lower_bound(temp);
        while (j!=f[x].end()&&(*j).ff <= r2)
        {
//            cerr<<l2<<" :: "<<r2<<" == "<<(*j).ff<<" , "<<(*j).ss<<endl;
            int v = (*j).ss; j++;
            if (!dau[v])
            {
                int val = calc(a[v].ff,a[idx].ff);
                int val2 = (a[v].ss+a[idx].ss); val2*=val2;
                if (val>val2) continue;
                dau[v] = 1;
                tmp.push_back(v);
            }
        }
        return;
    }
    int mid=(lx+rx)/2;
    qry(2*x,lx,mid,l,r,l2,r2,idx);
    qry(2*x+1,mid+1,rx,l,r,l2,r2,idx);
}
signed main()

{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr); cout.tie(nullptr);
    cin>>n;
    map<int,int> mp;
    for (int i=1; i<=n; i++)
    {
        cin>>a[i].ff.ff>>a[i].ff.ss>>a[i].ss;
        hcn[i] = {{a[i].ff.ff-a[i].ss,a[i].ff.ss-a[i].ss},{a[i].ff.ff+a[i].ss,a[i].ff.ss + a[i].ss}};
        mp[hcn[i].ff.ff] = 1;
        mp[hcn[i].ss.ff] = 1;
        dau[i]=0;
        id[i]=i;
    }
    m=0;
    for (auto &c:mp) c.ss = ++m;
    for (int i=1; i<=n; i++)
    {
        hcn[i].ff.ff = mp[hcn[i].ff.ff];
        hcn[i].ss.ff = mp[hcn[i].ss.ff];
//        cerr<<i<<" := "<<hcn[i].ff.ff<<" - "<<hcn[i].ss.ff<<" : "<<hcn[i].ff.ss<<' '<<hcn[i].ss.ss<<endl;
        update(1,1,m,hcn[i].ff.ff,{hcn[i].ff.ss,i});
        update(1,1,m,hcn[i].ff.ff,{hcn[i].ss.ss,i});
        update(1,1,m,hcn[i].ss.ff,{hcn[i].ff.ss,i});
        update(1,1,m,hcn[i].ss.ff,{hcn[i].ss.ss,i});
    }
    sort(id+1,id+n+1,cmp);
    for (int i=1; i<=n; i++)
    {
        int j=id[i];
        if (dau[j]) continue;
        tmp.clear();
        qry(1,1,m,hcn[j].ff.ff,hcn[j].ss.ff,hcn[j].ff.ss,hcn[j].ss.ss,j);
//        cerr<<j<<" !!"<<endl;
        for (int u:tmp)
        {
//            cerr<<u<<endl;
            res[u] = j;
            xoa(1,1,m,hcn[u].ff.ff,{hcn[u].ff.ss,u});
            xoa(1,1,m,hcn[u].ff.ff,{hcn[u].ss.ss,u});
            xoa(1,1,m,hcn[u].ss.ff,{hcn[u].ff.ss,u});
            xoa(1,1,m,hcn[u].ss.ff,{hcn[u].ss.ss,u});
        }
    }
    for (int i=1; i<=n; i++) cout<<res[i]<<' '; cout<<'\n';
}
/**
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

circle_selection.cpp: In function 'int main()':
circle_selection.cpp:121:5: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
  121 |     for (int i=1; i<=n; i++) cout<<res[i]<<' '; cout<<'\n';
      |     ^~~
circle_selection.cpp:121:49: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
  121 |     for (int i=1; i<=n; i++) cout<<res[i]<<' '; cout<<'\n';
      |                                                 ^~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 54 ms 112976 KB Output is correct
2 Correct 51 ms 112972 KB Output is correct
3 Correct 52 ms 113024 KB Output is correct
4 Correct 53 ms 113056 KB Output is correct
5 Correct 51 ms 112972 KB Output is correct
6 Correct 53 ms 113300 KB Output is correct
7 Correct 54 ms 113228 KB Output is correct
8 Correct 57 ms 113280 KB Output is correct
9 Correct 52 ms 113228 KB Output is correct
10 Correct 59 ms 113292 KB Output is correct
11 Correct 54 ms 113224 KB Output is correct
12 Correct 53 ms 113268 KB Output is correct
13 Correct 56 ms 113220 KB Output is correct
14 Correct 55 ms 113300 KB Output is correct
15 Correct 55 ms 113404 KB Output is correct
16 Correct 70 ms 116360 KB Output is correct
17 Correct 65 ms 116244 KB Output is correct
18 Correct 65 ms 116176 KB Output is correct
19 Correct 174 ms 132100 KB Output is correct
20 Correct 157 ms 132080 KB Output is correct
21 Correct 181 ms 132044 KB Output is correct
22 Correct 159 ms 132036 KB Output is correct
23 Correct 155 ms 131924 KB Output is correct
24 Correct 157 ms 131968 KB Output is correct
25 Correct 160 ms 132048 KB Output is correct
26 Correct 152 ms 132044 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 3077 ms 467028 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 55 ms 113024 KB Output is correct
2 Execution timed out 3094 ms 600856 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 3077 ms 615160 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 54 ms 112976 KB Output is correct
2 Correct 51 ms 112972 KB Output is correct
3 Correct 52 ms 113024 KB Output is correct
4 Correct 53 ms 113056 KB Output is correct
5 Correct 51 ms 112972 KB Output is correct
6 Correct 53 ms 113300 KB Output is correct
7 Correct 54 ms 113228 KB Output is correct
8 Correct 57 ms 113280 KB Output is correct
9 Correct 52 ms 113228 KB Output is correct
10 Correct 59 ms 113292 KB Output is correct
11 Correct 54 ms 113224 KB Output is correct
12 Correct 53 ms 113268 KB Output is correct
13 Correct 56 ms 113220 KB Output is correct
14 Correct 55 ms 113300 KB Output is correct
15 Correct 55 ms 113404 KB Output is correct
16 Correct 70 ms 116360 KB Output is correct
17 Correct 65 ms 116244 KB Output is correct
18 Correct 65 ms 116176 KB Output is correct
19 Correct 174 ms 132100 KB Output is correct
20 Correct 157 ms 132080 KB Output is correct
21 Correct 181 ms 132044 KB Output is correct
22 Correct 159 ms 132036 KB Output is correct
23 Correct 155 ms 131924 KB Output is correct
24 Correct 157 ms 131968 KB Output is correct
25 Correct 160 ms 132048 KB Output is correct
26 Correct 152 ms 132044 KB Output is correct
27 Correct 470 ms 153728 KB Output is correct
28 Correct 441 ms 153676 KB Output is correct
29 Correct 461 ms 153644 KB Output is correct
30 Correct 386 ms 153548 KB Output is correct
31 Correct 392 ms 153504 KB Output is correct
32 Correct 356 ms 153508 KB Output is correct
33 Execution timed out 3118 ms 461928 KB Time limit exceeded
34 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 54 ms 112976 KB Output is correct
2 Correct 51 ms 112972 KB Output is correct
3 Correct 52 ms 113024 KB Output is correct
4 Correct 53 ms 113056 KB Output is correct
5 Correct 51 ms 112972 KB Output is correct
6 Correct 53 ms 113300 KB Output is correct
7 Correct 54 ms 113228 KB Output is correct
8 Correct 57 ms 113280 KB Output is correct
9 Correct 52 ms 113228 KB Output is correct
10 Correct 59 ms 113292 KB Output is correct
11 Correct 54 ms 113224 KB Output is correct
12 Correct 53 ms 113268 KB Output is correct
13 Correct 56 ms 113220 KB Output is correct
14 Correct 55 ms 113300 KB Output is correct
15 Correct 55 ms 113404 KB Output is correct
16 Correct 70 ms 116360 KB Output is correct
17 Correct 65 ms 116244 KB Output is correct
18 Correct 65 ms 116176 KB Output is correct
19 Correct 174 ms 132100 KB Output is correct
20 Correct 157 ms 132080 KB Output is correct
21 Correct 181 ms 132044 KB Output is correct
22 Correct 159 ms 132036 KB Output is correct
23 Correct 155 ms 131924 KB Output is correct
24 Correct 157 ms 131968 KB Output is correct
25 Correct 160 ms 132048 KB Output is correct
26 Correct 152 ms 132044 KB Output is correct
27 Execution timed out 3077 ms 467028 KB Time limit exceeded
28 Halted 0 ms 0 KB -