QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#631886 | #5463. Range Closest Pair of Points Query | hxhhxh | WA | 362ms | 56700kb | C++20 | 1.6kb | 2024-10-12 10:47:52 | 2024-10-12 10:47:53 |
Judging History
answer
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#define ll long long
using namespace std;
using namespace __gnu_pbds;
int n,q,cnt,h[250005];
ll ans[250005],b[888],w[251005];
struct st{
int x,y;
}a[250005];
vector<int>e[250005],c[250005],p[250005];
gp_hash_table<ll,int>mp;
ll id(int x,int y){
return x*1000000000+y;
}
void add(int x,int y,int i){
int t=mp[id(x,y)];
if(!t) t=mp[id(x,y)]=++cnt;
p[t].push_back(i);
}
void cg(int x,ll v){
w[x]=min(w[x],v);
b[x>>9]=min(b[x>>9],v);
}
ll que(int x){
ll res=1e18;
for(;x&511;x++) res=min(res,w[x]);
for(x>>=9;!(x>>9);x++) res=min(res,b[x]);
return res;
}
mt19937 rd(time(NULL));
signed main(){
cin>>n>>q;
memset(w,0x3f,sizeof(w));
memset(b,0x3f,sizeof(b));
for(int i=1;i<=n;i++) scanf("%d %d",&a[i].x,&a[i].y);
int DX=rd()%999,DY=rd()%999;
for(int i=1;i<=n;i++) a[i].x+=DX,a[i].y+=DY;
for(int i=0;i<=30;i++){
for(int j=1;j<=cnt;j++) p[j].clear();
mp.clear(),cnt=0;
for(int j=1;j<=n;j++){
int x=a[j].x>>i,y=a[j].y>>i;
for(int k=-1;k<=1;k++){
for(int l=-1;l<=1;l++){
if(mp.find(id(x+k,y+l))!=mp.end()){
int t=mp[id(x+k,y+l)],d=p[t].size();
for(int o=max(d-5,0);o<d;o++) e[j].push_back(p[t][o]);
}
}
}
add(a[j].x>>i,a[j].y>>i,j);
}
}
for(int i=1,j;i<=q;i++){
scanf("%d %d",&h[i],&j);
c[j].push_back(i);
}
for(int i=1;i<=n;i++){
for(int j:e[i]) if(j<i) cg(j,1ll*(a[i].x-a[j].x)*(a[i].x-a[j].x)+1ll*(a[i].y-a[j].y)*(a[i].y-a[j].y));
for(int j:c[i]) ans[j]=que(h[j]);
}
for(int i=1;i<=q;i++) printf("%lld\n",ans[i]);
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 3ms
memory: 12024kb
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: 9988kb
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: 10316kb
input:
2 1 1 100000000 100000000 1 1 2
output:
19999999600000002
result:
ok 1 number(s): "19999999600000002"
Test #4:
score: 0
Accepted
time: 253ms
memory: 46184kb
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:
ok 250000 numbers
Test #5:
score: 0
Accepted
time: 337ms
memory: 56700kb
input:
20000 250000 72 45 72 34 34 10 20 96 79 39 43 5 72 49 56 85 1 72 44 70 73 89 69 76 49 89 57 38 39 9 33 47 22 3 96 41 90 82 25 6 72 92 73 38 53 21 16 88 59 9 54 2 14 6 7 94 99 68 27 82 70 50 81 81 60 81 2 98 33 19 98 9 35 36 49 66 86 7 3 95 32 89 62 42 68 88 65 16 94 6 85 10 51 69 90 36 70 87 13 79 4...
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 10 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 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0...
result:
ok 250000 numbers
Test #6:
score: -100
Wrong Answer
time: 362ms
memory: 53648kb
input:
20000 250000 116 165 150 677 951 676 552 324 267 222 739 755 705 663 235 142 152 714 735 641 414 201 313 663 683 300 403 739 37 521 42 833 553 733 886 449 86 913 55 637 731 932 143 161 500 891 719 79 916 237 431 992 804 210 643 332 165 362 178 332 821 510 762 34 188 83 283 357 743 407 750 487 19 658...
output:
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 45 1 0 1 0 0 0 2 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 4 0 0 0 0 0 0 0 0 0 2 0 0 0 0 0 0 0 0 0 0 52 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 2 0 0 0 0 5 0 0 0 0 0 1 0 0 0 1 1 0 0 0 2 0 0 0 0 0 0 ...
result:
wrong answer 4017th numbers differ - expected: '5237', found: '6290'