Submission #957358

# Submission time Handle Problem Language Result Execution time Memory
957358 2024-04-03T14:22:38 Z ono_de206 Sličnost (COI23_slicnost) C++14
100 / 100
1269 ms 434988 KB
#include<bits/stdc++.h>
using namespace std;

#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define in insert
#define all(x) x.begin(),x.end()
#define pb push_back
#define eb emplace_back
#define ff first
#define ss second

// #define int long long

typedef long long ll;
typedef vector<int> vi;
typedef set<int> si;
typedef multiset<int> msi;
typedef pair<int, int> pii;
typedef vector<pii> vpii;
// typedef pair<int, int> P;

template<typename T, typename U>
ostream & operator << (ostream &out, const pair<T, U> &c) {
	out << c.first << ' ' << c.second;
	return out;
}

template<typename T>
ostream & operator << (ostream &out, vector<T> &v) {
	const int sz = v.size();
	for (int i = 0; i < sz; i++) {
		if (i) out << ' ';
		out << v[i];
	}
	return out;
}

template<typename T>
istream & operator >> (istream &in, vector<T> &v) {
	for (T &x : v) in >> x;
	return in;
}

template<typename T, typename U>
	istream & operator >> (istream &in, pair<T, U> &c) {
	in >> c.first;
	in >> c.second;
	return in;
}

template<typename T>
void mxx(T &a, T b){if(b > a) a = b;}
template<typename T>
void mnn(T &a, T b){if(b < a) a = b;}

const int mxn = 1e5 + 10, MXLOG = 22, mod = 1e9 + 7, P = 1181, D = 1523, N = 2500;
const long long inf = 2e18 + 10;

struct node {
	int mx, cnt, sum;
	node() : mx(0), cnt(0), sum(0) {}
	node(int _mx, int _cnt, int _sum) : mx(_mx), cnt(_cnt), sum(_sum) {}
} d[mxn * 220];

node operator+(const node &a, const node &b) {
	node ret(0, 0, 0);
	ret.mx = max(a.mx, a.sum + b.mx);
	ret.sum = a.sum + b.sum;
	if(ret.mx == a.mx) ret.cnt += a.cnt;
	if(ret.mx == b.mx + a.sum) ret.cnt += b.cnt;
	return ret;
}

int lch[mxn * 220], rch[mxn * 220], p[mxn], q[mxn], pos[mxn], root[mxn], T;

int build(int l, int r) {
	int save = ++T;
	int m = (l + r) / 2;
	d[save].mx = 0;
	d[save].cnt = r - l + 1;
	d[save].sum = 0;
	if(l < r) {
		lch[save] = build(l, m);
		rch[save] = build(m + 1, r);
	}
	return save;
}

int update(int l, int r, int i, int x, int y) {
	int save = ++T;
	if(l == r) {
		d[save] = d[i];
		d[save].mx += y;
		d[save].sum += y;
		d[save].cnt = 1;
		return save;
	}
	int m = (l + r) / 2;
	if(x <= m) {
		lch[save] = update(l, m, lch[i], x, y);
		rch[save] = rch[i];
	} else {
		lch[save] = lch[i];
		rch[save] = update(m + 1, r, rch[i], x, y);
	}
	d[save] = d[lch[save]] + d[rch[save]];
	return save;
}

map<int, long long> mp;

void add(node x) {
	mp[x.mx] += x.cnt;
}

void rem(node x) {
	mp[x.mx] -= x.cnt;
	if(mp[x.mx] == 0) mp.erase(x.mx);
}

void print_ans() {
	auto val = *mp.rbegin();
	assert(val.ss != 0);
	cout << val.ff << ' ' << val.ss << endl;
}

