QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#72934#4378. BallpoiWA 1502ms36400kbC++3.9kb2023-01-20 15:44:302023-01-20 15:44:33

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 15:44:33]
  • 评测
  • 测评结果:WA
  • 用时:1502ms
  • 内存:36400kb
  • [2023-01-20 15:44:30]
  • 提交

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[100006] , pri[100006] , en;
void sieve() {
	np[1] = 1;
	rep( i , 2 , 100006 ) {
		if( !np[i] ) pri[++ en] = i;
		for( int j = 1 ; j <= en && i * pri[j] < 100006 ; ++ 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 ) {
	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[100006] , tx[MAXN] , ty[MAXN];
map<pii,int> M;

void solve() {
	cin >> n >> m;
	vx.clear() , vy.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 -= 2 * calc( xi , max( yi - d , yj - d ) , xj , min( yi + d , yj + d ) );
		} else {
			if( yi > yj ) swap( xi , xj ) , swap( yi , yj );
			res -= 2 * calc( max( xi - d , xj - d ) , yi , min( xi + d , xj + d ) , yj );
		}
	}
	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 , 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 += 4;
//		if( M.count( mp( tx[i] + l , Y ) ) ) res += 4;
//	}
//	rep( i , 1 , n ) rep( j , 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 += 4;
//		if( M.count( mp( X , ty[i] + l ) ) ) res += 4;
//	}
	cout << res << endl;
}

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

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 1502ms
memory: 36400kb

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:

294568693
120736673
120019499
294604604
119212701
119567717
282250035
122156328
119462944
295514038

result:

wrong answer 1st lines differ - expected: '306097111', found: '294568693'