답안 #810638

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
810638 2023-08-06T13:08:08 Z rainboy Sličnost (COI23_slicnost) C
100 / 100
1597 ms 422484 KB
#include <stdio.h>

#define N	100000
#define LN	17	/* LN = ceil(log2(N)) */
#define N_	(1 << LN)
#define N1	(N * 2 + (N * 4 + Q * 8) * (LN + 1) + 1)
#define Q	100000

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

int ll[N1], rr[N1], ss[N1], pr[N1], kk[N1], _ = 1;

int build(int l, int r) {
	int t_ = _++;

	ss[t_] = 0, pr[t_] = 0, kk[t_] = r - l;
	if (r - l > 1) {
		int m = (l + r) / 2;

		ll[t_] = build(l, m), rr[t_] = build(m, r);
	}
	return t_;
}

void pul(int t) {
	int l = ll[t], r = rr[t];

	ss[t] = ss[l] + ss[r];
	if (pr[l] > ss[l] + pr[r])
		pr[t] = pr[l], kk[t] = kk[l];
	else if (pr[l] < ss[l] + pr[r])
		pr[t] = ss[l] + pr[r], kk[t] = kk[r];
	else
		pr[t] = pr[l], kk[t] = kk[l] + kk[r];
}

int update(int t, int l, int r, int i, int x) {
	int t_ = _++;

	if (r - l > 1) {
		int m = (l + r) / 2;

		if (i < m)
			ll[t_] = update(ll[t], l, m, i, x), rr[t_] = rr[t];
		else
			ll[t_] = ll[t], rr[t_] = update(rr[t], m, r, i, x);
		pul(t_);
	} else
		ll[t_] = ll[t], rr[t_] = rr[t], pr[t_] = ss[t_] = ss[t] + x, kk[t_] = 1;
	return t_;
}

int tt[N], n, k;

int mx[N_ * 2], n_; long long kk_[N_ * 2];

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

	if (mx[l] > mx[r])
		mx[i] = mx[l], kk_[i] = kk_[l];
	else if (mx[l] < mx[r])
		mx[i] = mx[r], kk_[i] = kk_[r];
	else
		mx[i] = mx[l], kk_[i] = kk_[l] + kk_[r];
}

void build_() {
	int i;

	n_ = 1;
	while (n_ < n - k + 1)
		n_ <<= 1;
	for (i = 0; i < n_; i++)
		if (i < n - k + 1)
			mx[n_ + i] = pr[tt[i]], kk_[n_ + i] = kk[tt[i]];
		else
			mx[n_ + i] = 0, kk_[n_ + i] = 0;
	for (i = n_ - 1; i > 0; i--)
		pul_(i);
}

void update_(int i, int j, int x) {
	tt[i] = update(tt[i], 0, n - k + 1, j, x);
	mx[n_ + i] = pr[tt[i]], kk_[n_ + i] = kk[tt[i]];
	i += n_;
	while (i > 1)
		pul_(i >>= 1);
}

