QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#684556#5463. Range Closest Pair of Points Queryucup-team5217WA 168ms15716kbC++233.1kb2024-10-28 14:22:362024-10-28 14:22:37

Judging History

你现在查看的是最新测评结果

  • [2024-10-28 14:22:37]
  • 评测
  • 测评结果:WA
  • 用时:168ms
  • 内存:15716kb
  • [2024-10-28 14:22:36]
  • 提交

answer

/**
 * @file 5463.cpp
 * @author Macesuted ([email protected])
 * @date 2024-10-28
 *
 * @copyright Copyright (c) 2024
 *
 */

#include <bits/stdc++.h>
using namespace std;

#ifndef LOCAL
#define endl '\n'
#endif

bool mem1;

#define maxn 250005
#define maxlgv 28
#define B 500

typedef pair<int, int> pii;

pii a[maxn];

int64_t sqr(int64_t v) { return v * v; }
int64_t dist(int x, int y) { return sqr(a[x].first - a[y].first) + sqr(a[x].second - a[y].second); }

class Block {
   private:
    int n;
    int64_t a[maxn], b[maxn];

   public:
    Block(void) {
        for (int i = 0; i < maxn; i++) a[i] = b[i] = INT64_MAX;
    }

    void resize(int _n) { return n = _n, void(); }
    void add(int p, int64_t v) { return a[p] = min(a[p], v), b[p / B] = min(b[p / B], v), void(); }
    int64_t query(int p) {
        int64_t ans = INT64_MAX;
        int q = p;
        while (q / B == p / B) ans = min(ans, a[q++]);
        while (q / B <= n / B) ans = min(ans, b[q / B]), q += B;
        return ans;
    }
} BLK;

class Dime {
   private:
    int64_t lim;
    unordered_map<int64_t, deque<int>> list;
    queue<int> all;

    static int64_t _(int64_t x, int64_t y) { return x * int64_t(1e9) + y; }

   public:
    void setLim(int64_t v) { return lim = v, void(); }
    void insert(int p) {
        int x = a[p].first / lim / 2, y = a[p].second / lim / 2, del = 0;
        for (int tx = x - 1; tx <= x + 1; tx++)
            for (int ty = y - 1; ty <= y + 1; ty++)
                if (list.find(_(tx, ty)) != list.end())
                    for (auto q : list[_(tx, ty)]) {
                        int64_t d = dist(p, q);
                        BLK.add(q, d);
                        if (d < lim) del = q;
                    }

        while (!all.empty() && all.front() <= del) {
            int q = all.front();
            all.pop();
            int tx = a[q].first / lim / 2, ty = a[q].second / lim / 2;
            list[_(tx, ty)].pop_front();
            if (list[_(tx, ty)].empty()) list.erase(_(tx, ty));
        }

        list[_(x, y)].push_back(p), all.push(p);
        return;
    }
};

Dime dims[maxlgv];
vector<pii> ques[maxn];
int64_t ans[maxn];

void solve(void) {
    int n, q;
    cin >> n >> q;
    for (int i = 1; i <= n; i++) cin >> a[i].first >> a[i].second;
    for (int i = 1, l, r; i <= q; i++) cin >> l >> r, ques[r].emplace_back(l, i);

    for (int i = 0; i < maxlgv; i++) dims[i].setLim((int64_t)1 << i);
    for (int i = 1; i <= n; i++) {
        for (int j = 0; j < maxlgv; j++) dims[j].insert(i);
        for (auto [l, id] : ques[i]) ans[id] = BLK.query(l);
    }

    for (int i = 1; i <= q; i++) cout << ans[i] << endl;
    return;
}

bool mem2;

int main() {
    ios::sync_with_stdio(false), cin.tie(nullptr);
#ifdef LOCAL
    cerr << "Memory Cost: " << abs(&mem1 - &mem2) / 1024. / 1024. << "MB" << endl;
#endif

    int _ = 1;
    while (_--) solve();

#ifdef LOCAL
    cerr << "Time Cost: " << clock() * 1000. / CLOCKS_PER_SEC << "MS" << endl;
#endif
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 2ms
memory: 9724kb

input:

5 5
2 4
1 1
3 3
5 1
4 2
1 5
2 3
2 4
3 5
1 3

output:

2
8
8
2
2

result:

ok 5 number(s): "2 8 8 2 2"

Test #2:

score: 0
Accepted
time: 2ms
memory: 9724kb

input:

2 1
1 1
1 1
1 2

output:

0

result:

ok 1 number(s): "0"

Test #3:

score: 0
Accepted
time: 2ms
memory: 9844kb

input:

2 1
1 100000000
100000000 1
1 2

output:

19999999600000002

result:

ok 1 number(s): "19999999600000002"

Test #4:

score: -100
Wrong Answer
time: 168ms
memory: 15716kb

input:

20000 250000
3 10
5 4
4 7
1 5
2 1
10 6
2 3
8 4
2 1
8 5
9 8
7 7
4 5
2 7
9 4
9 10
3 2
9 5
10 2
9 2
3 1
9 9
6 5
9 5
9 10
9 1
1 2
8 8
3 4
7 6
6 2
6 8
6 6
8 4
10 2
1 1
10 2
8 3
4 4
5 5
5 1
4 9
7 6
6 8
6 4
1 6
10 3
3 2
4 10
6 8
9 7
2 10
7 8
10 7
3 2
5 1
6 4
7 9
1 3
4 9
4 8
9 4
5 2
2 2
9 2
9 2
9 6
6 9
8 7
...

output:

0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
1
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
1
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
...

result:

wrong answer 45th numbers differ - expected: '0', found: '1'