Submission #279713

# Submission time Handle Problem Language Result Execution time Memory
279713 2020-08-22T10:07:56 Z patrikpavic2 Pairs (IOI07_pairs) C++17
100 / 100
436 ms 12664 KB
#include <cstdio>
#include <cstring>
#include <vector>
#include <algorithm>

#define X first
#define Y second
#define PB push_back

using namespace std;

typedef long long ll;
typedef pair < int, int > pii;

const int N = 3e5 + 500;
const int OFF = 1e5 + 500;
const int M = 160;
const int OFF2 = 80;

int loga[N], B, n, m, D;
int Q[M][M][M], P[M][M][M];

inline int trans(int x){
	return max(min(x + OFF, N - 1), 0);
}

void add(int x, int y){
	x = trans(x);
	for(; x < N ; x += x & -x)
		loga[x] += y;
}

int query(int x){
	int ret = 0;
	x = trans(x);
	for(; x ; x -= x & -x)
		ret += loga[x];
	return ret;
}


int main(){
	scanf("%d%d%d%d", &B, &n, &D, &m);
	if(B == 1){
		vector < int > v;
		for(int i = 0;i < n;i++){
			int x; scanf("%d", &x);
			v.PB(x);
		}
		sort(v.begin(), v.end());
		int l = 0, r = 0, cur = 0;
		ll sol = 0;
		for(int i = 0;i < n;i++){
			while(v[i] - v[l] > D)
				cur--, l++;
			while(r < n && v[r] - v[i] <= D)
				cur++, r++;
			sol += cur;
		}
		printf("%lld\n", (sol - n) / 2);
	}
	if(B == 2){
		vector < pii > v;
		for(int i = 0;i < n;i++){
			int x, y; scanf("%d%d", &x, &y);
			v.PB({x + y, x - y});
		}
		sort(v.begin(), v.end());
		int l = 0, r = 0;
		ll sol = 0;
		for(int i = 0;i < n;i++){
			while(v[i].X - v[l].X > D)
				add(v[l++].Y, -1);
			while(r < n && v[r].X - v[i].X <= D)
				add(v[r++].Y, 1);
			sol += query(v[i].Y + D) - query(v[i].Y - D - 1);
		}
		printf("%lld\n", (sol - n) / 2);
	}
	if(B == 3){
		for(int i = 0;i < n;i++){
			int x, y, z; scanf("%d%d%d", &x, &y, &z);
			P[x][y][z]++;
			for(int k = 1;k <= 75;k++){
				int DD = D - abs(k - x);
				if(DD < 0) 
					continue;
				int y0 = (y - z - DD);
				int y1 = (y - z + DD);
				int z0 = (y + z - DD);
				int z1 = (y + z + DD);
				y0 += OFF2; y1 += OFF2;
				y0 = max(y0, 1);
				z0 = max(z0, 1);
				y1 = min(y1, M - 2);
				z1 = min(z1, M - 2);
				Q[k][y0][z0]++;	
				Q[k][y1 + 1][z0]--;
				Q[k][y0][z1 + 1]--;
				Q[k][y1 + 1][z1 + 1]++;
				//printf("na %d dodaj %d %d do %d %d\n", k, y0, z0, y1, z1);
			}
		}
		ll sol = 0;
		for(int k = 1;k <= 75;k++){
			for(int i = 1;i < M;i++)
				for(int j = 0;j < M;j++)
					Q[k][i][j] += Q[k][i - 1][j];
			for(int i = 0;i < M;i++)
				for(int j = 1;j < M;j++)
					Q[k][i][j] += Q[k][i][j - 1];
			for(int i = 1;i <= 75;i++){
				for(int j = 1;j <= 75;j++){
					sol += P[k][i][j] * Q[k][i - j + OFF2][i + j]; 
				}
			}
		}
		printf("%lld\n", (sol - n) / 2);
	}
	return 0;
}

Compilation message

pairs.cpp: In function 'int main()':
pairs.cpp:43:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   43 |  scanf("%d%d%d%d", &B, &n, &D, &m);
      |  ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
pairs.cpp:47:16: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   47 |    int x; scanf("%d", &x);
      |           ~~~~~^~~~~~~~~~
pairs.cpp:65:19: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   65 |    int x, y; scanf("%d%d", &x, &y);
      |              ~~~~~^~~~~~~~~~~~~~~~
pairs.cpp:82:22: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   82 |    int x, y, z; scanf("%d%d%d", &x, &y, &z);
      |                 ~~~~~^~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 256 KB Output is correct
2 Correct 0 ms 256 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 416 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 20 ms 1396 KB Output is correct
2 Correct 21 ms 1404 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 31 ms 1532 KB Output is correct
2 Correct 28 ms 1532 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 33 ms 1532 KB Output is correct
2 Correct 28 ms 1532 KB Output is correct
3 Correct 25 ms 1532 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 896 KB Output is correct
2 Correct 1 ms 896 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 39 ms 2040 KB Output is correct
2 Correct 37 ms 2040 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 45 ms 2168 KB Output is correct
2 Correct 44 ms 2168 KB Output is correct
3 Correct 45 ms 2168 KB Output is correct
4 Correct 43 ms 2048 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 49 ms 2924 KB Output is correct
2 Correct 49 ms 3196 KB Output is correct
3 Correct 56 ms 2924 KB Output is correct
4 Correct 47 ms 2924 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 15 ms 10368 KB Output is correct
2 Correct 14 ms 10368 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 51 ms 8600 KB Output is correct
2 Correct 64 ms 8568 KB Output is correct
3 Correct 87 ms 8568 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 122 ms 11512 KB Output is correct
2 Correct 365 ms 11512 KB Output is correct
3 Correct 158 ms 11384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 314 ms 12664 KB Output is correct
2 Correct 436 ms 12536 KB Output is correct
3 Correct 146 ms 12536 KB Output is correct