QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#453742 | #5463. Range Closest Pair of Points Query | ship2077 | WA | 133ms | 187652kb | C++17 | 1.8kb | 2024-06-24 10:11:06 | 2024-06-24 10:11:06 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
constexpr int M=2.5e5+5;
struct point{int x,y;}a[M];
int n,q,blk,idx,qr[M],bel[M];
ll ans[M],rec[M],sum1[M],sum2[M];
vector<pair<int,int>>qry[M];
unordered_map<ll,int>mp[28];
vector<int>vec[M*28];
ll dist(point a,point b){
return 1ll*(a.x-b.x)*(a.x-b.x)+1ll*(a.y-b.y)*(a.y-b.y);
}
int read(){
int x=0;char ch=getchar();
while (!isdigit(ch)) ch=getchar();
while (isdigit(ch)) x=x*10+ch-48,ch=getchar();
return x;
}
void update(int x,ll p){
sum1[bel[x]]=min(sum1[bel[x]],p);sum2[x]=min(sum2[x],p);
}
ll query(int x){ ll ans=LLONG_MAX;
for (int i=bel[x]+1;i<=bel[n];i++) ans=min(ans,sum1[i]);
for (int i=x;i<=qr[bel[x]];i++) ans=min(ans,sum2[i]);
return ans;
}
int main(){
n=read();q=read();blk=ceil(sqrt(n));
for (int i=1;i<=n;i++) rec[i]=sum1[i]=sum2[i]=LLONG_MAX;
for (int i=1;i<=n;i++) bel[i]=(i-1)/blk+1;
for (int i=1;i<=bel[n];i++) qr[i]=qr[i-1]+blk;
for (int i=1;i<=n;i++) a[i]={read(),read()};
for (int i=1;i<=q;i++){
int l=read(),r=read();
qry[r].emplace_back(l,i);
}
for (int i=1;i<=n;i++){
for (int k=0;k<28;k++){
for (auto x:{-1,0,1})
for (auto y:{-1,0,1}){
ll Hash=((a[i].x>>k)+x)<<30|((a[i].y>>k)+y);
if (!mp[k].count(Hash)) continue;
int num=mp[k][Hash];
vector<int>tmp;int pos=0;
for (auto x:vec[num]){
ll tmp=dist(a[x],a[i]);
if (tmp<rec[x]) update(x,rec[x]=tmp);
if (tmp<1ll<<(k<<1)) pos=x;
}
for (auto x:vec[num]) if (x>pos)
tmp.emplace_back(x);
swap(tmp,vec[num]);
}
ll Hash=(a[i].x>>k)<<30|(a[i].y>>k);
if (!mp[k].count(Hash)) mp[k][Hash]=idx++;
vec[mp[k][Hash]].emplace_back(i);
}
for (auto [j,id]:qry[i])
ans[id]=query(j);
}
for (int i=1;i<=q;i++) printf("%lld\n",ans[i]);
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 19ms
memory: 184432kb
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: 23ms
memory: 184320kb
input:
2 1 1 1 1 1 1 2
output:
0
result:
ok 1 number(s): "0"
Test #3:
score: 0
Accepted
time: 23ms
memory: 184784kb
input:
2 1 1 100000000 100000000 1 1 2
output:
19999999600000002
result:
ok 1 number(s): "19999999600000002"
Test #4:
score: -100
Wrong Answer
time: 133ms
memory: 187652kb
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 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 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...
result:
wrong answer 63625th numbers differ - expected: '1', found: '0'