답안 #1027060

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1027060 2024-07-18T19:41:22 Z vjudge1 Sličnost (COI23_slicnost) C++17
67 / 100
2920 ms 524288 KB
#include <bits/stdc++.h>
using namespace std;

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

int n, tl, tr, val, pos, check, id, rid; 
vector<int> roots;
int leftt[(int)2e7], rightt[(int)2e7];
array<int, 3> st[(int)2e7];



array<int, 3> TxT(array<int, 3> l, array<int, 3> r){
	
	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;
}

int add(){
	
	return id++;
}
void build(int v, int l, int r){
	if(l==r) st[v]={0, 0, 1};
	else{
		int mid=(l+r)/2;
		if(leftt[v]==-1) leftt[v]=add();
		if(rightt[v]==-1) rightt[v]=add();

		build(leftt[v], l, mid);
		build(rightt[v], mid+1, r);

		st[v]=TxT(st[leftt[v]], st[rightt[v]]);
	}
}




void update(int v, int l, int r, int nv){
	if(l==r){
		st[nv]=st[v];
		st[nv][0]+=val; st[nv][1]+=val;
	}
	else{
		int mid=(l+r) / 2;
		if(pos<=mid){
			leftt[nv]=add();
			rightt[nv]=rightt[v];
			update(leftt[v], l, mid, leftt[nv]);
		}
		else{
			leftt[nv]=leftt[v];
			rightt[nv]=add();
			update(rightt[v], mid+1, r, rightt[nv]);
		}
		st[nv]=TxT(st[leftt[nv]], st[rightt[nv]]);
	}


}
int upd(int p, int l, int v){

	if(check==0){
		pos=l, val=v;
		int id=add();
		roots.push_back(id);
		update(p, 0, n-1, id);
		return id;
	}
	else{
		pos=l, val=v;
		update(p, 0, n-1, p);
		return p;
	}
}

array<int, 3> g(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(g(leftt[v], l, mid), g(rightt[v], mid+1, r));

	}
}
array<int, 2> get(int pos, int l, int r){
	tl = l; tr = r;
	auto x= g(pos, 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;

	n=N+1;
	vector<int> a(N), b(N), pos(N), segt;
	int v=add();
		for(int l=0; l<2e7; l++) leftt[l]=rightt[l]=-1;

	build(v, 0, n-1);
	roots.push_back(v);
	int c=0;
	for(auto &i: a) cin >> i, i--;
	for(auto &i: b) cin >> i, i--, pos[i]=c++;

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

		int x=upd(y, max(0, r-k+1), 1);
		upd(x, r+1, -1);
		return (int) roots.back();
	
	};
	auto cik=[&](int y, int i){
		int r=pos[i];
		int x= upd(y, max(0, r-k+1), -1);
		upd(x, r+1, 1);
		return (int)roots.back();
	};

	for(int i=0; i<k; i++){
		ek(roots.back(), a[i]);
	}
	segt.push_back(roots.back());
	
	vector<array<int,2>> all(N-k+1);
	vector<long long> pf(N+3);

	auto x=get(roots.back(), 0, N-k);
	all[0]=x;
	pf[x[0]]+=x[1];
	int ma=x[0];

	for(int i=k; i<N; i++){
		cik(roots.back(), a[i-k]); 
		segt.push_back(ek(roots.back(), a[i]));
		auto y=get(segt.back(), 0, N-k);
		all[i-k+1]=y;
		pf[y[0]]+=y[1];

		ma=max(ma, y[0]);		
	}
		
	cout<<ma<<" "<<pf[ma]<<"\n";

	auto cikar=[&](int v, int value){
		if(v<0) return;
		
		pf[all[v][0]] -= all[v][1];
		segt[v]=cik(segt[v], value);
		auto x=get(segt[v], 0, N-k);
		all[v] = x;
		pf[all[v][0]] += all[v][1];
	};

	auto cikar2=[&](int v, int value){
		if(v>N-k) return;
		
		pf[all[v][0]] -= all[v][1];
		segt[v]=cik(segt[v], value);
		auto x=get(segt[v], 0, N-k);
		all[v] = x;
		pf[all[v][0]] += all[v][1];
	};
	auto ekle=[&](int v, int value){
		if(v<0) return;
		
		pf[all[v][0]] -= all[v][1];
		segt[v]=ek(segt[v], value);
		auto x=get(segt[v], 0, N-k);

		all[v] = x;
		pf[all[v][0]] += all[v][1];
	};

	auto ekle2=[&](int v, int value){
		if(v>N-k) return;
		
		pf[all[v][0]] -= all[v][1];
		segt[v]=ek(segt[v], value);
		auto x=get(segt[v], 0, N-k);

		all[v] = x;
		pf[all[v][0]] += all[v][1];
	};

	while(q--){
		int p; cin >> p; p--;
		
		cikar(p-k+1, a[p]);
		cikar2(p+1, a[p+1]);

		swap(a[p], a[p+1]);

		ekle(p-k+1, a[p]);
		ekle2(p+1, a[p+1]);

		if(pf[ma+1]>0) ma++;
		else if(pf[ma]==0) ma--;

		cout<<ma<<" "<<pf[ma]<<"\n";
	}
}