void go() {
	int n, k, Q;
	cin >> n >> k >> Q;
	for(int i = 1; i <= n; i++) {
		cin >> p[i];
	}
	for(int i = 1; i <= n; i++) {
		cin >> q[i];
		pos[q[i]] = i;
	}
	root[0] = build(1, n);
	for(int i = 1; i <= n; i++) {
		root[i] = update(1, n, root[i - 1], max(k, pos[p[i]]), 1);
		if(pos[p[i]] + k <= n) root[i] = update(1, n, root[i], pos[p[i]] + k, -1);
		if(i - k > 0) {
			root[i] = update(1, n, root[i], max(k, pos[p[i - k]]), -1);
			if(pos[p[i - k]] + k <= n) root[i] = update(1, n, root[i], pos[p[i - k]] + k, 1);
		}
		if(i >= k) add(d[root[i]]);
	}
	print_ans();
	// cout << endl;
	while(Q--) {
		int x;
		cin >> x;
		if(x >= k) {
			rem(d[root[x]]);
			root[x] = update(1, n, root[x], max(k, pos[p[x]]), -1);
			if(pos[p[x]] + k <= n) root[x] = update(1, n, root[x], pos[p[x]] + k, 1);
			root[x] = update(1, n, root[x], max(k, pos[p[x + 1]]), 1);
			if(pos[p[x + 1]] + k <= n) root[x] = update(1, n, root[x], pos[p[x + 1]] + k, -1);
			add(d[root[x]]);
		}
		if(x + k <= n) {
			rem(d[root[x + k]]);
			root[x + k] = update(1, n, root[x + k], max(k, pos[p[x + 1]]), -1);
			if(pos[p[x + 1]] + k <= n) root[x + k] = update(1, n, root[x + k], pos[p[x + 1]] + k, 1);
			root[x + k] = update(1, n, root[x + k], max(k, pos[p[x]]), 1);
			if(pos[p[x]] + k <= n) root[x + k] = update(1, n, root[x + k], pos[p[x]] + k, -1);
			add(d[root[x + k]]);
		}
		swap(p[x], p[x + 1]);
		print_ans();
	}
}

