QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#122430 | #5463. Range Closest Pair of Points Query | fansizhe | WA | 197ms | 21576kb | C++23 | 1.7kb | 2023-07-10 15:00:32 | 2023-07-10 15:00:33 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const double eps=1e-6;
int n,q,B;
struct node{
long double x,y;
int id;
bool operator <(const node &b)const{
if(abs(x-b.x)>eps)return x<b.x;
else return y<b.y;
}
}a[250005];
int b[250005];
int pos[250005],L[505],R[505];
vector<pair<int,int> > Query[250005];
ll ans[250005];
ll val[250005],mn[505];
ll getdis(long double x,long double y){return (ll)round(x*x+y*y);}
void init(){
for(int i=1;i<=n;i++)val[i]=0x3f3f3f3f3f3f3f3f;
for(int i=1;i<=pos[n];i++)mn[i]=0x3f3f3f3f3f3f3f3f;
}
void add(int x,ll y){
val[x]=min(val[x],y);
mn[pos[x]]=min(mn[pos[x]],y);
}
ll ask(int l,int r){
ll res=0x3f3f3f3f3f3f3f3f;
if(pos[l]==pos[r])for(int i=l;i<=r;i++)res=min(res,val[i]);
else{
for(int i=pos[l]+1;i<pos[r];i++)res=min(res,mn[i]);
for(int i=l;i<=R[pos[l]];i++)res=min(res,val[i]);
for(int i=L[pos[r]];i<=r;i++)res=min(res,val[i]);
}
return res;
}
int main(){
srand(time(NULL));
scanf("%d%d",&n,&q);B=sqrt(n);
long double cs=1.0*rand()/RAND_MAX,sn=sqrt(1-cs*cs);
for(int i=1;i<=n;i++){
long double x,y;
scanf("%LF%LF",&x,&y);
a[i].x=x*cs-y*sn,a[i].y=x*sn+y*cs;
a[i].id=i;
}
sort(a+1,a+n+1);
for(int i=1;i<=n;i++){
b[a[i].id]=i;
pos[i]=(i-1)/B+1;
if(!L[pos[i]])L[pos[i]]=i;
R[pos[i]]=i;
}
for(int i=1;i<=q;i++){
int l,r;scanf("%d%d",&l,&r);
Query[r].push_back(make_pair(l,i));
}
init();
for(int i=1;i<=n;i++){
for(int j=max(1,b[i]-1000);j<b[i];j++)add(a[j].id,getdis(a[j].x-a[b[i]].x,a[j].y-a[b[i]].y));
for(auto p:Query[i])ans[p.second]=ask(p.first,i);
}
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: 3ms
memory: 16184kb
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: 3ms
memory: 15992kb
input:
2 1 1 1 1 1 1 2
output:
0
result:
ok 1 number(s): "0"
Test #3:
score: 0
Accepted
time: 3ms
memory: 14008kb
input:
2 1 1 100000000 100000000 1 1 2
output:
19999999600000002
result:
ok 1 number(s): "19999999600000002"
Test #4:
score: -100
Wrong Answer
time: 197ms
memory: 21576kb
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 423rd numbers differ - expected: '1', found: '0'