int main() {
	static int aa[N], jj[N];
	int q, i, j, a, b, t;

	scanf("%d%d%d", &n, &k, &q);
	for (i = 0; i < n; i++)
		scanf("%d", &aa[i]), aa[i]--;
	for (j = 0; j < n; j++) {
		scanf("%d", &a), a--;
		jj[a] = j;
	}
	t = build(0, n - k + 1);
	for (i = 0; i < n; i++) {
		a = aa[i], j = jj[a];
		t = update(t, 0, n - k + 1, max(j - k + 1, 0), 1);
		if (j + k < n)
			t = update(t, 0, n - k + 1, j + 1, -1);
		if (i >= k - 1) {
			tt[i - k + 1] = t;
			a = aa[i - k + 1], j = jj[a];
			t = update(t, 0, n - k + 1, max(j - k + 1, 0), -1);
			if (j + k < n)
				t = update(t, 0, n - k + 1, j + 1, 1);
		}
	}
	build_();
	printf("%d %lld\n", mx[1], kk_[1]);
	while (q--) {
		scanf("%d", &i), i--;
		a = aa[i], b = aa[i + 1];
		aa[i] = b, aa[i + 1] = a;
		if (i >= k - 1) {
			j = jj[a];
			update_(i - k + 1, max(j - k + 1, 0), -1);
			if (j + k < n)
				update_(i - k + 1, j + 1, 1);
			j = jj[b];
			update_(i - k + 1, max(j - k + 1, 0), 1);
			if (j + k < n)
				update_(i - k + 1, j + 1, -1);
		}
		if (i + k < n) {
			j = jj[a];
			update_(i + 1, max(j - k + 1, 0), 1);
			if (j + k < n)
				update_(i + 1, j + 1, -1);
			j = jj[b];
			update_(i + 1, max(j - k + 1, 0), -1);
			if (j + k < n)
				update_(i + 1, j + 1, 1);
		}
		printf("%d %lld\n", mx[1], kk_[1]);
	}
	return 0;
}

Compilation message

Main.c: In function 'main':
Main.c:95:2: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   95 |  scanf("%d%d%d", &n, &k, &q);
      |  ^~~~~~~~~~~~~~~~~~~~~~~~~~~
Main.c:97:3: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   97 |   scanf("%d", &aa[i]), aa[i]--;
      |   ^~~~~~~~~~~~~~~~~~~
Main.c:99:3: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   99 |   scanf("%d", &a), a--;
      |   ^~~~~~~~~~~~~~~
Main.c:119:3: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
  119 |   scanf("%d", &i), i--;
      |   ^~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 0 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 0 ms 340 KB Output is correct
