답안 #456475

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
456475 2021-08-06T21:52:33 Z dutch Pairs (IOI07_pairs) C++17
55 / 100
342 ms 42564 KB
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define sp << ' ' <<
#define nl << '\n'

const int LIM = 1e5+1, B = 250;

int b, n, d, ans, x[LIM], y[LIM], z[LIM], F[LIM*2];

int s[80][B][B];

void add(int i, int v){
	for(; i<=LIM*2; i+=i&-i) F[i] += v;
}

int get(int i){
	int v = 0;
	for(; i>=1; i-=i&-i) v += F[i];
	return v;
}

signed main(){
	cin.tie(0)->sync_with_stdio(0);
	cin >> b >> n >> d >> x[0];
	if(b == 1){
		for(int i=0; i<n; ++i)
			cin >> x[i];
		sort(x, x+n);
		for(int i=0, j=0; i<n; ++i){
			while(j+1 < n && x[j+1]-x[i]<=d) ++j;
			ans += j-i;
		}
	}
	if(b == 2){
		array<int, 2> a[n];
		for(int i=0; i<n; ++i){
			cin >> x[i] >> y[i];
			a[i][1] = x[i] + y[i] + LIM;
			a[i][0] = x[i] - y[i] + LIM;
		}
		
		sort(a, a+n);
		for(int i=0; i<n; ++i){
			x[i] = a[i][1];
			y[i] = a[i][0];
		}

		int l = 0, r = 0;
		for(int i=0; i<n; ++i){
			while(r < n && y[r]-y[i] <= d)
				add(x[r++], 1);
			while(y[i]-y[l] > d)
				add(x[l++], -1);
			ans += get(x[i]+d) - get(x[i]-d-1);
		}
		(ans -= n) /= 2;
	}
	if(b == 3){
		for(int i=0; i<n; ++i){
			cin >> x[n] >> y[n] >> z[i];
			x[i] = x[n] + y[n] + 80;
			y[i] = x[n] - y[n] + 80;
			++s[z[i]][x[i]][y[i]];
		}

		for(int i=0; i<80; ++i)
			for(int j=1; j<B; ++j)
				for(int k=1; k<B; ++k)
					s[i][j][k] += s[i][j-1][k] + s[i][j][k-1] - s[i][j-1][k-1];
		
		for(int i=0; i<n; ++i){
			int fLim = min(z[i]+d, 80LL), diff;
			for(int f=max(z[i]-d, 0LL); f<=fLim; ++f){
				diff = abs(z[i] - f);
				int a1 = x[i] - d + diff - 1;
				int a2 = x[i] + d - diff;
				int b1 = y[i] - d + diff - 1;
				int b2 = y[i] + d - diff;
				ans += s[f][a2][b2] - s[f][a1][b2] - s[f][a2][b1] + s[f][a1][b1];
			}
		}
		(ans -= n) /= 2;
	}
	cout << ans;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 15 ms 1436 KB Output is correct
2 Correct 15 ms 1448 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 22 ms 1960 KB Output is correct
2 Correct 20 ms 1904 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 22 ms 1928 KB Output is correct
2 Correct 21 ms 1880 KB Output is correct
3 Correct 20 ms 1984 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 1100 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 38 ms 3968 KB Output is correct
2 Correct 41 ms 4012 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 44 ms 4224 KB Output is correct
2 Correct 39 ms 4184 KB Output is correct
3 Correct 42 ms 4428 KB Output is correct
4 Correct 40 ms 4240 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 46 ms 5336 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 35 ms 39364 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 57 ms 42320 KB Output is correct
2 Correct 64 ms 42308 KB Output is correct
3 Correct 76 ms 42396 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 98 ms 42564 KB Output is correct
2 Incorrect 342 ms 42552 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 263 ms 42564 KB Output isn't correct
2 Halted 0 ms 0 KB -