Submission #710102

# Submission time Handle Problem Language Result Execution time Memory
710102 2023-03-15T04:40:44 Z vjudge1 Circle selection (APIO18_circle_selection) C++17
7 / 100
3000 ms 628672 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';
      |                                                 ^~~~
# Verdict Execution time Memory Grader output
1 Correct 52 ms 112980 KB Output is correct
2 Correct 51 ms 113008 KB Output is correct
3 Correct 52 ms 113060 KB Output is correct
4 Correct 55 ms 112972 KB Output is correct
5 Correct 50 ms 112988 KB Output is correct
6 Correct 61 ms 113256 KB Output is correct
7 Correct 61 ms 113300 KB Output is correct
8 Correct 53 ms 113228 KB Output is correct
9 Correct 59 ms 113224 KB Output is correct
10 Correct 55 ms 113208 KB Output is correct
11 Correct 54 ms 113232 KB Output is correct
12 Correct 64 ms 113244 KB Output is correct
13 Correct 57 ms 113248 KB Output is correct
14 Correct 54 ms 113196 KB Output is correct
15 Correct 52 ms 113356 KB Output is correct
16 Correct 64 ms 116196 KB Output is correct
17 Correct 78 ms 116248 KB Output is correct
18 Correct 70 ms 116272 KB Output is correct
19 Correct 200 ms 132156 KB Output is correct
20 Correct 145 ms 132184 KB Output is correct
21 Correct 187 ms 132060 KB Output is correct
22 Correct 154 ms 132044 KB Output is correct
23 Correct 167 ms 132008 KB Output is correct
24 Correct 177 ms 132056 KB Output is correct
25 Correct 151 ms 132048 KB Output is correct
26 Correct 154 ms 132016 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 3102 ms 467748 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 55 ms 112972 KB Output is correct
2 Execution timed out 3106 ms 592996 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 3086 ms 628672 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 52 ms 112980 KB Output is correct
2 Correct 51 ms 113008 KB Output is correct
3 Correct 52 ms 113060 KB Output is correct
4 Correct 55 ms 112972 KB Output is correct
5 Correct 50 ms 112988 KB Output is correct
6 Correct 61 ms 113256 KB Output is correct
7 Correct 61 ms 113300 KB Output is correct
8 Correct 53 ms 113228 KB Output is correct
9 Correct 59 ms 113224 KB Output is correct
10 Correct 55 ms 113208 KB Output is correct
11 Correct 54 ms 113232 KB Output is correct
12 Correct 64 ms 113244 KB Output is correct
13 Correct 57 ms 113248 KB Output is correct
14 Correct 54 ms 113196 KB Output is correct
15 Correct 52 ms 113356 KB Output is correct
16 Correct 64 ms 116196 KB Output is correct
17 Correct 78 ms 116248 KB Output is correct
18 Correct 70 ms 116272 KB Output is correct
19 Correct 200 ms 132156 KB Output is correct
20 Correct 145 ms 132184 KB Output is correct
21 Correct 187 ms 132060 KB Output is correct
22 Correct 154 ms 132044 KB Output is correct
23 Correct 167 ms 132008 KB Output is correct
24 Correct 177 ms 132056 KB Output is correct
25 Correct 151 ms 132048 KB Output is correct
26 Correct 154 ms 132016 KB Output is correct
27 Correct 401 ms 153728 KB Output is correct
28 Correct 396 ms 153724 KB Output is correct
29 Correct 425 ms 153872 KB Output is correct
30 Correct 340 ms 153504 KB Output is correct
31 Correct 314 ms 153528 KB Output is correct
32 Correct 339 ms 153624 KB Output is correct
33 Execution timed out 3118 ms 467008 KB Time limit exceeded
34 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 52 ms 112980 KB Output is correct
2 Correct 51 ms 113008 KB Output is correct
3 Correct 52 ms 113060 KB Output is correct
4 Correct 55 ms 112972 KB Output is correct
5 Correct 50 ms 112988 KB Output is correct
6 Correct 61 ms 113256 KB Output is correct
7 Correct 61 ms 113300 KB Output is correct
8 Correct 53 ms 113228 KB Output is correct
9 Correct 59 ms 113224 KB Output is correct
10 Correct 55 ms 113208 KB Output is correct
11 Correct 54 ms 113232 KB Output is correct
12 Correct 64 ms 113244 KB Output is correct
13 Correct 57 ms 113248 KB Output is correct
14 Correct 54 ms 113196 KB Output is correct
15 Correct 52 ms 113356 KB Output is correct
16 Correct 64 ms 116196 KB Output is correct
17 Correct 78 ms 116248 KB Output is correct
18 Correct 70 ms 116272 KB Output is correct
19 Correct 200 ms 132156 KB Output is correct
20 Correct 145 ms 132184 KB Output is correct
21 Correct 187 ms 132060 KB Output is correct
22 Correct 154 ms 132044 KB Output is correct
23 Correct 167 ms 132008 KB Output is correct
24 Correct 177 ms 132056 KB Output is correct
25 Correct 151 ms 132048 KB Output is correct
26 Correct 154 ms 132016 KB Output is correct
27 Execution timed out 3102 ms 467748 KB Time limit exceeded
28 Halted 0 ms 0 KB -