QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#131666#5463. Range Closest Pair of Points Querysumi007WA 141ms237880kbC++141.9kb2023-07-27 20:04:202023-07-27 20:04:21

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-07-27 20:04:21]
  • 评测
  • 测评结果:WA
  • 用时:141ms
  • 内存:237880kb
  • [2023-07-27 20:04:20]
  • 提交

answer

#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/hash_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define ll long long
#define i64 __int128
#define fi first
#define se second
#define pii pair<int,int>
#define pb push_back
#define d(i,j) 1ll*j*1813327743ll+i
const ll N = 3e5+5,inf = 1e18;
ll n,Q,B,nodex,mn[N],mn_B[N],b[N],R[N],ans[N],L[N];
int dx[10]={-1,-1,-1,0,0,0,1,1,1},dy[10]={-1,0,1,-1,0,1,-1,0,1};
struct node{
	ll x,y;
}p[N];
vector<pii> q[N];
vector<int> pos[N*30];
gp_hash_table<ll,int> num[30];
ll calc(ll sx,ll sy,ll ex,ll ey){
	return (sx-ex)*(sx-ex)+(sy-ey)*(sy-ey);
}
ll ask(ll l,ll r){
	ll res = inf;
	for(int i=l;i<=min(R[b[l]],r);i++) res = min(res,mn[i]);
	for(int i=b[l]+1;i<=b[r]-1;i++) res = min(res,mn_B[i]);
	for(int i=L[b[r]];i<=r;i++) res = min(res,mn[i]);
	return res;
}
int main(){
	cin.tie(0),cout.tie(0);
	ios::sync_with_stdio(0);
	cin >> n >> Q;
	B = sqrt(n);
	for(int i=1;i<=n;i++){
		cin >> p[i].x >> p[i].y;
		b[i] = (i-1)/B+1;
		R[b[i]] = i;
		if(b[i]!=b[i-1]) L[b[i]] = i;
	}
	for(int i=1,l,r;i<=Q;i++){
		cin >> l >> r;
		q[r].pb({l,i});
	}
	for(int i=1;i<=n;i++) mn[i] = mn_B[i] = inf;
	for(int i=1;i<=n;i++){
		for(int j=0;(1<<j)<=1e8;j++){
			ll tx = (p[i].x)>>j,ty = (p[i].y)>>j;
			if(num[j].find(d(tx,ty))==num[j].end()) num[j][d(tx,ty)] = ++nodex;
			for(int k=0;k<9;k++){
				ll nx = tx+dx[k],ny = ty+dy[k]; 
				if(nx<0 || ny<0 || num[j].find(d(nx,ny))==num[j].end()) continue;
				int id = num[j][d(nx,ny)];
				vector<int> tmp;
				for(int l:pos[id]){
					ll dis = calc(p[l].x,p[l].y,p[i].x,p[i].y);
					mn[l] = min(mn[l],dis),mn_B[b[l]] = min(mn_B[b[l]],dis);
					if(dis>(1ll<<(2*j-2))) tmp.pb(l);
				}
				pos[id] = tmp;
				if(k==4) pos[id].pb(i);
			}
		}
		for(pii t:q[i]) ans[t.se] = ask(t.fi,i);
	}
	for(int i=1;i<=Q;i++) cout << ans[i] << '\n';
	return 0;
}

详细

Test #1:

score: 100
Accepted
time: 29ms
memory: 234452kb

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: 19ms
memory: 234024kb

input:

2 1
1 1
1 1
1 2

output:

0

result:

ok 1 number(s): "0"

Test #3:

score: 0
Accepted
time: 32ms
memory: 233968kb

input:

2 1
1 100000000
100000000 1
1 2

output:

19999999600000002

result:

ok 1 number(s): "19999999600000002"

Test #4:

score: -100
Wrong Answer
time: 141ms
memory: 237880kb

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'