답안 #381136

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
381136 2021-03-24T16:13:03 Z rainboy 새 집 (APIO18_new_home) C
12 / 100
5000 ms 1048576 KB
#include <stdio.h>

#define N	300000
#define Q	300000
#define M	(N * 2 + Q)
#define K	400
#define INF	0x3f3f3f3f

int min(int a, int b) { return a < b ? a : b; }
int max(int a, int b) { return a > b ? a : b; }

unsigned int X = 12345;

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

int xx[N], tt[M], n;

int compare(int h1, int h2) {
	int type1, type2;

	if (tt[h1] != tt[h2])
		return tt[h1] - tt[h2];
	type1 = h1 < n * 2 ? ((h1 & 1) == 0 ? 1 : -1) : 0;
	type2 = h2 < n * 2 ? ((h2 & 1) == 0 ? 1 : -1) : 0;
	return type2 - type1;
}

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 = compare(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 zz[1 + N], ll[1 + N], rr[1 + N], ii_[1 + N], u_, l_, r_;

int node(int i) {
	static int _ = 1;

	zz[_] = rand_();
	ii_[_] = i;
	return _++;
}

void split(int u, int i) {
	int c;

	if (u == 0) {
		u_ = l_ = r_ = 0;
		return;
	}
	c = xx[ii_[u]] != xx[i] ? xx[ii_[u]] - xx[i] : ii_[u] - i;
	if (c < 0) {
		split(rr[u], i);
		rr[u] = l_, l_ = u;
	} else if (c > 0) {
		split(ll[u], i);
		ll[u] = r_, r_ = u;
	} else {
		u_ = u, l_ = ll[u], r_ = rr[u];
		ll[u] = rr[u] = 0;
	}
}

int merge(int u, int v) {
	if (u == 0)
		return v;
	if (v == 0)
		return u;
	if (zz[u] < zz[v]) {
		rr[u] = merge(rr[u], v);
		return u;
	} else {
		ll[v] = merge(u, ll[v]);
		return v;
	}
}

int tr_update(int u, int i) {
	split(u, i);
	return merge(merge(l_, u_ == 0 ? node(i) : 0), r_);
}

int query(int u, int x) {
	int d;

	d = INF;
	while (u)
		if (xx[ii_[u]] < x)
			d = min(d, x - xx[ii_[u]]), u = rr[u];
		else
			d = min(d, xx[ii_[u]] - x), u = ll[u];
	return d;
}

int main() {
	static int gg[N], hh[M], xx_[Q], tr[K], ans[Q];
	int q, m, k, g, h, i;

	scanf("%d%d%d", &n, &k, &q);
	for (i = 0; i < n; i++)
		scanf("%d%d%d%d", &xx[i], &gg[i], &tt[i << 1 | 0], &tt[i << 1 | 1]), gg[i]--;
	for (h = 0; h < q; h++)
		scanf("%d%d", &xx_[h], &tt[n * 2 + h]);
	m = n * 2 + q;
	for (h = 0; h < m; h++)
		hh[h] = h;
	sort(hh, 0, m);
	for (h = 0; h < m; h++) {
		int h_ = hh[h];

		if (h_ >= n * 2) {
			h_ -= n * 2;
			for (g = 0; g < k; g++)
				ans[h_] = max(ans[h_], query(tr[g], xx_[h_]));
			if (ans[h_] == INF)
				ans[h_] = -1;
		} else {
			i = h_ >> 1;
			tr[gg[i]] = tr_update(tr[gg[i]], i);
		}
	}
	for (h = 0; h < q; h++)
		printf("%d\n", ans[h]);
	return 0;
}

Compilation message

new_home.c: In function 'main':
new_home.c:117:2: warning: ignoring return value of 'scanf', declared with attribute warn_unused_result [-Wunused-result]
  117 |  scanf("%d%d%d", &n, &k, &q);
      |  ^~~~~~~~~~~~~~~~~~~~~~~~~~~
new_home.c:119:3: warning: ignoring return value of 'scanf', declared with attribute warn_unused_result [-Wunused-result]
  119 |   scanf("%d%d%d%d", &xx[i], &gg[i], &tt[i << 1 | 0], &tt[i << 1 | 1]), gg[i]--;
      |   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
new_home.c:121:3: warning: ignoring return value of 'scanf', declared with attribute warn_unused_result [-Wunused-result]
  121 |   scanf("%d%d", &xx_[h], &tt[n * 2 + h]);
      |   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 2 ms 364 KB Output is correct
6 Correct 2 ms 384 KB Output is correct
7 Correct 3 ms 384 KB Output is correct
8 Correct 3 ms 364 KB Output is correct
9 Correct 2 ms 412 KB Output is correct
10 Correct 2 ms 364 KB Output is correct
11 Correct 2 ms 384 KB Output is correct
12 Correct 2 ms 384 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 2 ms 364 KB Output is correct
16 Correct 3 ms 364 KB Output is correct
17 Correct 2 ms 364 KB Output is correct
18 Correct 2 ms 364 KB Output is correct
19 Correct 2 ms 448 KB Output is correct
20 Correct 2 ms 364 KB Output is correct
21 Correct 2 ms 364 KB Output is correct
22 Correct 3 ms 496 KB Output is correct
23 Correct 3 ms 364 KB Output is correct
24 Correct 2 ms 364 KB Output is correct
25 Correct 2 ms 492 KB Output is correct
26 Correct 2 ms 364 KB Output is correct
27 Correct 2 ms 364 KB Output is correct
28 Correct 2 ms 492 KB Output is correct
29 Correct 4 ms 492 KB Output is correct
30 Correct 2 ms 364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 2 ms 364 KB Output is correct
6 Correct 2 ms 384 KB Output is correct
7 Correct 3 ms 384 KB Output is correct
8 Correct 3 ms 364 KB Output is correct
9 Correct 2 ms 412 KB Output is correct
10 Correct 2 ms 364 KB Output is correct
11 Correct 2 ms 384 KB Output is correct
12 Correct 2 ms 384 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 2 ms 364 KB Output is correct
16 Correct 3 ms 364 KB Output is correct
17 Correct 2 ms 364 KB Output is correct
18 Correct 2 ms 364 KB Output is correct
19 Correct 2 ms 448 KB Output is correct
20 Correct 2 ms 364 KB Output is correct
21 Correct 2 ms 364 KB Output is correct
22 Correct 3 ms 496 KB Output is correct
23 Correct 3 ms 364 KB Output is correct
24 Correct 2 ms 364 KB Output is correct
25 Correct 2 ms 492 KB Output is correct
26 Correct 2 ms 364 KB Output is correct
27 Correct 2 ms 364 KB Output is correct
28 Correct 2 ms 492 KB Output is correct
29 Correct 4 ms 492 KB Output is correct
30 Correct 2 ms 364 KB Output is correct
31 Correct 4260 ms 7028 KB Output is correct
32 Correct 174 ms 4716 KB Output is correct
33 Correct 349 ms 6848 KB Output is correct
34 Correct 2912 ms 7108 KB Output is correct
35 Correct 2016 ms 6972 KB Output is correct
36 Correct 429 ms 6840 KB Output is correct
37 Correct 296 ms 6992 KB Output is correct
38 Correct 199 ms 6840 KB Output is correct
39 Correct 152 ms 6896 KB Output is correct
40 Correct 134 ms 6912 KB Output is correct
41 Correct 307 ms 7148 KB Output is correct
42 Correct 400 ms 6912 KB Output is correct
43 Correct 693 ms 6484 KB Output is correct
44 Correct 296 ms 7104 KB Output is correct
45 Correct 142 ms 7148 KB Output is correct
46 Correct 114 ms 7068 KB Output is correct
47 Correct 102 ms 6636 KB Output is correct
48 Correct 91 ms 6584 KB Output is correct
49 Correct 126 ms 6732 KB Output is correct
50 Correct 251 ms 6908 KB Output is correct
51 Correct 117 ms 6800 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1027 ms 1048576 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 427 ms 34924 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 2 ms 364 KB Output is correct
6 Correct 2 ms 384 KB Output is correct
7 Correct 3 ms 384 KB Output is correct
8 Correct 3 ms 364 KB Output is correct
9 Correct 2 ms 412 KB Output is correct
10 Correct 2 ms 364 KB Output is correct
11 Correct 2 ms 384 KB Output is correct
12 Correct 2 ms 384 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 2 ms 364 KB Output is correct
16 Correct 3 ms 364 KB Output is correct
17 Correct 2 ms 364 KB Output is correct
18 Correct 2 ms 364 KB Output is correct
19 Correct 2 ms 448 KB Output is correct
20 Correct 2 ms 364 KB Output is correct
21 Correct 2 ms 364 KB Output is correct
22 Correct 3 ms 496 KB Output is correct
23 Correct 3 ms 364 KB Output is correct
24 Correct 2 ms 364 KB Output is correct
25 Correct 2 ms 492 KB Output is correct
26 Correct 2 ms 364 KB Output is correct
27 Correct 2 ms 364 KB Output is correct
28 Correct 2 ms 492 KB Output is correct
29 Correct 4 ms 492 KB Output is correct
30 Correct 2 ms 364 KB Output is correct
31 Correct 4260 ms 7028 KB Output is correct
32 Correct 174 ms 4716 KB Output is correct
33 Correct 349 ms 6848 KB Output is correct
34 Correct 2912 ms 7108 KB Output is correct
35 Correct 2016 ms 6972 KB Output is correct
36 Correct 429 ms 6840 KB Output is correct
37 Correct 296 ms 6992 KB Output is correct
38 Correct 199 ms 6840 KB Output is correct
39 Correct 152 ms 6896 KB Output is correct
40 Correct 134 ms 6912 KB Output is correct
41 Correct 307 ms 7148 KB Output is correct
42 Correct 400 ms 6912 KB Output is correct
43 Correct 693 ms 6484 KB Output is correct
44 Correct 296 ms 7104 KB Output is correct
45 Correct 142 ms 7148 KB Output is correct
46 Correct 114 ms 7068 KB Output is correct
47 Correct 102 ms 6636 KB Output is correct
48 Correct 91 ms 6584 KB Output is correct
49 Correct 126 ms 6732 KB Output is correct
50 Correct 251 ms 6908 KB Output is correct
51 Correct 117 ms 6800 KB Output is correct
52 Execution timed out 5035 ms 7488 KB Time limit exceeded
53 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 2 ms 364 KB Output is correct
6 Correct 2 ms 384 KB Output is correct
7 Correct 3 ms 384 KB Output is correct
8 Correct 3 ms 364 KB Output is correct
9 Correct 2 ms 412 KB Output is correct
10 Correct 2 ms 364 KB Output is correct
11 Correct 2 ms 384 KB Output is correct
12 Correct 2 ms 384 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 2 ms 364 KB Output is correct
16 Correct 3 ms 364 KB Output is correct
17 Correct 2 ms 364 KB Output is correct
18 Correct 2 ms 364 KB Output is correct
19 Correct 2 ms 448 KB Output is correct
20 Correct 2 ms 364 KB Output is correct
21 Correct 2 ms 364 KB Output is correct
22 Correct 3 ms 496 KB Output is correct
23 Correct 3 ms 364 KB Output is correct
24 Correct 2 ms 364 KB Output is correct
25 Correct 2 ms 492 KB Output is correct
26 Correct 2 ms 364 KB Output is correct
27 Correct 2 ms 364 KB Output is correct
28 Correct 2 ms 492 KB Output is correct
29 Correct 4 ms 492 KB Output is correct
30 Correct 2 ms 364 KB Output is correct
31 Correct 4260 ms 7028 KB Output is correct
32 Correct 174 ms 4716 KB Output is correct
33 Correct 349 ms 6848 KB Output is correct
34 Correct 2912 ms 7108 KB Output is correct
35 Correct 2016 ms 6972 KB Output is correct
36 Correct 429 ms 6840 KB Output is correct
37 Correct 296 ms 6992 KB Output is correct
38 Correct 199 ms 6840 KB Output is correct
39 Correct 152 ms 6896 KB Output is correct
40 Correct 134 ms 6912 KB Output is correct
41 Correct 307 ms 7148 KB Output is correct
42 Correct 400 ms 6912 KB Output is correct
43 Correct 693 ms 6484 KB Output is correct
44 Correct 296 ms 7104 KB Output is correct
45 Correct 142 ms 7148 KB Output is correct
46 Correct 114 ms 7068 KB Output is correct
47 Correct 102 ms 6636 KB Output is correct
48 Correct 91 ms 6584 KB Output is correct
49 Correct 126 ms 6732 KB Output is correct
50 Correct 251 ms 6908 KB Output is correct
51 Correct 117 ms 6800 KB Output is correct
52 Runtime error 1027 ms 1048576 KB Execution killed with signal 9
53 Halted 0 ms 0 KB -