Submission #130498

# Submission time Handle Problem Language Result Execution time Memory
130498 2019-07-15T11:08:15 Z imyujin Dominance (CEOI08_dominance) C++14
100 / 100
16 ms 552 KB
#include <stdio.h>
#include <algorithm>

using namespace std;

#define MAXN 3005

typedef long long lint;

struct QUERY {
	lint y, x1, x2;
	int z;
} que[2 * MAXN];

char C[MAXN];
lint A[MAXN], B[MAXN], R[MAXN];
lint xs[2 * MAXN], s[2 * MAXN];

int main() {
	int W, H, N;

	scanf("%d%d%d", &W, &H, &N);
	for(int i = 0; i < N; i++) scanf("\n%c%lld%lld%lld", C + i, A + i, B + i, R + i);

	for(int i = 0; i < N; i++) {
		xs[i * 2] = A[i] + B[i] - R[i];
		xs[i * 2 + 1] = A[i] + B[i] + R[i] + 1;
		que[i * 2] = (QUERY) { A[i] - B[i] - R[i], xs[i * 2], xs[i * 2 + 1], C[i] == 'W' ? 1 : -1 };
		que[i * 2 + 1] = (QUERY) { A[i] - B[i] + R[i] + 1, xs[i * 2], xs[i * 2 + 1], C[i] == 'W' ? -1 : 1 };
	}
	sort(xs, xs + 2 * N);
	int xn = unique(xs, xs + 2 * N) - xs;
	sort(que, que + 2 * N, [&](QUERY a, QUERY b) { return a.y < b.y; } );

	//for(int i = 0; i < 2 * N; i++) printf("que[%d] = { y = %lld, x1 = %lld, x2 = %lld, z = %d }\n", i, que[i].y, que[i].x1, que[i].x2, que[i].z);

	lint ansp = 0ll, ansm = 0ll;
	for(int i = 0; i < 2 * N - 1; i++) {
		int xidx1 = lower_bound(xs, xs + xn, que[i].x1) - xs;
		int xidx2 = lower_bound(xs, xs + xn, que[i].x2) - xs;
		for(int j = xidx1; j < xidx2; j++) s[j] += que[i].z;
		for(int j = 0; j < xn - 1; j++) {
			if(s[j] > 0) {
				ansp += (xs[j + 1] - xs[j]) * (que[i + 1].y - que[i].y) / 2;
				if((xs[j + 1] - xs[j]) % 2 != 0 && (que[i + 1].y - que[i].y) % 2 != 0 && (xs[j] - que[i].y) % 2 == 0) ansp++;
			}
			if(s[j] < 0) {
				ansm += (xs[j + 1] - xs[j]) * (que[i + 1].y - que[i].y) / 2;
				if((xs[j + 1] - xs[j]) % 2 != 0 && (que[i + 1].y - que[i].y) % 2 != 0 && (xs[j] - que[i].y) % 2 == 0) ansm++;
			}
		}
	}
	printf("%lld %lld", ansp, ansm);
	return 0;
}

Compilation message

dominance.cpp: In function 'int main()':
dominance.cpp:22:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d%d%d", &W, &H, &N);
  ~~~~~^~~~~~~~~~~~~~~~~~~~~~
dominance.cpp:23:34: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  for(int i = 0; i < N; i++) scanf("\n%c%lld%lld%lld", C + i, A + i, B + i, R + i);
                             ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 3 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 5 ms 376 KB Output is correct
5 Correct 5 ms 504 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 4 ms 376 KB Output is correct
9 Correct 7 ms 376 KB Output is correct
10 Correct 9 ms 376 KB Output is correct
11 Correct 9 ms 552 KB Output is correct
12 Correct 2 ms 256 KB Output is correct
13 Correct 7 ms 504 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 16 ms 504 KB Output is correct
16 Correct 8 ms 504 KB Output is correct
17 Correct 2 ms 376 KB Output is correct
18 Correct 2 ms 376 KB Output is correct
19 Correct 3 ms 376 KB Output is correct
20 Correct 3 ms 376 KB Output is correct