답안 #491093

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
491093 2021-11-30T13:58:20 Z rainboy Tenis (COI19_tenis) C
100 / 100
95 ms 10056 KB
#include <stdio.h>
#include <string.h>

#define N	100000
#define N_	(1 << 17)	/* N_ = pow2(ceil(log2(N))) */

long long sum[N_ * 2], pref[N_ * 2]; int ii[N_ * 2], n_;

void pul(int i) {
	int l = i << 1, r = l | 1;

	sum[i] = sum[l] + sum[r];
	if (pref[l] <= sum[l] + pref[r])
		pref[i] = pref[l], ii[i] = ii[l];
	else
		pref[i] = sum[l] + pref[r], ii[i] = ii[r];
}

void build(int *aa, int *yy, int *zz, int n) {
	int i;

	n_ = 1;
	while (n_ < n)
		n_ <<= 1;
	for (i = 0; i < n_; i++)
		pref[n_ + i] = sum[n_ + i] = i < n ? yy[aa[i]] + zz[aa[i]] - i * 2 : 0, ii[n_ + i] = i;
	for (i = n_ - 1; i > 0; i--)
		pul(i);
}

void update(int i, int x) {
	i += n_;
	pref[i] = sum[i] = x;
	while (i > 1)
		pul(i >>= 1);
}

int main() {
	static int aa[N], xx[N], yy[N], zz[N];
	int n, q, i, j, a, b;

	scanf("%d%d", &n, &q);
	for (i = 0; i < n; i++) {
		scanf("%d", &aa[i]), aa[i]--;
		xx[aa[i]] = i;
	}
	for (i = 0; i < n; i++) {
		scanf("%d", &a), a--;
		yy[a] = i;
	}
	for (i = 0; i < n; i++) {
		scanf("%d", &a), a--;
		zz[a] = i;
	}
	build(aa, yy, zz, n);
	while (q--) {
		int t;

		scanf("%d", &t);
		if (t == 1) {
			scanf("%d", &a), a--;
			printf(xx[a] <= ii[1] ? "DA\n" : "NE\n");
		} else {
			int tmp;

			scanf("%d%d%d", &t, &a, &b), a--, b--;
			if (t == 1) {
				i = xx[a], j = xx[b];
				xx[a] = j, xx[b] = i;
				update(xx[a], yy[a] + zz[a] - xx[a] * 2), update(xx[b], yy[b] + zz[b] - xx[b] * 2);
			} else if (t == 2) {
				tmp = yy[a], yy[a] = yy[b], yy[b] = tmp;
				update(xx[a], yy[a] + zz[a] - xx[a] * 2), update(xx[b], yy[b] + zz[b] - xx[b] * 2);
			} else {
				tmp = zz[a], zz[a] = zz[b], zz[b] = tmp;
				update(xx[a], yy[a] + zz[a] - xx[a] * 2), update(xx[b], yy[b] + zz[b] - xx[b] * 2);
			}
		}
	}
	return 0;
}

Compilation message

tenis.c: In function 'main':
tenis.c:42:2: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   42 |  scanf("%d%d", &n, &q);
      |  ^~~~~~~~~~~~~~~~~~~~~
tenis.c:44:3: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   44 |   scanf("%d", &aa[i]), aa[i]--;
      |   ^~~~~~~~~~~~~~~~~~~
tenis.c:48:3: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   48 |   scanf("%d", &a), a--;
      |   ^~~~~~~~~~~~~~~
tenis.c:52:3: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   52 |   scanf("%d", &a), a--;
      |   ^~~~~~~~~~~~~~~
tenis.c:59:3: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   59 |   scanf("%d", &t);
      |   ^~~~~~~~~~~~~~~
tenis.c:61:4: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   61 |    scanf("%d", &a), a--;
      |    ^~~~~~~~~~~~~~~
tenis.c:66:4: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   66 |    scanf("%d%d%d", &t, &a, &b), a--, b--;
      |    ^~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 288 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 288 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 296 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 288 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 296 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 33 ms 6996 KB Output is correct
