Submission #49638

#TimeUsernameProblemLanguageResultExecution timeMemory
49638gs13105Circle selection (APIO18_circle_selection)C++17
100 / 100
1483 ms36256 KiB
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cassert>
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <tuple>
#include <iterator>

using namespace std;

struct cir
{
    int x, y, r, i;
    bool operator <(const cir &a) const
    {
        return r != a.r ? r > a.r : i < a.i;
    }
};

const int MAXN = 300000;
const int MAXV = 1000000000;
cir arr[MAXN + 10];
int num[MAXN + 10];
int res[MAXN + 10];
int n;

bool inter(const cir &a, const cir &b)
{
    return 1LL * (a.x - b.x) * (a.x - b.x) + 1LL * (a.y - b.y) * (a.y - b.y) <= 1LL * (a.r + b.r) * (a.r + b.r);
}

vector<long long> com;
long long tmp[MAXN + 10];
vector<int> lis[MAXN + 10];

inline int idx(long long x)
{
    return lower_bound(com.begin(), com.end(), x) - com.begin();
}

inline long long idx2(int x, int y, int r)
{
    return (2LL * MAXV + 1) * ((x + MAXV) / r) + (y + MAXV) / r;
}

void init(int s, int mx)
{
    com.clear();
    for(int i = 0; i < n - s; i++)
        lis[i].clear();

    for(int i = s; i <= n; i++)
    {
        if(num[i])
            continue;

        tmp[i] = idx2(arr[i].x, arr[i].y, mx);
        com.push_back(tmp[i]);
    }

    sort(com.begin(), com.end());
    com.erase(unique(com.begin(), com.end()), com.end());

    for(int i = s; i <= n; i++)
    {
        if(num[i])
            continue;
        lis[idx(tmp[i])].push_back(i);
    }
}

int main()
{
    //freopen("in", "r", stdin);
    //freopen("out", "w", stdout);

    int i, j, k;
    scanf("%d", &n);
    for(i = 1; i <= n; i++)
    {
        int x, y, r;
        scanf("%d%d%d", &x, &y, &r);
        arr[i] = { x, y, r, i };
    }

    sort(arr + 1, arr + n + 1);

    int mx = arr[1].r;
    init(1, mx);
    for(i = 1; i <= n; i++)
    {
        if(num[i])
            continue;

        if(arr[i].r <= mx / 2)
        {
            mx = arr[i].r;
            init(i, mx);
        }

        for(j = -2; j <= 2; j++)
        {
            for(k = -2; k <= 2; k++)
            {
                int nx = max(0LL + -MAXV, min(0LL + MAXV, arr[i].x + 1LL * j * mx));
                int ny = max(0LL + -MAXV, min(0LL + MAXV, arr[i].y + 1LL * k * mx));

                long long t = idx2(nx, ny, mx);
                int t2 = idx(t);
                if(t2 == com.size() || com[t2] != t)
                    continue;

                vector<int> nex;
                for(int &x : lis[t2])
                {
                    if(inter(arr[i], arr[x]))
                        num[x] = arr[i].i;
                    else
                        nex.push_back(x);
                }
                lis[t2] = nex;
            }
        }
    }

    for(i = 1; i <= n; i++)
        res[arr[i].i] = num[i];

    for(i = 1; i <= n; i++)
        printf("%d ", res[i]);

    return 0;
}

Compilation message (stderr)

circle_selection.cpp: In function 'int main()':
circle_selection.cpp:119:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
                 if(t2 == com.size() || com[t2] != t)
                    ~~~^~~~~~~~~~~~~
circle_selection.cpp:87:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d", &n);
     ~~~~~^~~~~~~~~~
circle_selection.cpp:91:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d%d%d", &x, &y, &r);
         ~~~~~^~~~~~~~~~~~~~~~~~~~~~
#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...