Submission #810616

# Submission time Handle Problem Language Result Execution time Memory
810616 2023-08-06T12:24:22 Z qwerasdfzxcl Sličnost (COI23_slicnost) C++17
100 / 100
793 ms 46616 KB
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;

struct Node{
	int mx;
	ll cnt;
	
	Node(){}
	Node(int _mx, ll _cnt): mx(_mx), cnt(_cnt) {}

	Node operator + (const Node &N) const{
		if (mx > N.mx) return *this;
		if (mx < N.mx) return N;
		return Node(mx, cnt + N.cnt);
	}
};

struct Seg1{
	Node tree[800800];
	int lazy[800800];

	void init(int i, int l, int r){
		tree[i] = Node(0, r-l+1);
		lazy[i] = 0;
		if (l==r) return;

		int m = (l+r)>>1;
		init(i<<1, l, m); init(i<<1|1, m+1, r);
	}

	void propagate(int i, int l, int r){
		tree[i].mx += lazy[i];

		if (l!=r){
			lazy[i<<1] += lazy[i];
			lazy[i<<1|1] += lazy[i];
		}

		lazy[i] = 0;
	}

	void update(int i, int l, int r, int s, int e, int x){
		propagate(i, l, r);
		if (r<s || e<l) return;
		if (s<=l && r<=e){
			lazy[i] += x;
			propagate(i, l, r);
			return;
		}

		int m = (l+r)>>1;
		update(i<<1, l, m, s, e, x); update(i<<1|1, m+1, r, s, e, x);
		tree[i] = tree[i<<1] + tree[i<<1|1];
	}

	Node query(int i, int l, int r, int s, int e){
		propagate(i, l, r);
		if (r<s || e<l) return Node(0, 0);
		if (s<=l && r<=e) return tree[i];

		int m = (l+r)>>1;
		return query(i<<1, l, m, s, e) + query(i<<1|1, m+1, r, s, e);
	}
}tree1;

struct Seg2{
	Node tree[800800];
	Node lazy[800800];

	void init(int i, int l, int r){
		tree[i] = Node(0, 0);
		lazy[i] = Node(0, 0);
		if (l==r) return;

		int m = (l+r)>>1;
		init(i<<1, l, m); init(i<<1|1, m+1, r);
	}

	void propagate(int i, int l, int r){
		if (l!=r){
			lazy[i<<1] = lazy[i<<1] + lazy[i];
			lazy[i<<1|1] = lazy[i<<1|1] + lazy[i];
		}

		else{
			tree[i] = tree[i] + lazy[i];
		}

		lazy[i] = Node(0, 0);
	}

	void update(int i, int l, int r, int s, int e, Node x){
		propagate(i, l, r);
		if (r<s || e<l) return;
		if (s<=l && r<=e){
			lazy[i] = lazy[i] + x;
			propagate(i, l, r);
			return;
		}

		int m = (l+r)>>1;
		update(i<<1, l, m, s, e, x); update(i<<1|1, m+1, r, s, e, x);
	}

	Node query(int i, int l, int r, int p){
		propagate(i, l, r);
		if (r<p || p<l) return Node(0, 0);
		if (l==r) return tree[i];

		int m = (l+r)>>1;
		return query(i<<1, l, m, p) + query(i<<1|1, m+1, r, p);
	}
}tree2;

int a[100100], b[100100], X[100100], Y[100100];
vector<array<int, 3>> E[200200];
vector<array<int, 4>> F[200200];

void print(Node x){
	printf("%d %lld\n", x.mx, x.cnt);
}

