Submission #791819

# Submission time Handle Problem Language Result Execution time Memory
791819 2023-07-24T10:31:57 Z 박영우(#10050) Sličnost (COI23_slicnost) C++17
57 / 100
3000 ms 19344 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 (l <= s && e <= r) {
			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];
	//for (i = 1; i <= N; i++) A[i] = i;
	//for (i = 1; i <= N; i++) B[i] = 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;
      |           ~~^~~
# Verdict Execution time Memory Grader output
1 Correct 10 ms 16084 KB Output is correct
2 Correct 8 ms 16084 KB Output is correct
3 Correct 8 ms 16072 KB Output is correct
4 Correct 8 ms 16084 KB Output is correct
5 Correct 9 ms 16096 KB Output is correct
6 Correct 8 ms 16084 KB Output is correct
7 Correct 10 ms 16084 KB Output is correct
8 Correct 8 ms 16144 KB Output is correct
9 Correct 8 ms 16128 KB Output is correct
10 Correct 8 ms 16084 KB Output is correct
11 Correct 8 ms 16084 KB Output is correct
12 Correct 8 ms 16084 KB Output is correct
13 Correct 8 ms 16140 KB Output is correct
14 Correct 7 ms 16092 KB Output is correct
15 Correct 8 ms 16084 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 10 ms 16084 KB Output is correct
2 Correct 8 ms 16084 KB Output is correct
3 Correct 8 ms 16072 KB Output is correct
4 Correct 8 ms 16084 KB Output is correct
5 Correct 9 ms 16096 KB Output is correct
6 Correct 8 ms 16084 KB Output is correct
7 Correct 10 ms 16084 KB Output is correct
8 Correct 8 ms 16144 KB Output is correct
9 Correct 8 ms 16128 KB Output is correct
10 Correct 8 ms 16084 KB Output is correct
11 Correct 8 ms 16084 KB Output is correct
12 Correct 8 ms 16084 KB Output is correct
13 Correct 8 ms 16140 KB Output is correct
14 Correct 7 ms 16092 KB Output is correct
15 Correct 8 ms 16084 KB Output is correct
16 Correct 11 ms 16280 KB Output is correct
17 Correct 11 ms 16264 KB Output is correct
18 Correct 11 ms 16316 KB Output is correct
19 Correct 11 ms 16212 KB Output is correct
20 Correct 12 ms 16212 KB Output is correct
21 Correct 12 ms 16260 KB Output is correct
22 Correct 8 ms 16212 KB Output is correct
23 Correct 13 ms 16300 KB Output is correct
24 Correct 14 ms 16212 KB Output is correct
25 Correct 11 ms 16228 KB Output is correct
26 Correct 12 ms 16212 KB Output is correct
27 Correct 12 ms 16288 KB Output is correct
28 Correct 10 ms 16212 KB Output is correct
29 Correct 10 ms 16224 KB Output is correct
30 Correct 9 ms 16212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 10 ms 16084 KB Output is correct
2 Correct 8 ms 16084 KB Output is correct
3 Correct 8 ms 16072 KB Output is correct
4 Correct 8 ms 16084 KB Output is correct
5 Correct 9 ms 16096 KB Output is correct
6 Correct 8 ms 16084 KB Output is correct
7 Correct 10 ms 16084 KB Output is correct
8 Correct 8 ms 16144 KB Output is correct
9 Correct 8 ms 16128 KB Output is correct
10 Correct 8 ms 16084 KB Output is correct
11 Correct 8 ms 16084 KB Output is correct
12 Correct 8 ms 16084 KB Output is correct
13 Correct 8 ms 16140 KB Output is correct
14 Correct 7 ms 16092 KB Output is correct
15 Correct 8 ms 16084 KB Output is correct
16 Correct 11 ms 16280 KB Output is correct
17 Correct 11 ms 16264 KB Output is correct
18 Correct 11 ms 16316 KB Output is correct
19 Correct 11 ms 16212 KB Output is correct
20 Correct 12 ms 16212 KB Output is correct
21 Correct 12 ms 16260 KB Output is correct
22 Correct 8 ms 16212 KB Output is correct
23 Correct 13 ms 16300 KB Output is correct
24 Correct 14 ms 16212 KB Output is correct
25 Correct 11 ms 16228 KB Output is correct
26 Correct 12 ms 16212 KB Output is correct
27 Correct 12 ms 16288 KB Output is correct
28 Correct 10 ms 16212 KB Output is correct
29 Correct 10 ms 16224 KB Output is correct
30 Correct 9 ms 16212 KB Output is correct
31 Correct 101 ms 18504 KB Output is correct
32 Correct 89 ms 18460 KB Output is correct
33 Correct 20 ms 17572 KB Output is correct
34 Correct 73 ms 18024 KB Output is correct
35 Correct 147 ms 19008 KB Output is correct
36 Correct 105 ms 19172 KB Output is correct
37 Correct 24 ms 18348 KB Output is correct
38 Correct 134 ms 19324 KB Output is correct
39 Correct 108 ms 19320 KB Output is correct
40 Correct 91 ms 18544 KB Output is correct
41 Correct 105 ms 19344 KB Output is correct
42 Correct 145 ms 19248 KB Output is correct
43 Correct 79 ms 18812 KB Output is correct
44 Correct 58 ms 18604 KB Output is correct
45 Correct 26 ms 18124 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 10 ms 16084 KB Output is correct
2 Correct 8 ms 16084 KB Output is correct
3 Correct 8 ms 16072 KB Output is correct
4 Correct 8 ms 16084 KB Output is correct
5 Correct 9 ms 16096 KB Output is correct
6 Correct 8 ms 16084 KB Output is correct
7 Correct 10 ms 16084 KB Output is correct
8 Correct 8 ms 16144 KB Output is correct
9 Correct 8 ms 16128 KB Output is correct
10 Correct 8 ms 16084 KB Output is correct
11 Correct 8 ms 16084 KB Output is correct
12 Correct 8 ms 16084 KB Output is correct
13 Correct 8 ms 16140 KB Output is correct
14 Correct 7 ms 16092 KB Output is correct
15 Correct 8 ms 16084 KB Output is correct
16 Correct 9 ms 16160 KB Output is correct
17 Correct 11 ms 16168 KB Output is correct
18 Correct 7 ms 16156 KB Output is correct
19 Correct 10 ms 16128 KB Output is correct
20 Correct 11 ms 16124 KB Output is correct
21 Correct 8 ms 16084 KB Output is correct
22 Correct 10 ms 16164 KB Output is correct
23 Correct 10 ms 16132 KB Output is correct
24 Correct 10 ms 16084 KB Output is correct
25 Correct 8 ms 16084 KB Output is correct
26 Correct 10 ms 16124 KB Output is correct
27 Correct 9 ms 16084 KB Output is correct
28 Correct 8 ms 16100 KB Output is correct
29 Correct 10 ms 16104 KB Output is correct
30 Correct 8 ms 16160 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 10 ms 16084 KB Output is correct
2 Correct 8 ms 16084 KB Output is correct
3 Correct 8 ms 16072 KB Output is correct
4 Correct 8 ms 16084 KB Output is correct
5 Correct 9 ms 16096 KB Output is correct
6 Correct 8 ms 16084 KB Output is correct
7 Correct 10 ms 16084 KB Output is correct
8 Correct 8 ms 16144 KB Output is correct
9 Correct 8 ms 16128 KB Output is correct
10 Correct 8 ms 16084 KB Output is correct
11 Correct 8 ms 16084 KB Output is correct
12 Correct 8 ms 16084 KB Output is correct
13 Correct 8 ms 16140 KB Output is correct
14 Correct 7 ms 16092 KB Output is correct
15 Correct 8 ms 16084 KB Output is correct
16 Correct 11 ms 16280 KB Output is correct
17 Correct 11 ms 16264 KB Output is correct
18 Correct 11 ms 16316 KB Output is correct
19 Correct 11 ms 16212 KB Output is correct
20 Correct 12 ms 16212 KB Output is correct
21 Correct 12 ms 16260 KB Output is correct
22 Correct 8 ms 16212 KB Output is correct
23 Correct 13 ms 16300 KB Output is correct
24 Correct 14 ms 16212 KB Output is correct
25 Correct 11 ms 16228 KB Output is correct
26 Correct 12 ms 16212 KB Output is correct
27 Correct 12 ms 16288 KB Output is correct
28 Correct 10 ms 16212 KB Output is correct
29 Correct 10 ms 16224 KB Output is correct
30 Correct 9 ms 16212 KB Output is correct
31 Correct 9 ms 16160 KB Output is correct
32 Correct 11 ms 16168 KB Output is correct
33 Correct 7 ms 16156 KB Output is correct
34 Correct 10 ms 16128 KB Output is correct
35 Correct 11 ms 16124 KB Output is correct
36 Correct 8 ms 16084 KB Output is correct
37 Correct 10 ms 16164 KB Output is correct
38 Correct 10 ms 16132 KB Output is correct
39 Correct 10 ms 16084 KB Output is correct
40 Correct 8 ms 16084 KB Output is correct
41 Correct 10 ms 16124 KB Output is correct
42 Correct 9 ms 16084 KB Output is correct
43 Correct 8 ms 16100 KB Output is correct
44 Correct 10 ms 16104 KB Output is correct
45 Correct 8 ms 16160 KB Output is correct
46 Execution timed out 3080 ms 16340 KB Time limit exceeded
47 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 10 ms 16084 KB Output is correct
2 Correct 8 ms 16084 KB Output is correct
3 Correct 8 ms 16072 KB Output is correct
4 Correct 8 ms 16084 KB Output is correct
5 Correct 9 ms 16096 KB Output is correct
6 Correct 8 ms 16084 KB Output is correct
7 Correct 10 ms 16084 KB Output is correct
8 Correct 8 ms 16144 KB Output is correct
9 Correct 8 ms 16128 KB Output is correct
10 Correct 8 ms 16084 KB Output is correct
11 Correct 8 ms 16084 KB Output is correct
12 Correct 8 ms 16084 KB Output is correct
13 Correct 8 ms 16140 KB Output is correct
14 Correct 7 ms 16092 KB Output is correct
15 Correct 8 ms 16084 KB Output is correct
16 Correct 11 ms 16280 KB Output is correct
17 Correct 11 ms 16264 KB Output is correct
18 Correct 11 ms 16316 KB Output is correct
19 Correct 11 ms 16212 KB Output is correct
20 Correct 12 ms 16212 KB Output is correct
21 Correct 12 ms 16260 KB Output is correct
22 Correct 8 ms 16212 KB Output is correct
23 Correct 13 ms 16300 KB Output is correct
24 Correct 14 ms 16212 KB Output is correct
25 Correct 11 ms 16228 KB Output is correct
26 Correct 12 ms 16212 KB Output is correct
27 Correct 12 ms 16288 KB Output is correct
28 Correct 10 ms 16212 KB Output is correct
29 Correct 10 ms 16224 KB Output is correct
30 Correct 9 ms 16212 KB Output is correct
31 Correct 101 ms 18504 KB Output is correct
32 Correct 89 ms 18460 KB Output is correct
33 Correct 20 ms 17572 KB Output is correct
34 Correct 73 ms 18024 KB Output is correct
35 Correct 147 ms 19008 KB Output is correct
36 Correct 105 ms 19172 KB Output is correct
37 Correct 24 ms 18348 KB Output is correct
38 Correct 134 ms 19324 KB Output is correct
39 Correct 108 ms 19320 KB Output is correct
40 Correct 91 ms 18544 KB Output is correct
41 Correct 105 ms 19344 KB Output is correct
42 Correct 145 ms 19248 KB Output is correct
43 Correct 79 ms 18812 KB Output is correct
44 Correct 58 ms 18604 KB Output is correct
45 Correct 26 ms 18124 KB Output is correct
46 Correct 9 ms 16160 KB Output is correct
47 Correct 11 ms 16168 KB Output is correct
48 Correct 7 ms 16156 KB Output is correct
49 Correct 10 ms 16128 KB Output is correct
50 Correct 11 ms 16124 KB Output is correct
51 Correct 8 ms 16084 KB Output is correct
52 Correct 10 ms 16164 KB Output is correct
53 Correct 10 ms 16132 KB Output is correct
54 Correct 10 ms 16084 KB Output is correct
55 Correct 8 ms 16084 KB Output is correct
56 Correct 10 ms 16124 KB Output is correct
57 Correct 9 ms 16084 KB Output is correct
58 Correct 8 ms 16100 KB Output is correct
59 Correct 10 ms 16104 KB Output is correct
60 Correct 8 ms 16160 KB Output is correct
61 Execution timed out 3080 ms 16340 KB Time limit exceeded
62 Halted 0 ms 0 KB -