15 Correct 0 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 0 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 0 ms 340 KB Output is correct
15 Correct 0 ms 340 KB Output is correct
16 Correct 6 ms 5836 KB Output is correct
17 Correct 6 ms 5844 KB Output is correct
18 Correct 1 ms 468 KB Output is correct
19 Correct 4 ms 3156 KB Output is correct
20 Correct 8 ms 5844 KB Output is correct
21 Correct 5 ms 5572 KB Output is correct
22 Correct 2 ms 1380 KB Output is correct
23 Correct 7 ms 5596 KB Output is correct
24 Correct 6 ms 5716 KB Output is correct
25 Correct 5 ms 3668 KB Output is correct
26 Correct 5 ms 4180 KB Output is correct
27 Correct 7 ms 5304 KB Output is correct
28 Correct 4 ms 3328 KB Output is correct
29 Correct 4 ms 2644 KB Output is correct
30 Correct 2 ms 1364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 0 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 0 ms 340 KB Output is correct
15 Correct 0 ms 340 KB Output is correct
16 Correct 6 ms 5836 KB Output is correct
17 Correct 6 ms 5844 KB Output is correct
18 Correct 1 ms 468 KB Output is correct
19 Correct 4 ms 3156 KB Output is correct
20 Correct 8 ms 5844 KB Output is correct
21 Correct 5 ms 5572 KB Output is correct
22 Correct 2 ms 1380 KB Output is correct
23 Correct 7 ms 5596 KB Output is correct
24 Correct 6 ms 5716 KB Output is correct
25 Correct 5 ms 3668 KB Output is correct
26 Correct 5 ms 4180 KB Output is correct
27 Correct 7 ms 5304 KB Output is correct
28 Correct 4 ms 3328 KB Output is correct
29 Correct 4 ms 2644 KB Output is correct
30 Correct 2 ms 1364 KB Output is correct
31 Correct 217 ms 144296 KB Output is correct
32 Correct 233 ms 143224 KB Output is correct
33 Correct 16 ms 3964 KB Output is correct
34 Correct 137 ms 76376 KB Output is correct
35 Correct 309 ms 147028 KB Output is correct
36 Correct 129 ms 135472 KB Output is correct
37 Correct 36 ms 30540 KB Output is correct
38 Correct 275 ms 140356 KB Output is correct
39 Correct 147 ms 146236 KB Output is correct
40 Correct 163 ms 89252 KB Output is correct
41 Correct 220 ms 103752 KB Output is correct
42 Correct 268 ms 131368 KB Output is correct
43 Correct 151 ms 80716 KB Output is correct
44 Correct 137 ms 65872 KB Output is correct
45 Correct 44 ms 31548 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 0 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 0 ms 340 KB Output is correct
15 Correct 0 ms 340 KB Output is correct
16 Correct 1 ms 468 KB Output is correct
17 Correct 1 ms 468 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 0 ms 340 KB Output is correct
20 Correct 1 ms 468 KB Output is correct
21 Correct 0 ms 340 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 1 ms 468 KB Output is correct
24 Correct 0 ms 468 KB Output is correct
25 Correct 0 ms 340 KB Output is correct
26 Correct 1 ms 420 KB Output is correct
27 Correct 1 ms 468 KB Output is correct
28 Correct 0 ms 340 KB Output is correct
29 Correct 1 ms 416 KB Output is correct
30 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 0 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 0 ms 340 KB Output is correct
15 Correct 0 ms 340 KB Output is correct
16 Correct 6 ms 5836 KB Output is correct
17 Correct 6 ms 5844 KB Output is correct
18 Correct 1 ms 468 KB Output is correct
19 Correct 4 ms 3156 KB Output is correct
20 Correct 8 ms 5844 KB Output is correct
21 Correct 5 ms 5572 KB Output is correct
22 Correct 2 ms 1380 KB Output is correct
23 Correct 7 ms 5596 KB Output is correct
24 Correct 6 ms 5716 KB Output is correct
25 Correct 5 ms 3668 KB Output is correct
26 Correct 5 ms 4180 KB Output is correct
27 Correct 7 ms 5304 KB Output is correct
28 Correct 4 ms 3328 KB Output is correct
29 Correct 4 ms 2644 KB Output is correct
30 Correct 2 ms 1364 KB Output is correct
31 Correct 1 ms 468 KB Output is correct
32 Correct 1 ms 468 KB Output is correct
33 Correct 1 ms 340 KB Output is correct
34 Correct 0 ms 340 KB Output is correct
35 Correct 1 ms 468 KB Output is correct
36 Correct 0 ms 340 KB Output is correct
37 Correct 1 ms 340 KB Output is correct
38 Correct 1 ms 468 KB Output is correct
39 Correct 0 ms 468 KB Output is correct
40 Correct 0 ms 340 KB Output is correct
41 Correct 1 ms 420 KB Output is correct
42 Correct 1 ms 468 KB Output is correct
43 Correct 0 ms 340 KB Output is correct
44 Correct 1 ms 416 KB Output is correct
45 Correct 1 ms 340 KB Output is correct
46 Correct 20 ms 16084 KB Output is correct
47 Correct 24 ms 16296 KB Output is correct
48 Correct 2 ms 468 KB Output is correct
49 Correct 10 ms 6704 KB Output is correct
50 Correct 25 ms 16088 KB Output is correct
51 Correct 4 ms 2516 KB Output is correct
52 Correct 12 ms 9648 KB Output is correct
53 Correct 24 ms 15516 KB Output is correct
54 Correct 23 ms 15572 KB Output is correct
55 Correct 8 ms 6480 KB Output is correct
56 Correct 34 ms 15564 KB Output is correct
57 Correct 31 ms 15212 KB Output is correct
58 Correct 6 ms 3540 KB Output is correct
59 Correct 17 ms 11092 KB Output is correct
60 Correct 5 ms 3240 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 0 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 0 ms 340 KB Output is correct
15 Correct 0 ms 340 KB Output is correct
16 Correct 6 ms 5836 KB Output is correct
17 Correct 6 ms 5844 KB Output is correct
18 Correct 1 ms 468 KB Output is correct
19 Correct 4 ms 3156 KB Output is correct
20 Correct 8 ms 5844 KB Output is correct
21 Correct 5 ms 5572 KB Output is correct
22 Correct 2 ms 1380 KB Output is correct
23 Correct 7 ms 5596 KB Output is correct
24 Correct 6 ms 5716 KB Output is correct
25 Correct 5 ms 3668 KB Output is correct
26 Correct 5 ms 4180 KB Output is correct
27 Correct 7 ms 5304 KB Output is correct
28 Correct 4 ms 3328 KB Output is correct
29 Correct 4 ms 2644 KB Output is correct
30 Correct 2 ms 1364 KB Output is correct
31 Correct 217 ms 144296 KB Output is correct
32 Correct 233 ms 143224 KB Output is correct
33 Correct 16 ms 3964 KB Output is correct
34 Correct 137 ms 76376 KB Output is correct
35 Correct 309 ms 147028 KB Output is correct
36 Correct 129 ms 135472 KB Output is correct
37 Correct 36 ms 30540 KB Output is correct
38 Correct 275 ms 140356 KB Output is correct
39 Correct 147 ms 146236 KB Output is correct
40 Correct 163 ms 89252 KB Output is correct
41 Correct 220 ms 103752 KB Output is correct
42 Correct 268 ms 131368 KB Output is correct
43 Correct 151 ms 80716 KB Output is correct
44 Correct 137 ms 65872 KB Output is correct
45 Correct 44 ms 31548 KB Output is correct
46 Correct 1 ms 468 KB Output is correct
47 Correct 1 ms 468 KB Output is correct
48 Correct 1 ms 340 KB Output is correct
49 Correct 0 ms 340 KB Output is correct
50 Correct 1 ms 468 KB Output is correct
51 Correct 0 ms 340 KB Output is correct
52 Correct 1 ms 340 KB Output is correct
53 Correct 1 ms 468 KB Output is correct
54 Correct 0 ms 468 KB Output is correct
55 Correct 0 ms 340 KB Output is correct
56 Correct 1 ms 420 KB Output is correct
57 Correct 1 ms 468 KB Output is correct
58 Correct 0 ms 340 KB Output is correct
59 Correct 1 ms 416 KB Output is correct
60 Correct 1 ms 340 KB Output is correct
61 Correct 20 ms 16084 KB Output is correct
62 Correct 24 ms 16296 KB Output is correct
63 Correct 2 ms 468 KB Output is correct
64 Correct 10 ms 6704 KB Output is correct
65 Correct 25 ms 16088 KB Output is correct
66 Correct 4 ms 2516 KB Output is correct
67 Correct 12 ms 9648 KB Output is correct
68 Correct 24 ms 15516 KB Output is correct
69 Correct 23 ms 15572 KB Output is correct
70 Correct 8 ms 6480 KB Output is correct
71 Correct 34 ms 15564 KB Output is correct
72 Correct 31 ms 15212 KB Output is correct
73 Correct 6 ms 3540 KB Output is correct
74 Correct 17 ms 11092 KB Output is correct
75 Correct 5 ms 3240 KB Output is correct
76 Correct 1002 ms 416356 KB Output is correct
77 Correct 1100 ms 420780 KB Output is correct
78 Correct 38 ms 5388 KB Output is correct
79 Correct 637 ms 169756 KB Output is correct
80 Correct 1490 ms 422484 KB Output is correct
81 Correct 122 ms 62160 KB Output is correct
82 Correct 511 ms 253324 KB Output is correct
83 Correct 1472 ms 405572 KB Output is correct
84 Correct 954 ms 409316 KB Output is correct
85 Correct 258 ms 170188 KB Output is correct
86 Correct 1597 ms 401804 KB Output is correct
87 Correct 1577 ms 394816 KB Output is correct
88 Correct 225 ms 88884 KB Output is correct
89 Correct 1180 ms 289908 KB Output is correct
90 Correct 226 ms 81820 KB Output is correct