Compilation message

Main.cpp: In function 'void f()':
Main.cpp:6:9: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
    6 |  freopen("in.txt", "r", stdin);
      |  ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
Main.cpp:7:9: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
    7 |  freopen("out.txt", "w", stdout);
      |  ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 44 ms 157520 KB Output is correct
2 Correct 42 ms 157524 KB Output is correct
3 Correct 42 ms 157524 KB Output is correct
4 Correct 40 ms 157588 KB Output is correct
5 Correct 41 ms 157548 KB Output is correct
6 Correct 41 ms 157520 KB Output is correct
7 Correct 41 ms 157524 KB Output is correct
8 Correct 41 ms 157572 KB Output is correct
9 Correct 42 ms 157524 KB Output is correct
10 Correct 42 ms 157728 KB Output is correct
11 Correct 41 ms 157524 KB Output is correct
12 Correct 42 ms 157636 KB Output is correct
13 Correct 40 ms 157520 KB Output is correct
14 Correct 41 ms 157524 KB Output is correct
15 Correct 41 ms 157520 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 44 ms 157520 KB Output is correct
2 Correct 42 ms 157524 KB Output is correct
3 Correct 42 ms 157524 KB Output is correct
4 Correct 40 ms 157588 KB Output is correct
5 Correct 41 ms 157548 KB Output is correct
6 Correct 41 ms 157520 KB Output is correct
7 Correct 41 ms 157524 KB Output is correct
8 Correct 41 ms 157572 KB Output is correct
9 Correct 42 ms 157524 KB Output is correct
10 Correct 42 ms 157728 KB Output is correct
11 Correct 41 ms 157524 KB Output is correct
12 Correct 42 ms 157636 KB Output is correct
13 Correct 40 ms 157520 KB Output is correct
14 Correct 41 ms 157524 KB Output is correct
15 Correct 41 ms 157520 KB Output is correct
16 Correct 46 ms 161172 KB Output is correct
17 Correct 46 ms 161116 KB Output is correct
18 Correct 48 ms 159316 KB Output is correct
19 Correct 52 ms 160240 KB Output is correct
20 Correct 49 ms 161208 KB Output is correct
21 Correct 45 ms 160848 KB Output is correct
22 Correct 44 ms 159572 KB Output is correct
23 Correct 58 ms 160996 KB Output is correct
24 Correct 46 ms 161104 KB Output is correct
25 Correct 45 ms 160336 KB Output is correct
26 Correct 48 ms 160672 KB Output is correct
27 Correct 48 ms 160852 KB Output is correct
28 Correct 44 ms 160252 KB Output is correct
29 Correct 46 ms 160152 KB Output is correct
30 Correct 43 ms 159568 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 44 ms 157520 KB Output is correct
2 Correct 42 ms 157524 KB Output is correct
3 Correct 42 ms 157524 KB Output is correct
4 Correct 40 ms 157588 KB Output is correct
5 Correct 41 ms 157548 KB Output is correct
6 Correct 41 ms 157520 KB Output is correct
7 Correct 41 ms 157524 KB Output is correct
8 Correct 41 ms 157572 KB Output is correct
9 Correct 42 ms 157524 KB Output is correct
10 Correct 42 ms 157728 KB Output is correct
11 Correct 41 ms 157524 KB Output is correct
12 Correct 42 ms 157636 KB Output is correct
13 Correct 40 ms 157520 KB Output is correct
14 Correct 41 ms 157524 KB Output is correct
15 Correct 41 ms 157520 KB Output is correct
16 Correct 46 ms 161172 KB Output is correct
17 Correct 46 ms 161116 KB Output is correct
18 Correct 48 ms 159316 KB Output is correct
19 Correct 52 ms 160240 KB Output is correct
20 Correct 49 ms 161208 KB Output is correct
21 Correct 45 ms 160848 KB Output is correct
22 Correct 44 ms 159572 KB Output is correct
23 Correct 58 ms 160996 KB Output is correct
24 Correct 46 ms 161104 KB Output is correct
25 Correct 45 ms 160336 KB Output is correct
26 Correct 48 ms 160672 KB Output is correct
27 Correct 48 ms 160852 KB Output is correct
28 Correct 44 ms 160252 KB Output is correct
29 Correct 46 ms 160152 KB Output is correct
30 Correct 43 ms 159568 KB Output is correct
31 Correct 179 ms 246208 KB Output is correct
32 Correct 193 ms 245512 KB Output is correct
33 Correct 113 ms 203472 KB Output is correct
34 Correct 175 ms 224972 KB Output is correct
35 Correct 232 ms 248068 KB Output is correct
36 Correct 153 ms 242180 KB Output is correct
37 Correct 91 ms 206688 KB Output is correct
38 Correct 232 ms 243720 KB Output is correct
39 Correct 154 ms 247300 KB Output is correct
40 Correct 196 ms 228384 KB Output is correct
41 Correct 215 ms 234456 KB Output is correct
42 Correct 229 ms 241448 KB Output is correct
43 Correct 177 ms 225736 KB Output is correct
44 Correct 158 ms 221128 KB Output is correct
45 Correct 121 ms 206864 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 44 ms 157520 KB Output is correct
2 Correct 42 ms 157524 KB Output is correct
3 Correct 42 ms 157524 KB Output is correct
4 Correct 40 ms 157588 KB Output is correct
5 Correct 41 ms 157548 KB Output is correct
6 Correct 41 ms 157520 KB Output is correct
7 Correct 41 ms 157524 KB Output is correct
8 Correct 41 ms 157572 KB Output is correct
9 Correct 42 ms 157524 KB Output is correct
10 Correct 42 ms 157728 KB Output is correct
11 Correct 41 ms 157524 KB Output is correct
12 Correct 42 ms 157636 KB Output is correct
13 Correct 40 ms 157520 KB Output is correct
14 Correct 41 ms 157524 KB Output is correct
15 Correct 41 ms 157520 KB Output is correct
16 Correct 43 ms 157788 KB Output is correct
17 Correct 43 ms 157780 KB Output is correct
18 Correct 42 ms 157524 KB Output is correct
19 Correct 42 ms 157780 KB Output is correct
20 Correct 43 ms 157780 KB Output is correct
21 Correct 41 ms 157520 KB Output is correct
22 Correct 41 ms 157776 KB Output is correct
23 Correct 45 ms 157780 KB Output is correct
24 Correct 44 ms 157600 KB Output is correct
25 Correct 41 ms 157776 KB Output is correct
26 Correct 44 ms 157776 KB Output is correct
27 Correct 41 ms 157668 KB Output is correct
28 Correct 40 ms 157520 KB Output is correct
29 Correct 42 ms 157780 KB Output is correct
30 Correct 43 ms 157520 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 44 ms 157520 KB Output is correct
2 Correct 42 ms 157524 KB Output is correct
3 Correct 42 ms 157524 KB Output is correct
4 Correct 40 ms 157588 KB Output is correct
5 Correct 41 ms 157548 KB Output is correct
6 Correct 41 ms 157520 KB Output is correct
7 Correct 41 ms 157524 KB Output is correct
8 Correct 41 ms 157572 KB Output is correct
9 Correct 42 ms 157524 KB Output is correct
10 Correct 42 ms 157728 KB Output is correct
11 Correct 41 ms 157524 KB Output is correct
12 Correct 42 ms 157636 KB Output is correct
13 Correct 40 ms 157520 KB Output is correct
14 Correct 41 ms 157524 KB Output is correct
15 Correct 41 ms 157520 KB Output is correct
16 Correct 46 ms 161172 KB Output is correct
17 Correct 46 ms 161116 KB Output is correct
18 Correct 48 ms 159316 KB Output is correct
19 Correct 52 ms 160240 KB Output is correct
20 Correct 49 ms 161208 KB Output is correct
21 Correct 45 ms 160848 KB Output is correct
22 Correct 44 ms 159572 KB Output is correct
23 Correct 58 ms 160996 KB Output is correct
24 Correct 46 ms 161104 KB Output is correct
25 Correct 45 ms 160336 KB Output is correct
26 Correct 48 ms 160672 KB Output is correct
27 Correct 48 ms 160852 KB Output is correct
28 Correct 44 ms 160252 KB Output is correct
29 Correct 46 ms 160152 KB Output is correct
30 Correct 43 ms 159568 KB Output is correct
31 Correct 43 ms 157788 KB Output is correct
32 Correct 43 ms 157780 KB Output is correct
33 Correct 42 ms 157524 KB Output is correct
34 Correct 42 ms 157780 KB Output is correct
35 Correct 43 ms 157780 KB Output is correct
36 Correct 41 ms 157520 KB Output is correct
37 Correct 41 ms 157776 KB Output is correct
38 Correct 45 ms 157780 KB Output is correct
39 Correct 44 ms 157600 KB Output is correct
40 Correct 41 ms 157776 KB Output is correct
41 Correct 44 ms 157776 KB Output is correct
42 Correct 41 ms 157668 KB Output is correct
43 Correct 40 ms 157520 KB Output is correct
44 Correct 42 ms 157780 KB Output is correct
45 Correct 43 ms 157520 KB Output is correct
46 Correct 55 ms 167372 KB Output is correct
47 Correct 59 ms 167632 KB Output is correct
48 Correct 51 ms 159824 KB Output is correct
49 Correct 51 ms 163488 KB Output is correct
50 Correct 64 ms 167696 KB Output is correct
51 Correct 46 ms 160336 KB Output is correct
52 Correct 53 ms 165016 KB Output is correct
53 Correct 62 ms 167176 KB Output is correct
54 Correct 59 ms 167116 KB Output is correct
55 Correct 50 ms 163412 KB Output is correct
56 Correct 64 ms 167180 KB Output is correct
57 Correct 63 ms 167120 KB Output is correct
58 Correct 48 ms 161588 KB Output is correct
59 Correct 56 ms 165616 KB Output is correct
60 Correct 47 ms 161284 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 44 ms 157520 KB Output is correct
2 Correct 42 ms 157524 KB Output is correct
3 Correct 42 ms 157524 KB Output is correct
4 Correct 40 ms 157588 KB Output is correct
5 Correct 41 ms 157548 KB Output is correct
6 Correct 41 ms 157520 KB Output is correct
7 Correct 41 ms 157524 KB Output is correct
8 Correct 41 ms 157572 KB Output is correct
9 Correct 42 ms 157524 KB Output is correct
10 Correct 42 ms 157728 KB Output is correct
11 Correct 41 ms 157524 KB Output is correct
12 Correct 42 ms 157636 KB Output is correct
13 Correct 40 ms 157520 KB Output is correct
14 Correct 41 ms 157524 KB Output is correct
15 Correct 41 ms 157520 KB Output is correct
16 Correct 46 ms 161172 KB Output is correct
17 Correct 46 ms 161116 KB Output is correct
18 Correct 48 ms 159316 KB Output is correct
19 Correct 52 ms 160240 KB Output is correct
20 Correct 49 ms 161208 KB Output is correct
21 Correct 45 ms 160848 KB Output is correct
22 Correct 44 ms 159572 KB Output is correct
23 Correct 58 ms 160996 KB Output is correct
24 Correct 46 ms 161104 KB Output is correct
25 Correct 45 ms 160336 KB Output is correct
26 Correct 48 ms 160672 KB Output is correct
27 Correct 48 ms 160852 KB Output is correct
28 Correct 44 ms 160252 KB Output is correct
29 Correct 46 ms 160152 KB Output is correct
30 Correct 43 ms 159568 KB Output is correct
31 Correct 179 ms 246208 KB Output is correct
32 Correct 193 ms 245512 KB Output is correct
33 Correct 113 ms 203472 KB Output is correct
34 Correct 175 ms 224972 KB Output is correct
35 Correct 232 ms 248068 KB Output is correct
36 Correct 153 ms 242180 KB Output is correct
37 Correct 91 ms 206688 KB Output is correct
38 Correct 232 ms 243720 KB Output is correct
39 Correct 154 ms 247300 KB Output is correct
40 Correct 196 ms 228384 KB Output is correct
41 Correct 215 ms 234456 KB Output is correct
42 Correct 229 ms 241448 KB Output is correct
43 Correct 177 ms 225736 KB Output is correct
44 Correct 158 ms 221128 KB Output is correct
45 Correct 121 ms 206864 KB Output is correct
46 Correct 43 ms 157788 KB Output is correct
47 Correct 43 ms 157780 KB Output is correct
48 Correct 42 ms 157524 KB Output is correct
49 Correct 42 ms 157780 KB Output is correct
50 Correct 43 ms 157780 KB Output is correct
51 Correct 41 ms 157520 KB Output is correct
52 Correct 41 ms 157776 KB Output is correct
53 Correct 45 ms 157780 KB Output is correct
54 Correct 44 ms 157600 KB Output is correct
55 Correct 41 ms 157776 KB Output is correct
56 Correct 44 ms 157776 KB Output is correct
57 Correct 41 ms 157668 KB Output is correct
58 Correct 40 ms 157520 KB Output is correct
59 Correct 42 ms 157780 KB Output is correct
60 Correct 43 ms 157520 KB Output is correct
61 Correct 55 ms 167372 KB Output is correct
62 Correct 59 ms 167632 KB Output is correct
63 Correct 51 ms 159824 KB Output is correct
64 Correct 51 ms 163488 KB Output is correct
65 Correct 64 ms 167696 KB Output is correct
66 Correct 46 ms 160336 KB Output is correct
67 Correct 53 ms 165016 KB Output is correct
68 Correct 62 ms 167176 KB Output is correct
69 Correct 59 ms 167116 KB Output is correct
70 Correct 50 ms 163412 KB Output is correct
71 Correct 64 ms 167180 KB Output is correct
72 Correct 63 ms 167120 KB Output is correct
73 Correct 48 ms 161588 KB Output is correct
74 Correct 56 ms 165616 KB Output is correct
75 Correct 47 ms 161284 KB Output is correct
76 Runtime error 2920 ms 524288 KB Execution killed with signal 9
77 Halted 0 ms 0 KB -