signed main() {
	fast;
	int t = 1;
	// cin >> t;
	while(t--) {
		go();
	}
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 49 ms 264020 KB Output is correct
2 Correct 50 ms 264012 KB Output is correct
3 Correct 49 ms 264016 KB Output is correct
4 Correct 49 ms 263908 KB Output is correct
5 Correct 49 ms 264012 KB Output is correct
6 Correct 49 ms 264012 KB Output is correct
7 Correct 50 ms 264124 KB Output is correct
8 Correct 49 ms 264020 KB Output is correct
9 Correct 48 ms 264020 KB Output is correct
10 Correct 50 ms 264016 KB Output is correct
11 Correct 50 ms 263960 KB Output is correct
12 Correct 50 ms 263896 KB Output is correct
13 Correct 49 ms 264004 KB Output is correct
14 Correct 53 ms 264000 KB Output is correct
15 Correct 50 ms 263956 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 49 ms 264020 KB Output is correct
2 Correct 50 ms 264012 KB Output is correct
3 Correct 49 ms 264016 KB Output is correct
4 Correct 49 ms 263908 KB Output is correct
5 Correct 49 ms 264012 KB Output is correct
6 Correct 49 ms 264012 KB Output is correct
7 Correct 50 ms 264124 KB Output is correct
8 Correct 49 ms 264020 KB Output is correct
9 Correct 48 ms 264020 KB Output is correct
10 Correct 50 ms 264016 KB Output is correct
11 Correct 50 ms 263960 KB Output is correct
12 Correct 50 ms 263896 KB Output is correct
13 Correct 49 ms 264004 KB Output is correct
14 Correct 53 ms 264000 KB Output is correct
15 Correct 50 ms 263956 KB Output is correct
16 Correct 52 ms 268116 KB Output is correct
17 Correct 54 ms 268116 KB Output is correct
18 Correct 51 ms 264020 KB Output is correct
19 Correct 52 ms 263984 KB Output is correct
20 Correct 53 ms 268088 KB Output is correct
21 Correct 52 ms 268028 KB Output is correct
22 Correct 51 ms 264148 KB Output is correct
23 Correct 53 ms 268184 KB Output is correct
24 Correct 53 ms 268184 KB Output is correct
25 Correct 52 ms 265996 KB Output is correct
26 Correct 53 ms 268164 KB Output is correct
27 Correct 56 ms 268116 KB Output is correct
28 Correct 52 ms 263912 KB Output is correct
29 Correct 51 ms 264020 KB Output is correct
30 Correct 51 ms 264024 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 49 ms 264020 KB Output is correct
2 Correct 50 ms 264012 KB Output is correct
3 Correct 49 ms 264016 KB Output is correct
4 Correct 49 ms 263908 KB Output is correct
5 Correct 49 ms 264012 KB Output is correct
6 Correct 49 ms 264012 KB Output is correct
7 Correct 50 ms 264124 KB Output is correct
8 Correct 49 ms 264020 KB Output is correct
9 Correct 48 ms 264020 KB Output is correct
10 Correct 50 ms 264016 KB Output is correct
11 Correct 50 ms 263960 KB Output is correct
12 Correct 50 ms 263896 KB Output is correct
13 Correct 49 ms 264004 KB Output is correct
14 Correct 53 ms 264000 KB Output is correct
15 Correct 50 ms 263956 KB Output is correct
16 Correct 52 ms 268116 KB Output is correct
17 Correct 54 ms 268116 KB Output is correct
18 Correct 51 ms 264020 KB Output is correct
19 Correct 52 ms 263984 KB Output is correct
20 Correct 53 ms 268088 KB Output is correct
21 Correct 52 ms 268028 KB Output is correct
22 Correct 51 ms 264148 KB Output is correct
23 Correct 53 ms 268184 KB Output is correct
24 Correct 53 ms 268184 KB Output is correct
25 Correct 52 ms 265996 KB Output is correct
26 Correct 53 ms 268164 KB Output is correct
27 Correct 56 ms 268116 KB Output is correct
28 Correct 52 ms 263912 KB Output is correct
29 Correct 51 ms 264020 KB Output is correct
30 Correct 51 ms 264024 KB Output is correct
31 Correct 205 ms 321620 KB Output is correct
32 Correct 210 ms 321760 KB Output is correct
33 Correct 72 ms 280656 KB Output is correct
34 Correct 147 ms 297044 KB Output is correct
35 Correct 255 ms 321664 KB Output is correct
36 Correct 124 ms 317516 KB Output is correct
37 Correct 75 ms 280916 KB Output is correct
38 Correct 238 ms 317524 KB Output is correct
39 Correct 153 ms 321616 KB Output is correct
40 Correct 172 ms 302156 KB Output is correct
41 Correct 194 ms 306260 KB Output is correct
42 Correct 254 ms 318720 KB Output is correct
43 Correct 167 ms 298492 KB Output is correct
44 Correct 127 ms 293972 KB Output is correct
45 Correct 81 ms 281684 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 49 ms 264020 KB Output is correct
2 Correct 50 ms 264012 KB Output is correct
3 Correct 49 ms 264016 KB Output is correct
4 Correct 49 ms 263908 KB Output is correct
5 Correct 49 ms 264012 KB Output is correct
6 Correct 49 ms 264012 KB Output is correct
7 Correct 50 ms 264124 KB Output is correct
8 Correct 49 ms 264020 KB Output is correct
9 Correct 48 ms 264020 KB Output is correct
10 Correct 50 ms 264016 KB Output is correct
11 Correct 50 ms 263960 KB Output is correct
12 Correct 50 ms 263896 KB Output is correct
13 Correct 49 ms 264004 KB Output is correct
14 Correct 53 ms 264000 KB Output is correct
15 Correct 50 ms 263956 KB Output is correct
16 Correct 49 ms 263948 KB Output is correct
17 Correct 49 ms 264044 KB Output is correct
18 Correct 52 ms 264016 KB Output is correct
19 Correct 50 ms 264016 KB Output is correct
20 Correct 49 ms 264020 KB Output is correct
21 Correct 50 ms 264020 KB Output is correct
22 Correct 50 ms 263932 KB Output is correct
23 Correct 50 ms 263916 KB Output is correct
24 Correct 49 ms 264020 KB Output is correct
25 Correct 50 ms 264024 KB Output is correct
26 Correct 50 ms 264364 KB Output is correct
27 Correct 49 ms 264020 KB Output is correct
28 Correct 48 ms 264020 KB Output is correct
29 Correct 52 ms 264016 KB Output is correct
30 Correct 52 ms 264272 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 49 ms 264020 KB Output is correct
2 Correct 50 ms 264012 KB Output is correct
3 Correct 49 ms 264016 KB Output is correct
4 Correct 49 ms 263908 KB Output is correct
5 Correct 49 ms 264012 KB Output is correct
6 Correct 49 ms 264012 KB Output is correct
7 Correct 50 ms 264124 KB Output is correct
8 Correct 49 ms 264020 KB Output is correct
9 Correct 48 ms 264020 KB Output is correct
10 Correct 50 ms 264016 KB Output is correct
11 Correct 50 ms 263960 KB Output is correct
12 Correct 50 ms 263896 KB Output is correct
13 Correct 49 ms 264004 KB Output is correct
14 Correct 53 ms 264000 KB Output is correct
15 Correct 50 ms 263956 KB Output is correct
16 Correct 52 ms 268116 KB Output is correct
17 Correct 54 ms 268116 KB Output is correct
18 Correct 51 ms 264020 KB Output is correct
19 Correct 52 ms 263984 KB Output is correct
20 Correct 53 ms 268088 KB Output is correct
21 Correct 52 ms 268028 KB Output is correct
22 Correct 51 ms 264148 KB Output is correct
23 Correct 53 ms 268184 KB Output is correct
24 Correct 53 ms 268184 KB Output is correct
25 Correct 52 ms 265996 KB Output is correct
26 Correct 53 ms 268164 KB Output is correct
27 Correct 56 ms 268116 KB Output is correct
28 Correct 52 ms 263912 KB Output is correct
29 Correct 51 ms 264020 KB Output is correct
30 Correct 51 ms 264024 KB Output is correct
31 Correct 49 ms 263948 KB Output is correct
32 Correct 49 ms 264044 KB Output is correct
33 Correct 52 ms 264016 KB Output is correct
34 Correct 50 ms 264016 KB Output is correct
35 Correct 49 ms 264020 KB Output is correct
36 Correct 50 ms 264020 KB Output is correct
37 Correct 50 ms 263932 KB Output is correct
38 Correct 50 ms 263916 KB Output is correct
39 Correct 49 ms 264020 KB Output is correct
40 Correct 50 ms 264024 KB Output is correct
41 Correct 50 ms 264364 KB Output is correct
42 Correct 49 ms 264020 KB Output is correct
43 Correct 48 ms 264020 KB Output is correct
44 Correct 52 ms 264016 KB Output is correct
45 Correct 52 ms 264272 KB Output is correct
46 Correct 66 ms 272208 KB Output is correct
47 Correct 68 ms 272208 KB Output is correct
48 Correct 56 ms 264016 KB Output is correct
49 Correct 62 ms 268112 KB Output is correct
50 Correct 72 ms 272388 KB Output is correct
51 Correct 57 ms 264020 KB Output is correct
52 Correct 63 ms 268080 KB Output is correct
53 Correct 72 ms 272376 KB Output is correct
54 Correct 70 ms 272324 KB Output is correct
55 Correct 62 ms 268248 KB Output is correct
56 Correct 71 ms 272208 KB Output is correct
57 Correct 72 ms 272376 KB Output is correct
58 Correct 59 ms 268116 KB Output is correct
59 Correct 65 ms 268116 KB Output is correct
60 Correct 59 ms 266220 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 49 ms 264020 KB Output is correct
2 Correct 50 ms 264012 KB Output is correct
3 Correct 49 ms 264016 KB Output is correct
4 Correct 49 ms 263908 KB Output is correct
5 Correct 49 ms 264012 KB Output is correct
6 Correct 49 ms 264012 KB Output is correct
7 Correct 50 ms 264124 KB Output is correct
8 Correct 49 ms 264020 KB Output is correct
9 Correct 48 ms 264020 KB Output is correct
10 Correct 50 ms 264016 KB Output is correct
11 Correct 50 ms 263960 KB Output is correct
12 Correct 50 ms 263896 KB Output is correct
13 Correct 49 ms 264004 KB Output is correct
14 Correct 53 ms 264000 KB Output is correct
15 Correct 50 ms 263956 KB Output is correct
16 Correct 52 ms 268116 KB Output is correct
17 Correct 54 ms 268116 KB Output is correct
18 Correct 51 ms 264020 KB Output is correct
19 Correct 52 ms 263984 KB Output is correct
20 Correct 53 ms 268088 KB Output is correct
21 Correct 52 ms 268028 KB Output is correct
22 Correct 51 ms 264148 KB Output is correct
23 Correct 53 ms 268184 KB Output is correct
24 Correct 53 ms 268184 KB Output is correct
25 Correct 52 ms 265996 KB Output is correct
26 Correct 53 ms 268164 KB Output is correct
27 Correct 56 ms 268116 KB Output is correct
28 Correct 52 ms 263912 KB Output is correct
29 Correct 51 ms 264020 KB Output is correct
30 Correct 51 ms 264024 KB Output is correct
31 Correct 205 ms 321620 KB Output is correct
32 Correct 210 ms 321760 KB Output is correct
33 Correct 72 ms 280656 KB Output is correct
34 Correct 147 ms 297044 KB Output is correct
35 Correct 255 ms 321664 KB Output is correct
36 Correct 124 ms 317516 KB Output is correct
37 Correct 75 ms 280916 KB Output is correct
38 Correct 238 ms 317524 KB Output is correct
39 Correct 153 ms 321616 KB Output is correct
40 Correct 172 ms 302156 KB Output is correct
41 Correct 194 ms 306260 KB Output is correct
42 Correct 254 ms 318720 KB Output is correct
43 Correct 167 ms 298492 KB Output is correct
44 Correct 127 ms 293972 KB Output is correct
45 Correct 81 ms 281684 KB Output is correct
46 Correct 49 ms 263948 KB Output is correct
47 Correct 49 ms 264044 KB Output is correct
48 Correct 52 ms 264016 KB Output is correct
49 Correct 50 ms 264016 KB Output is correct
50 Correct 49 ms 264020 KB Output is correct
51 Correct 50 ms 264020 KB Output is correct
52 Correct 50 ms 263932 KB Output is correct
53 Correct 50 ms 263916 KB Output is correct
54 Correct 49 ms 264020 KB Output is correct
55 Correct 50 ms 264024 KB Output is correct
56 Correct 50 ms 264364 KB Output is correct
57 Correct 49 ms 264020 KB Output is correct
58 Correct 48 ms 264020 KB Output is correct
59 Correct 52 ms 264016 KB Output is correct
60 Correct 52 ms 264272 KB Output is correct
61 Correct 66 ms 272208 KB Output is correct
62 Correct 68 ms 272208 KB Output is correct
63 Correct 56 ms 264016 KB Output is correct
64 Correct 62 ms 268112 KB Output is correct
65 Correct 72 ms 272388 KB Output is correct
66 Correct 57 ms 264020 KB Output is correct
67 Correct 63 ms 268080 KB Output is correct
68 Correct 72 ms 272376 KB Output is correct
69 Correct 70 ms 272324 KB Output is correct
70 Correct 62 ms 268248 KB Output is correct
71 Correct 71 ms 272208 KB Output is correct
72 Correct 72 ms 272376 KB Output is correct
73 Correct 59 ms 268116 KB Output is correct
74 Correct 65 ms 268116 KB Output is correct
75 Correct 59 ms 266220 KB Output is correct
76 Correct 839 ms 431004 KB Output is correct
77 Correct 860 ms 434596 KB Output is correct
78 Correct 197 ms 282960 KB Output is correct
79 Correct 553 ms 336772 KB Output is correct
80 Correct 1166 ms 434988 KB Output is correct
81 Correct 237 ms 299736 KB Output is correct
82 Correct 465 ms 369748 KB Output is correct
83 Correct 1148 ms 426428 KB Output is correct
84 Correct 718 ms 427060 KB Output is correct
85 Correct 330 ms 340876 KB Output is correct
86 Correct 1269 ms 426636 KB Output is correct
87 Correct 1174 ms 422568 KB Output is correct
88 Correct 303 ms 307812 KB Output is correct
89 Correct 938 ms 385732 KB Output is correct
90 Correct 291 ms 304044 KB Output is correct