답안 #1026775

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1026775 2024-07-18T10:57:34 Z vjudge1 Sličnost (COI23_slicnost) C++17
57 / 100
3000 ms 13140 KB
#include <bits/stdc++.h>
using namespace std;

#define int long long

void f(){
	#ifndef ONLINE_JUDGE
	freopen("in.txt", "r", stdin);
	freopen("out.txt", "w", stdout);
	#endif
}

struct segtree{
	int n, tl, tr, val, pos ; 
	vector<array<int , 3>> st;

	array<int, 3> TxT(array<int, 3> l, array<int, 3> r){
		// leftsum ma count
		array<int, 3> res={0, 0, 0};
	

		res[0]=l[0]+r[0];
		res[1]=max(l[1], l[0]+r[1]);

		if(l[1]==res[1]) res[2]+=l[2];
		if(r[1]+l[0]==res[1]) res[2]+=r[2];

		return res;
	}

	




	segtree(int _n){
		n=_n;
		st.resize(4*n);

		build(1, 0, n-1);
	}

	void build(int v, int l, int r){
		if(l==r) st[v]={0, 0, 1};
		else{
			int mid=(l+r) / 2;
			build(v*2, l, mid);
			build(v*2+1, mid+1, r);

			st[v]=TxT(st[v*2], st[v*2+1]);

		}
	}
	void update(int v, int l, int r){
		if(l==r&&l==pos){
			st[v][1]+=val;
			st[v][0]+=val;
		}
		else{
			int mid=(l+r) / 2;
			if(pos<=mid)update(v*2, l, mid);
			else update(v*2+1, mid+1, r);

			st[v]=TxT(st[v*2], st[v*2+1]);
		}


	}
	void upd(int l, int v){
		pos=l, val=v;
		if(pos<n)
		update(1, 0, n-1);
	}

	array<int, 3> get(int v, int l, int r){
		if(l>tr||r<tl) return {0, 0, 0};
		else if(l>=tl&&r<=tr) return st[v];
		else{
			int mid=(l+r) /2;
			return TxT(get(v*2, l, mid), get(v*2+1, mid+1, r));

		}
	}
	array<int, 2> get(int l, int r){
		tl = l; tr = r;

		auto x=get(1, 0, n-1);
		return {x[1], x[2]};
	}
};

signed main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);

	//f();

	int n, k, q; cin >> n >> k >> q;

	segtree st(n);

	vector<int> a(n), b(n), pos(n);
	int c=0;
	for(auto &i: a) cin >> i, i--;
	for(auto &i: b) cin >> i, i--, pos[i]=c++;

	auto ek=[&](int i){
		int r=pos[i];

		st.upd(max(0LL, r-k+1), 1);
		st.upd(min(n-k+1, r+1), -1);
	};
	auto cik=[&](int i){
		int r=pos[i];
		st.upd(max(0LL, r-k+1), -1);
		st.upd(min(n-k+1, r+1), 1);
	};

	for(int i=0; i<k; i++){
		ek(a[i]);
	}

	
	auto x=st.get(0, n-k);

	for(int i=k; i<n; i++){
		cik(a[i-k]); ek(a[i]);
		auto y=st.get(0, n-k);
		if(x[0]==y[0]) x[1]+=y[1];
		else if(x[0]<y[0]) x=y;	
	}

	cout<<x[0]<<" "<<x[1]<<"\n";
	while(q--){
		int p; cin >> p;
		p--;
		swap(a[p], a[p+1]);

		st.build(1, 0, n-1);


		for(int i=0; i<k; i++){
			ek(a[i]);
		}
		auto x=st.get(0, n-k);

		for(int i=k; i<n; i++){
			cik(a[i-k]); ek(a[i]);
			auto y=st.get(0, n-k);
			if(x[0]==y[0]) x[1]+=y[1];
			else if(x[0]<y[0]) x=y;
		}

		cout<<x[0]<<" "<<x[1]<<"\n";
	}
}

Compilation message

Main.cpp: In function 'void f()':
Main.cpp:8:9: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
    8 |  freopen("in.txt", "r", stdin);
      |  ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
Main.cpp:9:9: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
    9 |  freopen("out.txt", "w", stdout);
      |  ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 456 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 456 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 3 ms 860 KB Output is correct