int main(){
	int n, k, q;
	scanf("%d %d %d", &n, &k, &q);

	for (int i=1;i<=n;i++){
		scanf("%d", a+i);
		X[a[i]] = i;
	} 
	for (int i=1;i<=n;i++){
		scanf("%d", b+i);
		Y[b[i]] = i;
	} 

	for (int i=1;i<=n;i++){
		E[X[i]].push_back({Y[i], Y[i]+k-1, 1});
		E[X[i]+k].push_back({Y[i], Y[i]+k-1, -1});
	}

	for (int i=1;i<=q;i++){
		int x;
		scanf("%d", &x);
		swap(a[x], a[x+1]);
		X[a[x]] = x;
		F[x].push_back({i, Y[a[x]], Y[a[x]]+k-1, 1});
		F[x+k].push_back({i, Y[a[x]], Y[a[x]]+k-1, -1});

		X[a[x+1]] = x+1;
		F[x].push_back({i, Y[a[x+1]], Y[a[x+1]]+k-1, -1});
		F[x+k].push_back({i, Y[a[x+1]], Y[a[x+1]]+k-1, 1});
	}

	tree1.init(1, 1, n+k-1);
	tree2.init(1, 0, q);

	for (int i=1;i<=n;i++){
		for (auto &[l, r, x]:E[i]) tree1.update(1, 1, n+k-1, l, r, x);
		if (i<k) continue;

		if (F[i].empty()){
			tree2.update(1, 0, q, 0, q, tree1.query(1, 1, n+k-1, k, n));
			continue;
		}

		tree2.update(1, 0, q, 0, F[i][0][0]-1, tree1.query(1, 1, n+k-1, k, n));
		for (int j=0;j<(int)F[i].size();j++){
			tree1.update(1, 1, n+k-1, F[i][j][1], F[i][j][2], F[i][j][3]);
			if (j+1<(int)F[i].size() && F[i][j][0]==F[i][j+1][0]) continue;

			tree2.update(1, 0, q, F[i][j][0], (j+1<(int)F[i].size())?(F[i][j+1][0]-1):q, tree1.query(1, 1, n+k-1, k, n));
		}

		for (int j=0;j<(int)F[i].size();j++){
			tree1.update(1, 1, n+k-1, F[i][j][1], F[i][j][2], -F[i][j][3]);
		}
	}

	for (int i=0;i<=q;i++) print(tree2.query(1, 0, q, i));
}

Compilation message

Main.cpp: In function 'int main()':
Main.cpp:127:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
  127 |  scanf("%d %d %d", &n, &k, &q);
      |  ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:130:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
  130 |   scanf("%d", a+i);
      |   ~~~~~^~~~~~~~~~~
Main.cpp:134:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
  134 |   scanf("%d", b+i);
      |   ~~~~~^~~~~~~~~~~
Main.cpp:145:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
  145 |   scanf("%d", &x);
      |   ~~~~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 5 ms 9720 KB Output is correct