14 Correct 31 ms 6988 KB Output is correct
15 Correct 34 ms 6980 KB Output is correct
16 Correct 32 ms 6956 KB Output is correct
17 Correct 37 ms 6956 KB Output is correct
18 Correct 35 ms 6932 KB Output is correct
19 Correct 35 ms 7120 KB Output is correct
20 Correct 38 ms 8588 KB Output is correct
21 Correct 33 ms 8620 KB Output is correct
22 Correct 34 ms 8656 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 57 ms 7348 KB Output is correct
2 Correct 60 ms 7304 KB Output is correct
3 Correct 58 ms 7240 KB Output is correct
4 Correct 57 ms 7256 KB Output is correct
5 Correct 57 ms 7268 KB Output is correct
6 Correct 58 ms 7312 KB Output is correct
7 Correct 55 ms 7304 KB Output is correct
8 Correct 55 ms 7316 KB Output is correct
9 Correct 55 ms 7236 KB Output is correct
10 Correct 56 ms 7364 KB Output is correct
11 Correct 61 ms 7284 KB Output is correct
12 Correct 56 ms 7228 KB Output is correct
13 Correct 56 ms 7336 KB Output is correct
14 Correct 60 ms 7316 KB Output is correct
15 Correct 58 ms 7308 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 288 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 296 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 33 ms 6996 KB Output is correct
14 Correct 31 ms 6988 KB Output is correct
15 Correct 34 ms 6980 KB Output is correct
16 Correct 32 ms 6956 KB Output is correct
17 Correct 37 ms 6956 KB Output is correct
18 Correct 35 ms 6932 KB Output is correct
19 Correct 35 ms 7120 KB Output is correct
20 Correct 38 ms 8588 KB Output is correct
21 Correct 33 ms 8620 KB Output is correct
22 Correct 34 ms 8656 KB Output is correct
23 Correct 57 ms 7348 KB Output is correct
24 Correct 60 ms 7304 KB Output is correct
25 Correct 58 ms 7240 KB Output is correct
26 Correct 57 ms 7256 KB Output is correct
27 Correct 57 ms 7268 KB Output is correct
28 Correct 58 ms 7312 KB Output is correct
29 Correct 55 ms 7304 KB Output is correct
30 Correct 55 ms 7316 KB Output is correct
31 Correct 55 ms 7236 KB Output is correct
32 Correct 56 ms 7364 KB Output is correct
33 Correct 61 ms 7284 KB Output is correct
34 Correct 56 ms 7228 KB Output is correct
35 Correct 56 ms 7336 KB Output is correct
36 Correct 60 ms 7316 KB Output is correct
37 Correct 58 ms 7308 KB Output is correct
38 Correct 89 ms 9944 KB Output is correct
39 Correct 66 ms 9788 KB Output is correct
40 Correct 95 ms 10056 KB Output is correct
41 Correct 84 ms 9888 KB Output is correct
42 Correct 73 ms 9892 KB Output is correct
43 Correct 84 ms 10012 KB Output is correct
44 Correct 81 ms 9744 KB Output is correct
45 Correct 87 ms 9868 KB Output is correct
46 Correct 65 ms 9796 KB Output is correct
47 Correct 82 ms 9848 KB Output is correct
48 Correct 69 ms 9748 KB Output is correct
49 Correct 70 ms 9808 KB Output is correct
50 Correct 67 ms 9932 KB Output is correct
51 Correct 80 ms 9880 KB Output is correct
52 Correct 82 ms 10012 KB Output is correct
53 Correct 67 ms 9856 KB Output is correct
54 Correct 73 ms 9884 KB Output is correct
55 Correct 86 ms 9924 KB Output is correct
56 Correct 76 ms 9876 KB Output is correct
57 Correct 72 ms 9880 KB Output is correct
58 Correct 83 ms 9796 KB Output is correct