QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#102535 | #5463. Range Closest Pair of Points Query | Hongzy | WA | 4ms | 15824kb | C++14 | 1.6kb | 2023-05-03 14:28:36 | 2023-05-03 14:28:37 |
Judging History
answer
#include <bits/stdc++.h>
#define fs first
#define sc second
#define pb push_back
#define LOG(FMT...) fprintf(stderr, FMT);
#define rep(i, j, k) for(int i = j; i <= k; ++ i)
#define per(i, j, k) for(int i = j; i >= k; -- i)
using namespace std;
using pii = pair<int, int>;
using ll = long long;
const int N = 3e5 + 5;
const ll INF = 1e18;
pii a[N];
int n, q;
ll ans[N], bit[N];
vector<pii> vec[N];
map< pii, vector<int> > sys[32];
ll pw(ll x) { return x * x; }
ll dis(int x, int y) {
return pw(a[x].fs - a[y].fs) + pw(a[x].sc - a[y].sc);
}
void init() {
rep(i, 1, n) bit[i] = INF;
}
void ins(int x, ll y) {
x = n-x+1;
for(; x <= n; x += x & (-x))
bit[x] = min(bit[x], y);
}
ll qry(int x) {
x = n-x+1;
ll ans = INF;
for(; x >= 1; x &= x-1)
ans = min(ans, bit[x]);
return ans;
}
int main() {
scanf("%d%d", &n, &q);
rep(i, 1, n) {
scanf("%d%d", &a[i].fs, &a[i].sc);
}
rep(i, 1, q) {
int l, r;
scanf("%d%d", &l, &r);
vec[r].pb(pii(l, i));
}
init();
rep(r, 1, q) {
int mx = 0;
rep(k, 0, 26) {
int x = a[r].fs >> (k+1), y = a[r].sc >> (k+1);
int _mx = 0;
rep(dx, -1, 1) rep(dy, -1, 1) {
auto &it = sys[k][pii(x+dx, y+dy)];
while(it.size() && *it.begin() <= mx)
it.erase(it.begin());
for(int z: it) {
// printf("(%d, %d)\n", z, r);
_mx = max(_mx, z);
ins(z, dis(z, r));
}
}
mx = max(mx, _mx);
sys[k][pii(x, y)].pb(r);
}
for(auto it: vec[r])
ans[it.sc] = qry(it.fs);
}
rep(i, 1, q)
printf("%lld\n", ans[i]);
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 15824kb
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: 1ms
memory: 13728kb
input:
2 1 1 1 1 1 1 2
output:
0
result:
ok 1 number(s): "0"
Test #3:
score: -100
Wrong Answer
time: 4ms
memory: 12976kb
input:
2 1 1 100000000 100000000 1 1 2
output:
0
result:
wrong answer 1st numbers differ - expected: '19999999600000002', found: '0'