답안 #456552

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
456552 2021-08-07T01:17:22 Z dutch Pairs (IOI07_pairs) C++17
100 / 100
539 ms 21884 KB
#include <bits/stdc++.h>
using namespace std;
#define ll long long

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

int b, n, d, x[LIM], y[LIM], z[LIM], F[LIM*3], s[80][B][B];
ll ans;

void add(int i, int v){
	for(; i<=LIM*3; 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 < n && x[j]-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);
		}
	}
	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, 75), diff;
			for(int f=max(z[i]-d, 0); f<=fLim; ++f){
				diff = d - abs(z[i] - f);
				int u = max(x[i] - diff - 1, 0);
				int v = min(x[i] + diff, 249);
				int p = max(y[i] - diff - 1, 0);
				int q = min(y[i] + diff, 249);
				ans += s[f][v][q] - s[f][u][q] - s[f][v][p] + s[f][u][p];
			}
		}
	}
	cout << (ans - n) / (1LL + (b > 1));
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 15 ms 1096 KB Output is correct
2 Correct 15 ms 972 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 22 ms 1360 KB Output is correct
2 Correct 21 ms 1400 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 22 ms 1344 KB Output is correct
2 Correct 21 ms 1388 KB Output is correct
3 Correct 21 ms 1412 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 844 KB Output is correct
2 Correct 1 ms 844 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 40 ms 2372 KB Output is correct
2 Correct 37 ms 2496 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 45 ms 2552 KB Output is correct
2 Correct 39 ms 2580 KB Output is correct
3 Correct 41 ms 2500 KB Output is correct
4 Correct 39 ms 2464 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 48 ms 3124 KB Output is correct
2 Correct 51 ms 3152 KB Output is correct
3 Correct 42 ms 3152 KB Output is correct
4 Correct 51 ms 3108 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 29 ms 19908 KB Output is correct
2 Correct 28 ms 19908 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 51 ms 21648 KB Output is correct
2 Correct 62 ms 21644 KB Output is correct
3 Correct 77 ms 21644 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 108 ms 21744 KB Output is correct
2 Correct 399 ms 21740 KB Output is correct
3 Correct 226 ms 21884 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 272 ms 21648 KB Output is correct
2 Correct 539 ms 21740 KB Output is correct
3 Correct 296 ms 21744 KB Output is correct