제출 #904033

#제출 시각아이디문제언어결과실행 시간메모리
904033rainboyVera and Modern Art (CCO17_art)C11
25 / 25
528 ms32796 KiB
#include <stdio.h>

#define N	200000
#define Q	200000
#define M	(N * 2 + Q)
#define L	60	/* L = ceil(log2(10^18 + 1)) */

unsigned int X = 12345;

int rand_() {
	return (X *= 3) >> 1;
}

long long rev(long long a) {
	int l;
	long long b;

	b = 0;
	for (l = L - 1; l >= 0; l--)
		if ((a & 1LL << l) != 0)
			b |= 1LL << L - 1 - l;
	return b;
}

long long *ww;

void sort(int *hh, int l, int r) {
	while (l < r) {
		int i = l, j = l, k = r, h = hh[l + rand_() % (r - l)], tmp;

		while (j < k) {
			int c = ww[hh[j]] != ww[h] ? (ww[hh[j]] < ww[h] ? -1 : 1) : hh[j] - h;

			if (c == 0)
				j++;
			else if (c < 0) {
				tmp = hh[i], hh[i] = hh[j], hh[j] = tmp;
				i++, j++;
			} else {
				k--;
				tmp = hh[j], hh[j] = hh[k], hh[k] = tmp;
			}
		}
		sort(hh, l, i);
		l = k;
	}
}

int ft[M];

void update(int i, int n, int x) {
	while (i < n) {
		ft[i] += x;
		i |= i + 1;
	}
}

int query(int i) {
	int x = 0;

	while (i >= 0) {
		x += ft[i];
		i &= i + 1, i--;
	}
	return x;
}

int main() {
	static long long xx[M], yy[M];
	static int cc[N], hh[M], ans[Q];
	int n, m, q, h, h_, i, x;

	scanf("%d%d", &n, &q);
	for (i = 0; i < n; i++) {
		long long x, y, u, v;

		scanf("%lld%lld%d", &x, &y, &cc[i]), x = rev(x), y = rev(y), u = x & -x, v = y & -y;
		xx[i << 1 | 0] = x - u + 1, xx[i << 1 | 1] = x + u;
		yy[i << 1 | 0] = y - v + 1, yy[i << 1 | 1] = y + v;
	}
	for (h = 0; h < q; h++) {
		long long x, y;

		scanf("%lld%lld", &x, &y), x = rev(x), y = rev(y);
		xx[n * 2 + h] = x, yy[n * 2 + h] = y;
	}
	m = n * 2 + q;
	for (h = 0; h < m; h++)
		hh[h] = h;
	ww = xx, sort(hh, 0, m);
	for (h = 0, x = 0; h < m; h++)
		xx[hh[h]] = h + 1 == m || xx[hh[h + 1]] != xx[hh[h]] ? x++ : x;
	ww = yy, sort(hh, 0, m);
	for (h = 0; h < m; h++) {
		h_ = hh[h];
		if (h_ < n * 2) {
			i = h_ >> 1;
			update(xx[h_], m, cc[i]), update(xx[h_ ^ 1], m, -cc[i]);
		} else
			ans[h_ - n * 2] = query(xx[h_]);
	}
	for (h = 0; h < q; h++)
		printf("%d\n", ans[h]);
	return 0;
}

컴파일 시 표준 에러 (stderr) 메시지

Main.c: In function 'rev':
Main.c:21:22: warning: suggest parentheses around '-' inside '<<' [-Wparentheses]
   21 |    b |= 1LL << L - 1 - l;
      |                      ^
Main.c: In function 'main':
Main.c:73:2: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   73 |  scanf("%d%d", &n, &q);
      |  ^~~~~~~~~~~~~~~~~~~~~
Main.c:77:3: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   77 |   scanf("%lld%lld%d", &x, &y, &cc[i]), x = rev(x), y = rev(y), u = x & -x, v = y & -y;
      |   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Main.c:84:3: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   84 |   scanf("%lld%lld", &x, &y), x = rev(x), y = rev(y);
      |   ^~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...