QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#72937#4378. BallpoiAC ✓2030ms37584kbC++4.1kb2023-01-20 16:31:412023-01-20 16:31:42

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-01-20 16:31:42]
  • 评测
  • 测评结果:AC
  • 用时:2030ms
  • 内存:37584kb
  • [2023-01-20 16:31:41]
  • 提交

answer

#include "iostream"
#include "cstring"
#include "cstdio"
#include "algorithm"
#include "queue"
#include "vector"
#include "queue"
#include "stack"
#include "ctime"
#include "set"
#include "map"
#include "bitset"
using namespace std;
#define fi first
#define se second
#define vi vector<int>
#define pb push_back
#define eb emplace_back
#define pii pair<int,int>
#define mp make_pair
#define rep( i , a , b ) for( int i = (a) , i##end = b ; i <= i##end ; ++ i )
#define per( i , a , b ) for( int i = (a) , i##end = b ; i >= i##end ; -- i )
#define mem( a ) memset( a , 0 , sizeof (a) )
#define all( x ) x.begin() , x.end()
//#define int long long
typedef long long ll;
const int MAXN = 2e3 + 10;
const int P = 998244353;
int n , m , k;

vector<int> vx , vy;
int X[MAXN] , Y[MAXN] , dis[MAXN][MAXN];

int np[200006] , pri[200006] , en;
void sieve() {
	np[1] = 1;
	rep( i , 2 , 200006 ) {
		if( !np[i] ) pri[++ en] = i;
		for( int j = 1 ; j <= en && i * pri[j] < 200006 ; ++ j ) {
			np[i * pri[j]] = 1;
			if( i % pri[j] == 0 ) break;
		}
	}
}

int gx( int x ) {
	return lower_bound( all( vx ) , x ) - vx.begin() + 1;
}
int gy( int y ) {
	return lower_bound( all( vy ) , y ) - vy.begin() + 1;
}

int S[MAXN][MAXN];

int calc( int x1 , int y1 , int x2 , int y2 ) {
	if( x1 > x2 || y1 > y2 ) return 0;
	int X = gx( x2 + 1 ) - 1 , Y = gy( y2 + 1 ) - 1 , x = gx( x1 ) - 1 , y = gy( y1 ) - 1;
	return S[X][Y] - S[X][y] - S[x][Y] + S[x][y];
}

int cn[200006] , tx[MAXN] , ty[MAXN];
map<pii,int> M;

void solve() {
	cin >> n >> m;
	vx.clear() , vy.clear();
	M.clear();
	rep( i , 1 , n ) {
		int x , y;
		scanf("%d%d",&x,&y);
		tx[i] = x , ty[i] = y;
		M[mp( x , y )] ++;
		X[i] = x - y , Y[i] = x + y;
		vx.pb( X[i] ) , vy.pb( Y[i] );
	}
	rep( i , 1 , n ) rep( j , 1 , n ) dis[i][j] = max( abs( X[i] - X[j] ) , abs( Y[i] - Y[j] ) );
	sort( all( vx ) ) , vx.erase( unique( all( vx ) ) , vx.end() );
	sort( all( vy ) ) , vy.erase( unique( all( vy ) ) , vy.end() );
	rep( i , 1 , n ) X[i] = lower_bound( all( vx ) , X[i] ) - vx.begin() + 1;
	rep( i , 1 , n ) Y[i] = lower_bound( all( vy ) , Y[i] ) - vy.begin() + 1;
	rep( i , 1 , n ) S[X[i]][Y[i]] ++;
	rep( i , 1 , vx.size() + 1 ) rep( j , 1 , vy.size() + 1 ) 
		S[i][j] += S[i - 1][j] + S[i][j - 1] - S[i - 1][j - 1];
	int res = 0;
	rep( i , 1 , n ) rep( j , i + 1 , n ) if( !np[dis[i][j]] ) {
		int xi = vx[X[i] - 1] , yi = vy[Y[i] - 1] , xj = vx[X[j] - 1] , yj = vy[Y[j] - 1];
		int d = dis[i][j];
		res += calc( xi - d , yi - d , xi + d , yi + d ) + calc( xj - d , yj - d , xj + d , yj + d );
		if( abs( xi - xj ) > abs( yi - yj ) ) {
			if( xi > xj ) swap( xi , xj ) , swap( yi , yj );
			res -= calc( xi , max( yi - d , yj - d ) , xj , min( yi + d , yj + d ) );
			res -= calc( xi + 1 , max( yi - d , yj - d ) + 1 , xj - 1 , min( yi + d , yj + d ) - 1 ) + 2;
		} else {
			if( yi > yj ) swap( xi , xj ) , swap( yi , yj );
			res -= calc( max( xi - d , xj - d ) , yi , min( xi + d , xj + d ) , yj );
			res -= calc( max( xi - d , xj - d ) + 1 , yi + 1 , min( xi + d , xj + d ) - 1 , yj - 1 ) + 2;
		}
	}
	rep( i , 1 , n ) {
		int re = 0;
		rep( j , 1 , n ) if( !np[dis[i][j]] ) {
			re += cn[dis[i][j]] , ++ cn[dis[i][j]];
		}
		rep( j , 1 , n ) if( !np[dis[i][j]] ) {
			-- cn[dis[i][j]];
		}
		res -= re;
	}
	rep( i , 1 , vx.size() + 1 ) rep( j , 1 , vy.size() + 1 ) S[i][j] = 0;
	rep( i , 1 , n ) rep( j , i + 1 , n ) if( i != j && !np[dis[i][j]] && tx[i] == tx[j] && ( ty[i] - ty[j] ) % 2 == 0 ) {
		int Y = ( ty[i] + ty[j] ) / 2 , l = ( ty[i] - ty[j] ) / 2;
		if( M.count( mp( tx[i] - l , Y ) ) ) res += 1;
		if( M.count( mp( tx[i] + l , Y ) ) ) res += 1;
	}
	rep( i , 1 , n ) rep( j , i + 1 , n ) if( i != j && !np[dis[i][j]] && ty[i] == ty[j] && ( tx[i] - tx[j] ) % 2 == 0 ) {
		int X = ( tx[i] + tx[j] ) / 2 , l = ( tx[i] - tx[j] ) / 2;
		if( M.count( mp( X , ty[i] - l ) ) ) res += 1;
		if( M.count( mp( X , ty[i] + l ) ) ) res += 1;
	}
	cout << res << endl;
}

signed main() {
	sieve();
//	freopen("in","r",stdin);
//	freopen("out","w",stdout);
	int T;cin >> T;while( T-- ) solve();
//	solve();
}

詳細信息

Test #1:

score: 100
Accepted
time: 2030ms
memory: 37584kb

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