17 Correct 3 ms 860 KB Output is correct
18 Correct 1 ms 860 KB Output is correct
19 Correct 2 ms 860 KB Output is correct
20 Correct 4 ms 860 KB Output is correct
21 Correct 3 ms 860 KB Output is correct
22 Correct 1 ms 860 KB Output is correct
23 Correct 4 ms 1068 KB Output is correct
24 Correct 3 ms 860 KB Output is correct
25 Correct 3 ms 860 KB Output is correct
26 Correct 3 ms 860 KB Output is correct
27 Correct 4 ms 860 KB Output is correct
28 Correct 3 ms 856 KB Output is correct
29 Correct 2 ms 860 KB Output is correct
30 Correct 2 ms 860 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 456 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 3 ms 860 KB Output is correct
17 Correct 3 ms 860 KB Output is correct
18 Correct 1 ms 860 KB Output is correct
19 Correct 2 ms 860 KB Output is correct
20 Correct 4 ms 860 KB Output is correct
21 Correct 3 ms 860 KB Output is correct
22 Correct 1 ms 860 KB Output is correct
23 Correct 4 ms 1068 KB Output is correct
24 Correct 3 ms 860 KB Output is correct
25 Correct 3 ms 860 KB Output is correct
26 Correct 3 ms 860 KB Output is correct
27 Correct 4 ms 860 KB Output is correct
28 Correct 3 ms 856 KB Output is correct
29 Correct 2 ms 860 KB Output is correct
30 Correct 2 ms 860 KB Output is correct
31 Correct 59 ms 12520 KB Output is correct
32 Correct 79 ms 12380 KB Output is correct
33 Correct 30 ms 12628 KB Output is correct
34 Correct 56 ms 12692 KB Output is correct
35 Correct 101 ms 12892 KB Output is correct
36 Correct 49 ms 12368 KB Output is correct
37 Correct 29 ms 12892 KB Output is correct
38 Correct 93 ms 12280 KB Output is correct
39 Correct 62 ms 12892 KB Output is correct
40 Correct 64 ms 12380 KB Output is correct
41 Correct 73 ms 12592 KB Output is correct
42 Correct 100 ms 12376 KB Output is correct
43 Correct 58 ms 12380 KB Output is correct
44 Correct 51 ms 13140 KB Output is correct
45 Correct 32 ms 12632 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 456 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 2 ms 348 KB Output is correct
17 Correct 2 ms 348 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 1 ms 452 KB Output is correct
23 Correct 2 ms 348 KB Output is correct
24 Correct 1 ms 476 KB Output is correct
25 Correct 1 ms 344 KB Output is correct
26 Correct 2 ms 348 KB Output is correct
27 Correct 1 ms 348 KB Output is correct
28 Correct 1 ms 348 KB Output is correct
29 Correct 1 ms 348 KB Output is correct
30 Correct 1 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 456 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 3 ms 860 KB Output is correct
17 Correct 3 ms 860 KB Output is correct
18 Correct 1 ms 860 KB Output is correct
19 Correct 2 ms 860 KB Output is correct
20 Correct 4 ms 860 KB Output is correct
21 Correct 3 ms 860 KB Output is correct
22 Correct 1 ms 860 KB Output is correct
23 Correct 4 ms 1068 KB Output is correct
24 Correct 3 ms 860 KB Output is correct
25 Correct 3 ms 860 KB Output is correct
26 Correct 3 ms 860 KB Output is correct
27 Correct 4 ms 860 KB Output is correct
28 Correct 3 ms 856 KB Output is correct
29 Correct 2 ms 860 KB Output is correct
30 Correct 2 ms 860 KB Output is correct
31 Correct 2 ms 348 KB Output is correct
32 Correct 2 ms 348 KB Output is correct
33 Correct 1 ms 348 KB Output is correct
34 Correct 1 ms 348 KB Output is correct
35 Correct 1 ms 348 KB Output is correct
36 Correct 1 ms 348 KB Output is correct
37 Correct 1 ms 452 KB Output is correct
38 Correct 2 ms 348 KB Output is correct
39 Correct 1 ms 476 KB Output is correct
40 Correct 1 ms 344 KB Output is correct
41 Correct 2 ms 348 KB Output is correct
42 Correct 1 ms 348 KB Output is correct
43 Correct 1 ms 348 KB Output is correct
44 Correct 1 ms 348 KB Output is correct
45 Correct 1 ms 348 KB Output is correct
46 Execution timed out 3057 ms 1116 KB Time limit exceeded
47 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 456 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 3 ms 860 KB Output is correct
17 Correct 3 ms 860 KB Output is correct
18 Correct 1 ms 860 KB Output is correct
19 Correct 2 ms 860 KB Output is correct
20 Correct 4 ms 860 KB Output is correct
21 Correct 3 ms 860 KB Output is correct
22 Correct 1 ms 860 KB Output is correct
23 Correct 4 ms 1068 KB Output is correct
24 Correct 3 ms 860 KB Output is correct
25 Correct 3 ms 860 KB Output is correct
26 Correct 3 ms 860 KB Output is correct
27 Correct 4 ms 860 KB Output is correct
28 Correct 3 ms 856 KB Output is correct
29 Correct 2 ms 860 KB Output is correct
30 Correct 2 ms 860 KB Output is correct
31 Correct 59 ms 12520 KB Output is correct
32 Correct 79 ms 12380 KB Output is correct
33 Correct 30 ms 12628 KB Output is correct
34 Correct 56 ms 12692 KB Output is correct
35 Correct 101 ms 12892 KB Output is correct
36 Correct 49 ms 12368 KB Output is correct
37 Correct 29 ms 12892 KB Output is correct
38 Correct 93 ms 12280 KB Output is correct
39 Correct 62 ms 12892 KB Output is correct
40 Correct 64 ms 12380 KB Output is correct
41 Correct 73 ms 12592 KB Output is correct
42 Correct 100 ms 12376 KB Output is correct
43 Correct 58 ms 12380 KB Output is correct
44 Correct 51 ms 13140 KB Output is correct
45 Correct 32 ms 12632 KB Output is correct
46 Correct 2 ms 348 KB Output is correct
47 Correct 2 ms 348 KB Output is correct
48 Correct 1 ms 348 KB Output is correct
49 Correct 1 ms 348 KB Output is correct
50 Correct 1 ms 348 KB Output is correct
51 Correct 1 ms 348 KB Output is correct
52 Correct 1 ms 452 KB Output is correct
53 Correct 2 ms 348 KB Output is correct
54 Correct 1 ms 476 KB Output is correct
55 Correct 1 ms 344 KB Output is correct
56 Correct 2 ms 348 KB Output is correct
57 Correct 1 ms 348 KB Output is correct
58 Correct 1 ms 348 KB Output is correct
59 Correct 1 ms 348 KB Output is correct
60 Correct 1 ms 348 KB Output is correct
61 Execution timed out 3057 ms 1116 KB Time limit exceeded
62 Halted 0 ms 0 KB -