Submission #961968

# Submission time Handle Problem Language Result Execution time Memory
961968 2024-04-12T23:43:43 Z TAhmed33 Sličnost (COI23_slicnost) C++
57 / 100
3000 ms 7948 KB
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define mid ((l + r) >> 1)
#define tl (node + 1)
#define tr (node + 2 * (mid - l + 1))
const int MAXN = 1e5 + 25;
struct SegmentTree {
	pair <int, int> tree[MAXN << 1];
	int lazy[MAXN << 1];
	pair <int, int> comb (pair <int, int> a, pair <int, int> b) {
		if (a.first > b.first) return a;
		if (a.first < b.first) return b;
		return {a.first, a.second + b.second};
	}
	void init (int l, int r, int node) {
		lazy[node] = 0;
		tree[node] = {0, r - l + 1};
		if (l == r) return;
		init(l, mid, tl); init(mid + 1, r, tr);
	}
	void prop (int l, int r, int node) {
		if (lazy[node] == 0) return;
		if (l != r) {
			lazy[tl] += lazy[node];
			lazy[tr] += lazy[node];
		}
		tree[node].first += lazy[node];
		lazy[node] = 0;
	}
	void update (int l, int r, int a, int b, int c, int node) {
		prop(l, r, node);
		if (l > b || r < a) return;
		if (l >= a && r <= b) {
			lazy[node] += c;
			prop(l, r, node);
			return;
		}
		update(l, mid, a, b, c, tl); update(mid + 1, r, a, b, c, tr);
		tree[node] = comb(tree[tl], tree[tr]);
	}
	pair <int, int> get (int l, int r, int a, int b, int node) {
		prop(l, r, node);
		if (l > b || r < a) return {-1, 0};
		if (l >= a && r <= b) return tree[node];
		return comb(get(l, mid, a, b, tl), get(mid + 1, r, a, b, tr));
	}
} cur;
long long n, k, q, a[MAXN], p[MAXN];
void solve () {
	cur.init(1, n, 1);
	pair <int, int> u = {0, 0};
	for (int i = 1; i <= k; i++) {
		cur.update(1, n, max(1ll, a[i] - k + 1), min(a[i], n - k + 1), 1, 1);
	}
	auto z = cur.get(1, n, 1, n, 1);
	u = z;
	for (int i = k + 1; i <= n; i++) {
		cur.update(1, n, max(1ll, a[i - k] - k + 1), min(a[i - k], n - k + 1), -1, 1);
		cur.update(1, n, max(1ll, a[i] - k + 1), min(a[i], n - k + 1), 1, 1);
		auto z = cur.get(1, n, 1, n, 1);
		u = cur.comb(u, z);
	}
	cout << u.first << " " << u.second << '\n';
}
signed main () {
	ios::sync_with_stdio(0); cin.tie(0);
	cin >> n >> k >> q;
	for (int i = 1; i <= n; i++) cin >> a[i];
	for (int i = 1; i <= n; i++) {
		int x; cin >> x;
		p[x] = i;
	}
	for (int i = 1; i <= n; i++) a[i] = p[a[i]];
	solve();
	while (q--) {
		int x; cin >> x;
		swap(a[x], a[x + 1]);
		solve();
	}
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4952 KB Output is correct
2 Correct 1 ms 4956 KB Output is correct
3 Correct 1 ms 4956 KB Output is correct
4 Correct 1 ms 4956 KB Output is correct
5 Correct 1 ms 4956 KB Output is correct
6 Correct 1 ms 4956 KB Output is correct
7 Correct 2 ms 4956 KB Output is correct
8 Correct 2 ms 4952 KB Output is correct
9 Correct 1 ms 4956 KB Output is correct
10 Correct 1 ms 4956 KB Output is correct
11 Correct 1 ms 4956 KB Output is correct
12 Correct 1 ms 4956 KB Output is correct
13 Correct 1 ms 4956 KB Output is correct
14 Correct 2 ms 4956 KB Output is correct
15 Correct 1 ms 4956 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4952 KB Output is correct
2 Correct 1 ms 4956 KB Output is correct
3 Correct 1 ms 4956 KB Output is correct
4 Correct 1 ms 4956 KB Output is correct
5 Correct 1 ms 4956 KB Output is correct
6 Correct 1 ms 4956 KB Output is correct
7 Correct 2 ms 4956 KB Output is correct
8 Correct 2 ms 4952 KB Output is correct
9 Correct 1 ms 4956 KB Output is correct
10 Correct 1 ms 4956 KB Output is correct
11 Correct 1 ms 4956 KB Output is correct
12 Correct 1 ms 4956 KB Output is correct
13 Correct 1 ms 4956 KB Output is correct
14 Correct 2 ms 4956 KB Output is correct
15 Correct 1 ms 4956 KB Output is correct
16 Correct 3 ms 4956 KB Output is correct
17 Correct 4 ms 5036 KB Output is correct
18 Correct 2 ms 4956 KB Output is correct
19 Correct 4 ms 4956 KB Output is correct
20 Correct 5 ms 4956 KB Output is correct
21 Correct 4 ms 5052 KB Output is correct
22 Correct 2 ms 4956 KB Output is correct
23 Correct 5 ms 4956 KB Output is correct
24 Correct 4 ms 4956 KB Output is correct
25 Correct 5 ms 5000 KB Output is correct
26 Correct 5 ms 4956 KB Output is correct
27 Correct 5 ms 4956 KB Output is correct
28 Correct 4 ms 4956 KB Output is correct
29 Correct 3 ms 4996 KB Output is correct
30 Correct 2 ms 4952 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4952 KB Output is correct
2 Correct 1 ms 4956 KB Output is correct
3 Correct 1 ms 4956 KB Output is correct
4 Correct 1 ms 4956 KB Output is correct
5 Correct 1 ms 4956 KB Output is correct
6 Correct 1 ms 4956 KB Output is correct
7 Correct 2 ms 4956 KB Output is correct
8 Correct 2 ms 4952 KB Output is correct
9 Correct 1 ms 4956 KB Output is correct
10 Correct 1 ms 4956 KB Output is correct
11 Correct 1 ms 4956 KB Output is correct
12 Correct 1 ms 4956 KB Output is correct
13 Correct 1 ms 4956 KB Output is correct
14 Correct 2 ms 4956 KB Output is correct
15 Correct 1 ms 4956 KB Output is correct
16 Correct 3 ms 4956 KB Output is correct
17 Correct 4 ms 5036 KB Output is correct
18 Correct 2 ms 4956 KB Output is correct
19 Correct 4 ms 4956 KB Output is correct
20 Correct 5 ms 4956 KB Output is correct
21 Correct 4 ms 5052 KB Output is correct
22 Correct 2 ms 4956 KB Output is correct
23 Correct 5 ms 4956 KB Output is correct
24 Correct 4 ms 4956 KB Output is correct
25 Correct 5 ms 5000 KB Output is correct
26 Correct 5 ms 4956 KB Output is correct
27 Correct 5 ms 4956 KB Output is correct
28 Correct 4 ms 4956 KB Output is correct
29 Correct 3 ms 4996 KB Output is correct
30 Correct 2 ms 4952 KB Output is correct
31 Correct 58 ms 7772 KB Output is correct
32 Correct 60 ms 7772 KB Output is correct
33 Correct 28 ms 7768 KB Output is correct
34 Correct 74 ms 7768 KB Output is correct
35 Correct 114 ms 7776 KB Output is correct
36 Correct 72 ms 7512 KB Output is correct
37 Correct 31 ms 7768 KB Output is correct
38 Correct 124 ms 7700 KB Output is correct
39 Correct 76 ms 7772 KB Output is correct
40 Correct 92 ms 7724 KB Output is correct
41 Correct 101 ms 7768 KB Output is correct
42 Correct 127 ms 7516 KB Output is correct
43 Correct 78 ms 7504 KB Output is correct
44 Correct 64 ms 7824 KB Output is correct
45 Correct 40 ms 7948 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4952 KB Output is correct
2 Correct 1 ms 4956 KB Output is correct
3 Correct 1 ms 4956 KB Output is correct
4 Correct 1 ms 4956 KB Output is correct
5 Correct 1 ms 4956 KB Output is correct
6 Correct 1 ms 4956 KB Output is correct
7 Correct 2 ms 4956 KB Output is correct
8 Correct 2 ms 4952 KB Output is correct
9 Correct 1 ms 4956 KB Output is correct
10 Correct 1 ms 4956 KB Output is correct
11 Correct 1 ms 4956 KB Output is correct
12 Correct 1 ms 4956 KB Output is correct
13 Correct 1 ms 4956 KB Output is correct
14 Correct 2 ms 4956 KB Output is correct
15 Correct 1 ms 4956 KB Output is correct
16 Correct 3 ms 4952 KB Output is correct
17 Correct 3 ms 4980 KB Output is correct
18 Correct 2 ms 4952 KB Output is correct
19 Correct 3 ms 4956 KB Output is correct
20 Correct 3 ms 4956 KB Output is correct
21 Correct 2 ms 4956 KB Output is correct
22 Correct 3 ms 4956 KB Output is correct
23 Correct 3 ms 4956 KB Output is correct
24 Correct 3 ms 4956 KB Output is correct
25 Correct 2 ms 4952 KB Output is correct
26 Correct 3 ms 4956 KB Output is correct
27 Correct 2 ms 4784 KB Output is correct
28 Correct 2 ms 4956 KB Output is correct
29 Correct 3 ms 4956 KB Output is correct
30 Correct 2 ms 4956 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4952 KB Output is correct
2 Correct 1 ms 4956 KB Output is correct
3 Correct 1 ms 4956 KB Output is correct
4 Correct 1 ms 4956 KB Output is correct
5 Correct 1 ms 4956 KB Output is correct
6 Correct 1 ms 4956 KB Output is correct
7 Correct 2 ms 4956 KB Output is correct
8 Correct 2 ms 4952 KB Output is correct
9 Correct 1 ms 4956 KB Output is correct
10 Correct 1 ms 4956 KB Output is correct
11 Correct 1 ms 4956 KB Output is correct
12 Correct 1 ms 4956 KB Output is correct
13 Correct 1 ms 4956 KB Output is correct
14 Correct 2 ms 4956 KB Output is correct
15 Correct 1 ms 4956 KB Output is correct
16 Correct 3 ms 4956 KB Output is correct
17 Correct 4 ms 5036 KB Output is correct
18 Correct 2 ms 4956 KB Output is correct
19 Correct 4 ms 4956 KB Output is correct
20 Correct 5 ms 4956 KB Output is correct
21 Correct 4 ms 5052 KB Output is correct
22 Correct 2 ms 4956 KB Output is correct
23 Correct 5 ms 4956 KB Output is correct
24 Correct 4 ms 4956 KB Output is correct
25 Correct 5 ms 5000 KB Output is correct
26 Correct 5 ms 4956 KB Output is correct
27 Correct 5 ms 4956 KB Output is correct
28 Correct 4 ms 4956 KB Output is correct
29 Correct 3 ms 4996 KB Output is correct
30 Correct 2 ms 4952 KB Output is correct
31 Correct 3 ms 4952 KB Output is correct
32 Correct 3 ms 4980 KB Output is correct
33 Correct 2 ms 4952 KB Output is correct
34 Correct 3 ms 4956 KB Output is correct
35 Correct 3 ms 4956 KB Output is correct
36 Correct 2 ms 4956 KB Output is correct
37 Correct 3 ms 4956 KB Output is correct
38 Correct 3 ms 4956 KB Output is correct
39 Correct 3 ms 4956 KB Output is correct
40 Correct 2 ms 4952 KB Output is correct
41 Correct 3 ms 4956 KB Output is correct
42 Correct 2 ms 4784 KB Output is correct
43 Correct 2 ms 4956 KB Output is correct
44 Correct 3 ms 4956 KB Output is correct
45 Correct 2 ms 4956 KB Output is correct
46 Execution timed out 3012 ms 5148 KB Time limit exceeded
47 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4952 KB Output is correct
2 Correct 1 ms 4956 KB Output is correct
3 Correct 1 ms 4956 KB Output is correct
4 Correct 1 ms 4956 KB Output is correct
5 Correct 1 ms 4956 KB Output is correct
6 Correct 1 ms 4956 KB Output is correct
7 Correct 2 ms 4956 KB Output is correct
8 Correct 2 ms 4952 KB Output is correct
9 Correct 1 ms 4956 KB Output is correct
10 Correct 1 ms 4956 KB Output is correct
11 Correct 1 ms 4956 KB Output is correct
12 Correct 1 ms 4956 KB Output is correct
13 Correct 1 ms 4956 KB Output is correct
14 Correct 2 ms 4956 KB Output is correct
15 Correct 1 ms 4956 KB Output is correct
16 Correct 3 ms 4956 KB Output is correct
17 Correct 4 ms 5036 KB Output is correct
18 Correct 2 ms 4956 KB Output is correct
19 Correct 4 ms 4956 KB Output is correct
20 Correct 5 ms 4956 KB Output is correct
21 Correct 4 ms 5052 KB Output is correct
22 Correct 2 ms 4956 KB Output is correct
23 Correct 5 ms 4956 KB Output is correct
24 Correct 4 ms 4956 KB Output is correct
25 Correct 5 ms 5000 KB Output is correct
26 Correct 5 ms 4956 KB Output is correct
27 Correct 5 ms 4956 KB Output is correct
28 Correct 4 ms 4956 KB Output is correct
29 Correct 3 ms 4996 KB Output is correct
30 Correct 2 ms 4952 KB Output is correct
31 Correct 58 ms 7772 KB Output is correct
32 Correct 60 ms 7772 KB Output is correct
33 Correct 28 ms 7768 KB Output is correct
34 Correct 74 ms 7768 KB Output is correct
35 Correct 114 ms 7776 KB Output is correct
36 Correct 72 ms 7512 KB Output is correct
37 Correct 31 ms 7768 KB Output is correct
38 Correct 124 ms 7700 KB Output is correct
39 Correct 76 ms 7772 KB Output is correct
40 Correct 92 ms 7724 KB Output is correct
41 Correct 101 ms 7768 KB Output is correct
42 Correct 127 ms 7516 KB Output is correct
43 Correct 78 ms 7504 KB Output is correct
44 Correct 64 ms 7824 KB Output is correct
45 Correct 40 ms 7948 KB Output is correct
46 Correct 3 ms 4952 KB Output is correct
47 Correct 3 ms 4980 KB Output is correct
48 Correct 2 ms 4952 KB Output is correct
49 Correct 3 ms 4956 KB Output is correct
50 Correct 3 ms 4956 KB Output is correct
51 Correct 2 ms 4956 KB Output is correct
52 Correct 3 ms 4956 KB Output is correct
53 Correct 3 ms 4956 KB Output is correct
54 Correct 3 ms 4956 KB Output is correct
55 Correct 2 ms 4952 KB Output is correct
56 Correct 3 ms 4956 KB Output is correct
57 Correct 2 ms 4784 KB Output is correct
58 Correct 2 ms 4956 KB Output is correct
59 Correct 3 ms 4956 KB Output is correct
60 Correct 2 ms 4956 KB Output is correct
61 Execution timed out 3012 ms 5148 KB Time limit exceeded
62 Halted 0 ms 0 KB -