답안 #791815

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
791815 2023-07-24T10:28:03 Z 박영우(#10050) Sličnost (COI23_slicnost) C++17
24 / 100
3000 ms 19228 KB
#include <bits/stdc++.h>
#include <cassert>
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("avx,avx2,fma")
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
#define MAX 1010101
#define MAXS 500
#define INF 1000000000000000001
#define bb ' '
#define ln '\n'
#define Ln '\n'
struct node {
	int mx;
	ll cnt;
	node(int x = 0) :mx(x), cnt(1) {}
};
node operator+(node n1, node n2) {
	node ret;
	ret.mx = max(n1.mx, n2.mx);
	ret.cnt = 0;
	if (ret.mx == n1.mx) ret.cnt += n1.cnt;
	if (ret.mx == n2.mx) ret.cnt += n2.cnt;
	return ret;
}
node operator+(node n, ll x) {
	node ret = n;
	ret.mx += x;
	return ret;
}
namespace segtree {
	node tree[MAX];
	int lazy[MAX];
	int N;
	void init(int s, int e, int loc = 1) {
		lazy[loc] = 0;
		if (s == e) {
			tree[loc] = node();
			return;
		}
		int m = s + e >> 1;
		init(s, m, loc * 2);
		init(m + 1, e, loc * 2 + 1);
		tree[loc] = tree[loc * 2] + tree[loc * 2 + 1];
	}
	void prop(int loc) {
		for (auto c : { loc * 2, loc * 2 + 1 }) {
			tree[c] = tree[c] + lazy[loc];
			lazy[c] += lazy[loc];
		}
		lazy[loc] = 0;
	}
	void upd(int s, int e, int l, int r, ll x, int loc = 1) {
		if (l < 1) l = 1;
		if (r > N) r = N;
		if (l > r) return;
		if (s != e) prop(loc);
		if (e < l || r < s) return;
		if (s == e) {
			tree[loc] = tree[loc] + x;
			lazy[loc] += x;
			return;
		}
		int m = s + e >> 1;
		upd(s, m, l, r, x, loc * 2);
		upd(m + 1, e, l, r, x, loc * 2 + 1);
		tree[loc] = tree[loc * 2] + tree[loc * 2 + 1];
	}
};
int N, K, Q;
int A[MAX];
int B[MAX];
int rb[MAX];
node calc() {
	int i;
	node res(0);
	for (i = 1; i <= N; i++) rb[B[i]] = i;
	segtree::N = N - K + 1;
	segtree::init(1, N - K + 1);
	for (i = 1; i <= N; i++) {
		segtree::upd(1, N - K + 1, rb[A[i]] - K + 1, rb[A[i]], 1);
		if (i > K) segtree::upd(1, N - K + 1, rb[A[i - K]] - K + 1, rb[A[i - K]], -1);
		if (i >= K) res = res + segtree::tree[1];
	}
	return res;
}
signed main() {
	ios::sync_with_stdio(false), cin.tie(0);
	cin >> N >> K >> Q;
	int i;
	for (i = 1; i <= N; i++) cin >> A[i];
	for (i = 1; i <= N; i++) cin >> B[i];
	auto res = calc();
	cout << res.mx << bb << res.cnt << ln;
	while (Q--) {
		int k;
		cin >> k;
		swap(A[k], A[k + 1]);
		auto res = calc();
		cout << res.mx << bb << res.cnt << ln;
	}
}

Compilation message

Main.cpp: In function 'void segtree::init(int, int, int)':
Main.cpp:45:13: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   45 |   int m = s + e >> 1;
      |           ~~^~~
Main.cpp: In function 'void segtree::upd(int, int, int, int, ll, int)':
Main.cpp:68:13: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   68 |   int m = s + e >> 1;
      |           ~~^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 16084 KB Output is correct
2 Correct 7 ms 16084 KB Output is correct
3 Correct 7 ms 16084 KB Output is correct
4 Correct 7 ms 16084 KB Output is correct
5 Correct 8 ms 16084 KB Output is correct
6 Correct 8 ms 16084 KB Output is correct
7 Correct 8 ms 16128 KB Output is correct
8 Correct 8 ms 16084 KB Output is correct
9 Correct 8 ms 16144 KB Output is correct
10 Correct 9 ms 16056 KB Output is correct
11 Correct 8 ms 16148 KB Output is correct
12 Correct 7 ms 16104 KB Output is correct
13 Correct 7 ms 16088 KB Output is correct
14 Correct 7 ms 16084 KB Output is correct
15 Correct 7 ms 16084 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 16084 KB Output is correct
2 Correct 7 ms 16084 KB Output is correct
3 Correct 7 ms 16084 KB Output is correct
4 Correct 7 ms 16084 KB Output is correct
5 Correct 8 ms 16084 KB Output is correct
6 Correct 8 ms 16084 KB Output is correct
7 Correct 8 ms 16128 KB Output is correct
8 Correct 8 ms 16084 KB Output is correct
9 Correct 8 ms 16144 KB Output is correct
10 Correct 9 ms 16056 KB Output is correct
11 Correct 8 ms 16148 KB Output is correct
12 Correct 7 ms 16104 KB Output is correct
13 Correct 7 ms 16088 KB Output is correct
14 Correct 7 ms 16084 KB Output is correct
15 Correct 7 ms 16084 KB Output is correct
16 Correct 11 ms 16308 KB Output is correct
17 Correct 11 ms 16328 KB Output is correct
18 Correct 8 ms 16264 KB Output is correct
19 Correct 134 ms 16276 KB Output is correct
20 Correct 20 ms 16212 KB Output is correct
21 Correct 40 ms 16292 KB Output is correct
22 Correct 23 ms 16212 KB Output is correct
23 Correct 19 ms 16212 KB Output is correct
24 Correct 19 ms 16296 KB Output is correct
25 Correct 140 ms 16256 KB Output is correct
26 Correct 131 ms 16284 KB Output is correct
27 Correct 50 ms 16312 KB Output is correct
28 Correct 130 ms 16268 KB Output is correct
29 Correct 145 ms 16300 KB Output is correct
30 Correct 30 ms 16268 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 16084 KB Output is correct
2 Correct 7 ms 16084 KB Output is correct
3 Correct 7 ms 16084 KB Output is correct
4 Correct 7 ms 16084 KB Output is correct
5 Correct 8 ms 16084 KB Output is correct
6 Correct 8 ms 16084 KB Output is correct
7 Correct 8 ms 16128 KB Output is correct
8 Correct 8 ms 16084 KB Output is correct
9 Correct 8 ms 16144 KB Output is correct
10 Correct 9 ms 16056 KB Output is correct
11 Correct 8 ms 16148 KB Output is correct
12 Correct 7 ms 16104 KB Output is correct
13 Correct 7 ms 16088 KB Output is correct
14 Correct 7 ms 16084 KB Output is correct
15 Correct 7 ms 16084 KB Output is correct
16 Correct 11 ms 16308 KB Output is correct
17 Correct 11 ms 16328 KB Output is correct
18 Correct 8 ms 16264 KB Output is correct
19 Correct 134 ms 16276 KB Output is correct
20 Correct 20 ms 16212 KB Output is correct
21 Correct 40 ms 16292 KB Output is correct
22 Correct 23 ms 16212 KB Output is correct
23 Correct 19 ms 16212 KB Output is correct
24 Correct 19 ms 16296 KB Output is correct
25 Correct 140 ms 16256 KB Output is correct
26 Correct 131 ms 16284 KB Output is correct
27 Correct 50 ms 16312 KB Output is correct
28 Correct 130 ms 16268 KB Output is correct
29 Correct 145 ms 16300 KB Output is correct
30 Correct 30 ms 16268 KB Output is correct
31 Correct 83 ms 19228 KB Output is correct
32 Correct 90 ms 19216 KB Output is correct
33 Correct 19 ms 18168 KB Output is correct
34 Execution timed out 3058 ms 18636 KB Time limit exceeded
35 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 16084 KB Output is correct
2 Correct 7 ms 16084 KB Output is correct
3 Correct 7 ms 16084 KB Output is correct
4 Correct 7 ms 16084 KB Output is correct
5 Correct 8 ms 16084 KB Output is correct
6 Correct 8 ms 16084 KB Output is correct
7 Correct 8 ms 16128 KB Output is correct
8 Correct 8 ms 16084 KB Output is correct
9 Correct 8 ms 16144 KB Output is correct
10 Correct 9 ms 16056 KB Output is correct
11 Correct 8 ms 16148 KB Output is correct
12 Correct 7 ms 16104 KB Output is correct
13 Correct 7 ms 16088 KB Output is correct
14 Correct 7 ms 16084 KB Output is correct
15 Correct 7 ms 16084 KB Output is correct
16 Correct 11 ms 16132 KB Output is correct
17 Correct 11 ms 16084 KB Output is correct
18 Correct 7 ms 16084 KB Output is correct
19 Correct 13 ms 16164 KB Output is correct
20 Correct 12 ms 16084 KB Output is correct
21 Correct 9 ms 16084 KB Output is correct
22 Correct 13 ms 16168 KB Output is correct
23 Correct 11 ms 16160 KB Output is correct
24 Correct 11 ms 16080 KB Output is correct
25 Correct 15 ms 16084 KB Output is correct
26 Correct 10 ms 16084 KB Output is correct
27 Correct 12 ms 16048 KB Output is correct
28 Correct 11 ms 16164 KB Output is correct
29 Correct 13 ms 16084 KB Output is correct
30 Correct 10 ms 16060 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 16084 KB Output is correct
2 Correct 7 ms 16084 KB Output is correct
3 Correct 7 ms 16084 KB Output is correct
4 Correct 7 ms 16084 KB Output is correct
5 Correct 8 ms 16084 KB Output is correct
6 Correct 8 ms 16084 KB Output is correct
7 Correct 8 ms 16128 KB Output is correct
8 Correct 8 ms 16084 KB Output is correct
9 Correct 8 ms 16144 KB Output is correct
10 Correct 9 ms 16056 KB Output is correct
11 Correct 8 ms 16148 KB Output is correct
12 Correct 7 ms 16104 KB Output is correct
13 Correct 7 ms 16088 KB Output is correct
14 Correct 7 ms 16084 KB Output is correct
15 Correct 7 ms 16084 KB Output is correct
16 Correct 11 ms 16308 KB Output is correct
17 Correct 11 ms 16328 KB Output is correct
18 Correct 8 ms 16264 KB Output is correct
19 Correct 134 ms 16276 KB Output is correct
20 Correct 20 ms 16212 KB Output is correct
21 Correct 40 ms 16292 KB Output is correct
22 Correct 23 ms 16212 KB Output is correct
23 Correct 19 ms 16212 KB Output is correct
24 Correct 19 ms 16296 KB Output is correct
25 Correct 140 ms 16256 KB Output is correct
26 Correct 131 ms 16284 KB Output is correct
27 Correct 50 ms 16312 KB Output is correct
28 Correct 130 ms 16268 KB Output is correct
29 Correct 145 ms 16300 KB Output is correct
30 Correct 30 ms 16268 KB Output is correct
31 Correct 11 ms 16132 KB Output is correct
32 Correct 11 ms 16084 KB Output is correct
33 Correct 7 ms 16084 KB Output is correct
34 Correct 13 ms 16164 KB Output is correct
35 Correct 12 ms 16084 KB Output is correct
36 Correct 9 ms 16084 KB Output is correct
37 Correct 13 ms 16168 KB Output is correct
38 Correct 11 ms 16160 KB Output is correct
39 Correct 11 ms 16080 KB Output is correct
40 Correct 15 ms 16084 KB Output is correct
41 Correct 10 ms 16084 KB Output is correct
42 Correct 12 ms 16048 KB Output is correct
43 Correct 11 ms 16164 KB Output is correct
44 Correct 13 ms 16084 KB Output is correct
45 Correct 10 ms 16060 KB Output is correct
46 Execution timed out 3061 ms 16456 KB Time limit exceeded
47 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 16084 KB Output is correct
2 Correct 7 ms 16084 KB Output is correct
3 Correct 7 ms 16084 KB Output is correct
4 Correct 7 ms 16084 KB Output is correct
5 Correct 8 ms 16084 KB Output is correct
6 Correct 8 ms 16084 KB Output is correct
7 Correct 8 ms 16128 KB Output is correct
8 Correct 8 ms 16084 KB Output is correct
9 Correct 8 ms 16144 KB Output is correct
10 Correct 9 ms 16056 KB Output is correct
11 Correct 8 ms 16148 KB Output is correct
12 Correct 7 ms 16104 KB Output is correct
13 Correct 7 ms 16088 KB Output is correct
14 Correct 7 ms 16084 KB Output is correct
15 Correct 7 ms 16084 KB Output is correct
16 Correct 11 ms 16308 KB Output is correct
17 Correct 11 ms 16328 KB Output is correct
18 Correct 8 ms 16264 KB Output is correct
19 Correct 134 ms 16276 KB Output is correct
20 Correct 20 ms 16212 KB Output is correct
21 Correct 40 ms 16292 KB Output is correct
22 Correct 23 ms 16212 KB Output is correct
23 Correct 19 ms 16212 KB Output is correct
24 Correct 19 ms 16296 KB Output is correct
25 Correct 140 ms 16256 KB Output is correct
26 Correct 131 ms 16284 KB Output is correct
27 Correct 50 ms 16312 KB Output is correct
28 Correct 130 ms 16268 KB Output is correct
29 Correct 145 ms 16300 KB Output is correct
30 Correct 30 ms 16268 KB Output is correct
31 Correct 83 ms 19228 KB Output is correct
32 Correct 90 ms 19216 KB Output is correct
33 Correct 19 ms 18168 KB Output is correct
34 Execution timed out 3058 ms 18636 KB Time limit exceeded
35 Halted 0 ms 0 KB -