Submission #1362066

#TimeUsernameProblemLanguageResultExecution timeMemory
1362066iamhereforfunPark (BOI16_park)C++20
0 / 100
217 ms49752 KiB
// Starcraft 2 enjoyer //

#include <bits/stdc++.h>

// #pragma GCC target("avx2")
// #pragma GCC optimize("O3")
// #pragma GCC optimize("unroll-loops")

using namespace std;

#define LSOne(X) ((X) & -(X))
#define int long long

const int N = 2e5 + 5;
const int M = 1 << 15;
const int B = 18;
const long long K = 2;
const int LG = 20;
const int INF = 1e9 + 5;
const int P = 31;
const int MOD = 1e9 + 7;
const int nx[] = {0, 1, 0, -1}, ny[] = {-1, 0, 1, 0};

int n, m, parent[N], sz[N], mn[5][5], w, h;
bool has[N][5];
array<int, 3> tree[N];
vector<array<int, 3>> v;

int getParent(int x)
{
    return parent[x] == x ? x : parent[x] = getParent(parent[x]);
}

void update(int a, int b)
{
    a = getParent(a);
    b = getParent(b);
    if (a != b)
    {
        if (sz[a] < sz[b])
        {
            swap(a, b);
        }
        parent[b] = a;
        for (int x = 1; x <= 4; x++)
        {
            has[a][x] |= has[b][x];
        }
        sz[a] += sz[b];
    }
}

bool chkConnect(int a, int b)
{
    return getParent(a) == getParent(b);
}

int dis(array<int, 3> a, array<int, 3> b)
{
    // cout << a[0] << " " << a[1] << " " << b[0] << " " << b[1] << " " << a[2] << " " << b[2] << "w\n";
    // cout << sqrt((a[0] - b[0]) * (a[0] - b[0]) + (a[1] - b[1]) * (a[1] - b[1])) - a[2] - b[2] << "\n";
    return sqrt((a[0] - b[0]) * (a[0] - b[0]) + (a[1] - b[1]) * (a[1] - b[1])) - a[2] - b[2];
}

inline void solve()
{
    cin >> n >> m >> w >> h;
    for (int x = 0; x < n; x++)
    {
        cin >> tree[x][0] >> tree[x][1] >> tree[x][2];
        v.push_back({tree[x][1] - tree[x][2], x, -1});
        v.push_back({w - tree[x][0] - tree[x][2], x, -2});
        v.push_back({h - tree[x][1] - tree[x][2], x, -3});
        v.push_back({tree[x][0] - tree[x][2], x, -4});
    }
    for (int x = 0; x < n; x++)
    {
        for (int y = x + 1; y < n; y++)
        {
            v.push_back({dis(tree[x], tree[y]), x, y});
        }
    }
    for (int x = 0; x < n; x++)
    {
        parent[x] = x;
        sz[x] = 0;
    }
    sort(v.begin(), v.end());
    for (int x = 1; x <= 4; x++)
    {
        for (int y = x + 1; y <= 4; y++)
        {
            mn[x][y] = INF;
        }
    }
    for (auto &[d, a, b] : v)
    {
        if (b < 0)
        {
            has[getParent(a)][-b] = 1;
        }
        else
        {
            update(a, b);
        }
        int i = getParent(a);
        for (int x = 1; x <= 4; x++)
        {
            for (int y = x + 1; y <= 4; y++)
            {
                if (has[a][x] && has[a][y])
                {
                    mn[x][y] = min(mn[x][y], d);
                }
            }
        }
    }
    // for (int x = 1; x <= 4; x++)
    // {
    //     for (int y = x + 1; y <= 4; y++)
    //     {
    //         cout << mn[x][y] << " " << x << " " << y << "\n";
    //     }
    // }
    for (int x = 0; x < m; x++)
    {
        int r, s;
        cin >> r >> s;
        r = 2 * r;
        vector<int> ans;
        for (int y = 1; y <= 4; y++)
        {
            if (y == s)
            {
                ans.push_back(y);
                continue;
            }
            int i = s, j = y;
            if (i > j)
                swap(i, j);
            if (i == 1)
            {
                if (j == 2)
                {
                    if (r <= min({mn[3][4], mn[1][3], mn[1][2]}))
                    {
                        ans.push_back(y);
                    }
                }
                if (j == 3)
                {
                    if (r <= min({mn[3][4], mn[2][4], mn[1][2], mn[1][3]}))
                    {
                        ans.push_back(y);
                    }
                }
                if (j == 4)
                {
                    if (r <= min({mn[3][4], mn[2][4], mn[1][4]}))
                    {
                        ans.push_back(y);
                    }
                }
            }
            if (i == 2)
            {
                if (j == 3)
                {
                    if (r <= min({mn[2][3], mn[2][4], mn[1][2]}))
                    {
                        ans.push_back(y);
                    }
                }
                if (j == 4)
                {
                    if (r <= min({mn[2][3], mn[1][4], mn[1][3], mn[2][4]}))
                    {
                        ans.push_back(y);
                    }
                }
            }
            if (i == 3)
            {
                if (j == 4)
                {
                    if (r <= min({mn[1][2], mn[1][3], mn[1][4]}))
                    {
                        ans.push_back(y);
                    }
                }
            }
        }
        for (int i : ans)
            cout << i;
        cout << "\n";
    }
}

signed main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int t = 1;
    // cin >> t;
    for (int x = 1; x <= t; x++)
    {
        solve();
    }
    return 0;
}
#Result Execution timeMemoryGrader output
Fetching results...
#Result Execution timeMemoryGrader output
Fetching results...
#Result Execution timeMemoryGrader output
Fetching results...