QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#47485#4378. Ballzzxzzx123AC ✓1227ms44540kbC++171.2kb2022-09-10 10:40:362022-09-10 10:40:37

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2022-09-10 10:40:37]
  • 评测
  • 测评结果:AC
  • 用时:1227ms
  • 内存:44540kb
  • [2022-09-10 10:40:36]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=2010,M=N*N;
int x[N],y[N];
struct node{
	int i,j,val;
	bool operator<(const node& a)const {
		return val<a.val;
	}
}e[M];
int vis[M],pri[M],cnt;
void init(){
	vis[1]=1;
	for(int i=2;i<M;i++){
		if(!vis[i]){
			pri[++cnt]=i;
		}
		for(int j=1;j<=cnt&&(ll)i*pri[j]<M;j++){
			int v=i*pri[j];
			vis[v]=1;
			if(!(i%pri[j])){
				break;
			}
		}
	}
}
int get_val(int i,int j){
	return abs(x[i]-x[j])+abs(y[i]-y[j]);
}
bitset<N>bi[N];		
int main(){
	int t;
	scanf("%d",&t);
	init();
	while(t--){
		int n,m;
		scanf("%d%d",&n,&m);
		for(int i=1;i<=n;i++){
			scanf("%d%d",&x[i],&y[i]);
		}
		int cnt=0;
		for(int i=1;i<=n;i++){
			for(int j=i+1;j<=n;j++){
				e[++cnt]={i,j,get_val(i,j)};
			}
		}
		sort(e+1,e+cnt+1);
		
		for(int i=1;i<=n;i++){
			bi[i].reset();//全部都比你大 
		}
		int ans=0;
		for(int i=1;i<=cnt;i++){
			int u=e[i].i,v=e[i].j,val=e[i].val;//获得你的编号
			if(!vis[val])
			{
				ans+=(bi[u]^bi[v]).count();
			}
			bi[u][v]=bi[v][u]=1;	
			//接下来考虑删除和添加
		}
		printf("%d\n",ans);
	}
	return 0;
} 

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1227ms
memory: 44540kb

input:

10
2000 80
9 25
39 66
5 63
59 17
45 19
41 21
21 75
21 61
1 65
29 61
11 23
38 51
1 3
41 59
41 61
61 33
45 65
80 49
38 49
45 79
66 60
61 41
56 33
65 57
26 17
36 1
77 11
13 28
25 41
33 23
66 16
4 73
1 1
57 61
32 11
31 29
42 21
37 69
53 59
1 66
54 70
21 57
65 49
49 18
6 5
11 1
1 67
78 49
43 30
27 1
57 7...

output:

306097111
113711265
112644014
306052056
111920257
112598067
290930159
115277403
112743440
307026778

result:

ok 10 lines