2 Correct 5 ms 9684 KB Output is correct
3 Correct 4 ms 9684 KB Output is correct
4 Correct 5 ms 9684 KB Output is correct
5 Correct 5 ms 9648 KB Output is correct
6 Correct 5 ms 9684 KB Output is correct
7 Correct 5 ms 9684 KB Output is correct
8 Correct 6 ms 9684 KB Output is correct
9 Correct 5 ms 9768 KB Output is correct
10 Correct 6 ms 9684 KB Output is correct
11 Correct 7 ms 9684 KB Output is correct
12 Correct 5 ms 9684 KB Output is correct
13 Correct 5 ms 9684 KB Output is correct
14 Correct 5 ms 9684 KB Output is correct
15 Correct 5 ms 9684 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 9720 KB Output is correct
2 Correct 5 ms 9684 KB Output is correct
3 Correct 4 ms 9684 KB Output is correct
4 Correct 5 ms 9684 KB Output is correct
5 Correct 5 ms 9648 KB Output is correct
6 Correct 5 ms 9684 KB Output is correct
7 Correct 5 ms 9684 KB Output is correct
8 Correct 6 ms 9684 KB Output is correct
9 Correct 5 ms 9768 KB Output is correct
10 Correct 6 ms 9684 KB Output is correct
11 Correct 7 ms 9684 KB Output is correct
12 Correct 5 ms 9684 KB Output is correct
13 Correct 5 ms 9684 KB Output is correct
14 Correct 5 ms 9684 KB Output is correct
15 Correct 5 ms 9684 KB Output is correct
16 Correct 9 ms 10256 KB Output is correct
17 Correct 10 ms 10240 KB Output is correct
18 Correct 9 ms 10780 KB Output is correct
19 Correct 10 ms 10404 KB Output is correct
20 Correct 10 ms 10324 KB Output is correct
21 Correct 10 ms 10324 KB Output is correct
22 Correct 8 ms 10708 KB Output is correct
23 Correct 10 ms 10324 KB Output is correct
24 Correct 10 ms 10324 KB Output is correct
25 Correct 11 ms 10276 KB Output is correct
26 Correct 12 ms 10324 KB Output is correct
27 Correct 11 ms 10240 KB Output is correct
28 Correct 10 ms 10356 KB Output is correct
29 Correct 10 ms 10324 KB Output is correct
30 Correct 9 ms 10708 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 9720 KB Output is correct
2 Correct 5 ms 9684 KB Output is correct
3 Correct 4 ms 9684 KB Output is correct
4 Correct 5 ms 9684 KB Output is correct
5 Correct 5 ms 9648 KB Output is correct
6 Correct 5 ms 9684 KB Output is correct
7 Correct 5 ms 9684 KB Output is correct
8 Correct 6 ms 9684 KB Output is correct
9 Correct 5 ms 9768 KB Output is correct
10 Correct 6 ms 9684 KB Output is correct
11 Correct 7 ms 9684 KB Output is correct
12 Correct 5 ms 9684 KB Output is correct
13 Correct 5 ms 9684 KB Output is correct
14 Correct 5 ms 9684 KB Output is correct
15 Correct 5 ms 9684 KB Output is correct
16 Correct 9 ms 10256 KB Output is correct
17 Correct 10 ms 10240 KB Output is correct
18 Correct 9 ms 10780 KB Output is correct
19 Correct 10 ms 10404 KB Output is correct
20 Correct 10 ms 10324 KB Output is correct
21 Correct 10 ms 10324 KB Output is correct
22 Correct 8 ms 10708 KB Output is correct
23 Correct 10 ms 10324 KB Output is correct
24 Correct 10 ms 10324 KB Output is correct
25 Correct 11 ms 10276 KB Output is correct
26 Correct 12 ms 10324 KB Output is correct
27 Correct 11 ms 10240 KB Output is correct
28 Correct 10 ms 10356 KB Output is correct
29 Correct 10 ms 10324 KB Output is correct
30 Correct 9 ms 10708 KB Output is correct
31 Correct 96 ms 20332 KB Output is correct
32 Correct 125 ms 20188 KB Output is correct
33 Correct 117 ms 28672 KB Output is correct
34 Correct 160 ms 27020 KB Output is correct
35 Correct 168 ms 20472 KB Output is correct
36 Correct 126 ms 20404 KB Output is correct
37 Correct 81 ms 28560 KB Output is correct
38 Correct 173 ms 20224 KB Output is correct
39 Correct 130 ms 20568 KB Output is correct
40 Correct 153 ms 21348 KB Output is correct
41 Correct 153 ms 21328 KB Output is correct
42 Correct 176 ms 20368 KB Output is correct
43 Correct 152 ms 26856 KB Output is correct
44 Correct 154 ms 27304 KB Output is correct
45 Correct 140 ms 28260 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 9720 KB Output is correct
2 Correct 5 ms 9684 KB Output is correct
3 Correct 4 ms 9684 KB Output is correct
4 Correct 5 ms 9684 KB Output is correct
5 Correct 5 ms 9648 KB Output is correct
6 Correct 5 ms 9684 KB Output is correct
7 Correct 5 ms 9684 KB Output is correct
8 Correct 6 ms 9684 KB Output is correct
9 Correct 5 ms 9768 KB Output is correct
10 Correct 6 ms 9684 KB Output is correct
11 Correct 7 ms 9684 KB Output is correct
12 Correct 5 ms 9684 KB Output is correct
13 Correct 5 ms 9684 KB Output is correct
14 Correct 5 ms 9684 KB Output is correct
15 Correct 5 ms 9684 KB Output is correct
16 Correct 5 ms 9684 KB Output is correct
17 Correct 5 ms 9684 KB Output is correct
18 Correct 8 ms 9684 KB Output is correct
19 Correct 7 ms 9748 KB Output is correct
20 Correct 7 ms 9700 KB Output is correct
21 Correct 5 ms 9684 KB Output is correct
22 Correct 5 ms 9684 KB Output is correct
23 Correct 5 ms 9684 KB Output is correct
24 Correct 5 ms 9684 KB Output is correct
25 Correct 5 ms 9780 KB Output is correct
26 Correct 5 ms 9684 KB Output is correct
27 Correct 6 ms 9684 KB Output is correct
28 Correct 8 ms 9684 KB Output is correct
29 Correct 6 ms 9716 KB Output is correct
30 Correct 7 ms 9684 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 9720 KB Output is correct
2 Correct 5 ms 9684 KB Output is correct
3 Correct 4 ms 9684 KB Output is correct
4 Correct 5 ms 9684 KB Output is correct
5 Correct 5 ms 9648 KB Output is correct
6 Correct 5 ms 9684 KB Output is correct
7 Correct 5 ms 9684 KB Output is correct
8 Correct 6 ms 9684 KB Output is correct
9 Correct 5 ms 9768 KB Output is correct
10 Correct 6 ms 9684 KB Output is correct
11 Correct 7 ms 9684 KB Output is correct
12 Correct 5 ms 9684 KB Output is correct
13 Correct 5 ms 9684 KB Output is correct
14 Correct 5 ms 9684 KB Output is correct
15 Correct 5 ms 9684 KB Output is correct
16 Correct 9 ms 10256 KB Output is correct
17 Correct 10 ms 10240 KB Output is correct
18 Correct 9 ms 10780 KB Output is correct
19 Correct 10 ms 10404 KB Output is correct
20 Correct 10 ms 10324 KB Output is correct
21 Correct 10 ms 10324 KB Output is correct
22 Correct 8 ms 10708 KB Output is correct
23 Correct 10 ms 10324 KB Output is correct
24 Correct 10 ms 10324 KB Output is correct
25 Correct 11 ms 10276 KB Output is correct
26 Correct 12 ms 10324 KB Output is correct
27 Correct 11 ms 10240 KB Output is correct
28 Correct 10 ms 10356 KB Output is correct
29 Correct 10 ms 10324 KB Output is correct
30 Correct 9 ms 10708 KB Output is correct
31 Correct 5 ms 9684 KB Output is correct
32 Correct 5 ms 9684 KB Output is correct
33 Correct 8 ms 9684 KB Output is correct
34 Correct 7 ms 9748 KB Output is correct
35 Correct 7 ms 9700 KB Output is correct
36 Correct 5 ms 9684 KB Output is correct
37 Correct 5 ms 9684 KB Output is correct
38 Correct 5 ms 9684 KB Output is correct
39 Correct 5 ms 9684 KB Output is correct
40 Correct 5 ms 9780 KB Output is correct
41 Correct 5 ms 9684 KB Output is correct
42 Correct 6 ms 9684 KB Output is correct
43 Correct 8 ms 9684 KB Output is correct
44 Correct 6 ms 9716 KB Output is correct
45 Correct 7 ms 9684 KB Output is correct
46 Correct 23 ms 11260 KB Output is correct
47 Correct 29 ms 11220 KB Output is correct
48 Correct 12 ms 11676 KB Output is correct
49 Correct 33 ms 11380 KB Output is correct
50 Correct 31 ms 11340 KB Output is correct
51 Correct 14 ms 11776 KB Output is correct
52 Correct 27 ms 11328 KB Output is correct
53 Correct 31 ms 11308 KB Output is correct
54 Correct 29 ms 11264 KB Output is correct
55 Correct 21 ms 11404 KB Output is correct
56 Correct 32 ms 11284 KB Output is correct
57 Correct 46 ms 11288 KB Output is correct
58 Correct 17 ms 11732 KB Output is correct
59 Correct 30 ms 11340 KB Output is correct
60 Correct 17 ms 11724 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 9720 KB Output is correct
2 Correct 5 ms 9684 KB Output is correct
3 Correct 4 ms 9684 KB Output is correct
4 Correct 5 ms 9684 KB Output is correct
5 Correct 5 ms 9648 KB Output is correct
6 Correct 5 ms 9684 KB Output is correct
7 Correct 5 ms 9684 KB Output is correct
8 Correct 6 ms 9684 KB Output is correct
9 Correct 5 ms 9768 KB Output is correct
10 Correct 6 ms 9684 KB Output is correct
11 Correct 7 ms 9684 KB Output is correct
12 Correct 5 ms 9684 KB Output is correct
13 Correct 5 ms 9684 KB Output is correct
14 Correct 5 ms 9684 KB Output is correct
15 Correct 5 ms 9684 KB Output is correct
16 Correct 9 ms 10256 KB Output is correct
17 Correct 10 ms 10240 KB Output is correct
18 Correct 9 ms 10780 KB Output is correct
19 Correct 10 ms 10404 KB Output is correct
20 Correct 10 ms 10324 KB Output is correct
21 Correct 10 ms 10324 KB Output is correct
22 Correct 8 ms 10708 KB Output is correct
23 Correct 10 ms 10324 KB Output is correct
24 Correct 10 ms 10324 KB Output is correct
25 Correct 11 ms 10276 KB Output is correct
26 Correct 12 ms 10324 KB Output is correct
27 Correct 11 ms 10240 KB Output is correct
28 Correct 10 ms 10356 KB Output is correct
29 Correct 10 ms 10324 KB Output is correct
30 Correct 9 ms 10708 KB Output is correct
31 Correct 96 ms 20332 KB Output is correct
32 Correct 125 ms 20188 KB Output is correct
33 Correct 117 ms 28672 KB Output is correct
34 Correct 160 ms 27020 KB Output is correct
35 Correct 168 ms 20472 KB Output is correct
36 Correct 126 ms 20404 KB Output is correct
37 Correct 81 ms 28560 KB Output is correct
38 Correct 173 ms 20224 KB Output is correct
39 Correct 130 ms 20568 KB Output is correct
40 Correct 153 ms 21348 KB Output is correct
41 Correct 153 ms 21328 KB Output is correct
42 Correct 176 ms 20368 KB Output is correct
43 Correct 152 ms 26856 KB Output is correct
44 Correct 154 ms 27304 KB Output is correct
45 Correct 140 ms 28260 KB Output is correct
46 Correct 5 ms 9684 KB Output is correct
47 Correct 5 ms 9684 KB Output is correct
48 Correct 8 ms 9684 KB Output is correct
49 Correct 7 ms 9748 KB Output is correct
50 Correct 7 ms 9700 KB Output is correct
51 Correct 5 ms 9684 KB Output is correct
52 Correct 5 ms 9684 KB Output is correct
53 Correct 5 ms 9684 KB Output is correct
54 Correct 5 ms 9684 KB Output is correct
55 Correct 5 ms 9780 KB Output is correct
56 Correct 5 ms 9684 KB Output is correct
57 Correct 6 ms 9684 KB Output is correct
58 Correct 8 ms 9684 KB Output is correct
59 Correct 6 ms 9716 KB Output is correct
60 Correct 7 ms 9684 KB Output is correct
61 Correct 23 ms 11260 KB Output is correct
62 Correct 29 ms 11220 KB Output is correct
63 Correct 12 ms 11676 KB Output is correct
64 Correct 33 ms 11380 KB Output is correct
65 Correct 31 ms 11340 KB Output is correct
66 Correct 14 ms 11776 KB Output is correct
67 Correct 27 ms 11328 KB Output is correct
68 Correct 31 ms 11308 KB Output is correct
69 Correct 29 ms 11264 KB Output is correct
70 Correct 21 ms 11404 KB Output is correct
71 Correct 32 ms 11284 KB Output is correct
72 Correct 46 ms 11288 KB Output is correct
73 Correct 17 ms 11732 KB Output is correct
74 Correct 30 ms 11340 KB Output is correct
75 Correct 17 ms 11724 KB Output is correct
76 Correct 492 ms 38348 KB Output is correct
77 Correct 628 ms 38688 KB Output is correct
78 Correct 225 ms 46616 KB Output is correct
79 Correct 533 ms 44836 KB Output is correct
80 Correct 793 ms 38744 KB Output is correct
81 Correct 269 ms 46108 KB Output is correct
82 Correct 565 ms 44708 KB Output is correct
83 Correct 738 ms 38104 KB Output is correct
84 Correct 692 ms 38516 KB Output is correct
85 Correct 381 ms 42668 KB Output is correct
86 Correct 789 ms 38088 KB Output is correct
87 Correct 755 ms 38100 KB Output is correct
88 Correct 354 ms 45736 KB Output is correct
89 Correct 758 ms 38488 KB Output is correct
90 Correct 398 ms 45984 KB Output is correct