QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#47486 | #4378. Ball | zzxzzx123 | AC ✓ | 1827ms | 45072kb | C++17 | 1.3kb | 2022-09-10 10:41:40 | 2022-09-10 10:41:43 |
Judging History
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];
bitset<N>ma[N],mi[N];
int vis[N*N],pri[N*N],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]);
}
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++){
mi[i].reset();//全部都比你小
ma[i].set();//全部都比你大
mi[i][i]=ma[i][i]=0;
}
ll ans=0;
for(int i=1;i<=cnt;i++){
int u=e[i].i,v=e[i].j,val=e[i].val;//获得你的编号
auto temp1=ma[u]&mi[v];
auto temp2=ma[v]&mi[u];
if(!vis[val])
ans+=temp1.count()+temp2.count();
//接下来考虑删除和添加
mi[u][v]=1;
mi[v][u]=1;
ma[u][v]=ma[v][u]=0;
}
printf("%lld\n",ans);
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1827ms
memory: 45072kb
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