답안 #1001636

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1001636 2024-06-19T06:40:10 Z amirhoseinfar1385 Sličnost (COI23_slicnost) C++17
67 / 100
805 ms 524288 KB
#include<bits/stdc++.h>
using namespace std;
const int maxn=100000+10,lg=17;
int n,k,q,inf=1e8;
int all[maxn],allb[maxn],lnk[maxn],allroot[maxn],root=0,kaf=(1<<lg);
set<pair<int,int>>st;
map<int,long long>mp;
const int sz=(lg+1)*maxn*16;
 
struct segmentpersistant{
	struct node{
		int cl,cr;
		unsigned short ted;
		int maxa,lazy;
		node(){
			ted=0;
			cl=cr=0;
			maxa=lazy=0;
		}
	};
	vector<node>seg;
	segmentpersistant(){
		seg.resize(1);
	}
	int te=1;
	pair<int,int>comp(pair<int,int>a,pair<int,int>b,int w){
		pair<int ,int> ret=a;
		if(b.first==a.first){
			ret.second+=b.second;
		}else if(b.first>a.first){
			ret=b;
		}
		ret.first+=w;
		return ret;
	}
	void calc(int u,int l,int r){
		int len=r-l+1;
		len/=2;
		seg[u].ted=0;
		seg[u].maxa=max(seg[seg[u].cl].maxa+seg[seg[u].cl].lazy,seg[seg[u].cr].maxa+seg[seg[u].cr].lazy);
		if(seg[seg[u].cl].maxa+seg[seg[u].cl].lazy==seg[u].maxa){
			seg[u].ted+=seg[seg[u].cl].ted;
		}
		if(seg[seg[u].cr].maxa+seg[seg[u].cr].lazy==seg[u].maxa){
			seg[u].ted+=seg[seg[u].cr].ted;
		}
		if(seg[u].maxa==0){
			if(seg[u].cl==0){
				seg[u].ted+=len;
			}
			if(seg[u].cr==0){
				seg[u].ted+=len;
			}
		}
		return ;
	}
	int upd(int i,int l,int r,int tl,int tr,int w){
		if(l>r||l>tr||r<tl||tl>tr){
			return i;
		}
		int u=(int)seg.size();
		seg.push_back(seg[i]);
//		seg[te]=seg[i];
		te++;
		if(te==sz){
			exit(0);
		}
		if(l>=tl&&r<=tr){
			seg[u].lazy+=w;
			if(seg[u].cl==0&&seg[u].cr==0){
				seg[u].ted=r-l+1;
			}
			return u;
		}
		int m=(l+r)>>1;
		seg[u].cl=upd(seg[u].cl,l,m,tl,tr,w);
		seg[u].cr=upd(seg[u].cr,m+1,r,tl,tr,w);
		calc(u,l,r);
		return u;
	}
	pair<int,int> pors(int i,int l,int r,int tl,int tr){
		pair<int,int>ret;
		ret.first=max((int)seg[seg[i].cl].maxa+seg[seg[i].cl].lazy,(int)seg[seg[i].cr].maxa+seg[seg[i].cr].lazy);
		if(ret.first==(int)seg[seg[i].cl].maxa+seg[seg[i].cl].lazy){
			ret.second+=seg[seg[i].cl].ted;
		}
		if(ret.first==(int)seg[seg[i].cr].maxa+seg[seg[i].cl].lazy){
			ret.second+=seg[seg[i].cr].ted;
		}
		return ret;
	}
}segper;
 
void ezaf(int u){
	if(u<k){
		return ;
	}
	pair<int,int>z=segper.pors(allroot[u],0,kaf-1,1,n-k+1);
	st.insert(make_pair(z.first,u));
	mp[z.first]+=z.second;
	//cout<<"ziad: "<<u<<" "<<z.first<<" "<<z.second<<endl;
}
 
void kam(int u){
	if(u<k){
		return ;
	}
	pair<int,int>z=segper.pors(allroot[u],0,kaf-1,1,n-k+1);
	st.erase(make_pair(z.first,u));
	mp[z.first]-=z.second;
	//cout<<"kam: "<<u<<" "<<z.first<<" "<<z.second<<endl;
}
 
void khor(){
	auto x=(*st.rbegin());
	cout<<x.first<<" "<<mp[x.first]<<"\n";
}
 
void vorod(){
	cin>>n>>k>>q;
	for(int i=1;i<=n;i++){
		cin>>all[i];
	}
	for(int i=1;i<=n;i++){
		cin>>allb[i];
		lnk[allb[i]]=i;
	}
}
 
void pre(){
	for(int i=1;i<=n;i++){
		root=segper.upd(root,0,kaf-1,max(lnk[all[i]]-k+1,1),min(n-k+1,lnk[all[i]]),1);
		if(i-k>=1){
			root=segper.upd(root,0,kaf-1,max(lnk[all[i-k]]-k+1,1),min(n-k+1,lnk[all[i-k]]),-1);
		}
		allroot[i]=root;
		if(i>=k){
			ezaf(i);
		}
	}
}
 
void solve(){
	khor();
	for(int i=0;i<q;i++){
		int u;
		cin>>u;
		kam(u);
		root=allroot[u];
		root=segper.upd(root,0,kaf-1,max(lnk[all[u]]-k+1,1),min(n-k+1,lnk[all[u]]),-1);
		root=segper.upd(root,0,kaf-1,max(lnk[all[u+1]]-k+1,1),min(n-k+1,lnk[all[u+1]]),1);
		allroot[u]=root;
		ezaf(u);
		if(u+k<=n){
			kam(u+k);
			root=allroot[u+k];
			root=segper.upd(root,0,kaf-1,max(lnk[all[u]]-k+1,1),min(n-k+1,lnk[all[u]]),1);
			root=segper.upd(root,0,kaf-1,max(lnk[all[u+1]]-k+1,1),min(n-k+1,lnk[all[u+1]]),-1);
			allroot[u+k]=root;
			ezaf(u+k);
		}
		swap(all[u],all[u+1]);
		khor();
	}
}
 
int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	//freopen("inp.txt","r",stdin);
	vorod();
	pre();
	solve();
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 604 KB Output is correct
2 Correct 1 ms 604 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 604 KB Output is correct
5 Correct 1 ms 600 KB Output is correct
6 Correct 0 ms 604 KB Output is correct
7 Correct 0 ms 604 KB Output is correct
8 Correct 0 ms 604 KB Output is correct
9 Correct 0 ms 604 KB Output is correct
10 Correct 0 ms 604 KB Output is correct
11 Correct 0 ms 604 KB Output is correct
12 Correct 0 ms 604 KB Output is correct
13 Correct 0 ms 600 KB Output is correct
14 Correct 0 ms 604 KB Output is correct
15 Correct 0 ms 604 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 604 KB Output is correct
2 Correct 1 ms 604 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 604 KB Output is correct
5 Correct 1 ms 600 KB Output is correct
6 Correct 0 ms 604 KB Output is correct
7 Correct 0 ms 604 KB Output is correct
8 Correct 0 ms 604 KB Output is correct
9 Correct 0 ms 604 KB Output is correct
10 Correct 0 ms 604 KB Output is correct
11 Correct 0 ms 604 KB Output is correct
12 Correct 0 ms 604 KB Output is correct
13 Correct 0 ms 600 KB Output is correct
14 Correct 0 ms 604 KB Output is correct
15 Correct 0 ms 604 KB Output is correct
16 Correct 7 ms 5840 KB Output is correct
17 Correct 7 ms 5844 KB Output is correct
18 Correct 3 ms 3280 KB Output is correct
19 Correct 13 ms 10804 KB Output is correct
20 Correct 12 ms 10956 KB Output is correct
21 Correct 11 ms 10952 KB Output is correct
22 Correct 5 ms 5836 KB Output is correct
23 Correct 11 ms 11032 KB Output is correct
24 Correct 10 ms 11208 KB Output is correct
25 Correct 11 ms 10816 KB Output is correct
26 Correct 11 ms 10948 KB Output is correct
27 Correct 13 ms 10952 KB Output is correct
28 Correct 10 ms 10876 KB Output is correct
29 Correct 9 ms 10920 KB Output is correct
30 Correct 6 ms 5836 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 604 KB Output is correct
2 Correct 1 ms 604 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 604 KB Output is correct
5 Correct 1 ms 600 KB Output is correct
6 Correct 0 ms 604 KB Output is correct
7 Correct 0 ms 604 KB Output is correct
8 Correct 0 ms 604 KB Output is correct
9 Correct 0 ms 604 KB Output is correct
10 Correct 0 ms 604 KB Output is correct
11 Correct 0 ms 604 KB Output is correct
12 Correct 0 ms 604 KB Output is correct
13 Correct 0 ms 600 KB Output is correct
14 Correct 0 ms 604 KB Output is correct
15 Correct 0 ms 604 KB Output is correct
16 Correct 7 ms 5840 KB Output is correct
17 Correct 7 ms 5844 KB Output is correct
18 Correct 3 ms 3280 KB Output is correct
19 Correct 13 ms 10804 KB Output is correct
20 Correct 12 ms 10956 KB Output is correct
21 Correct 11 ms 10952 KB Output is correct
22 Correct 5 ms 5836 KB Output is correct
23 Correct 11 ms 11032 KB Output is correct
24 Correct 10 ms 11208 KB Output is correct
25 Correct 11 ms 10816 KB Output is correct
26 Correct 11 ms 10948 KB Output is correct
27 Correct 13 ms 10952 KB Output is correct
28 Correct 10 ms 10876 KB Output is correct
29 Correct 9 ms 10920 KB Output is correct
30 Correct 6 ms 5836 KB Output is correct
31 Correct 170 ms 87680 KB Output is correct
32 Correct 180 ms 87400 KB Output is correct
33 Correct 61 ms 43920 KB Output is correct
34 Correct 252 ms 167948 KB Output is correct
35 Correct 288 ms 169992 KB Output is correct
36 Correct 232 ms 169228 KB Output is correct
37 Correct 136 ms 167412 KB Output is correct
38 Correct 306 ms 170060 KB Output is correct
39 Correct 250 ms 170020 KB Output is correct
40 Correct 294 ms 168232 KB Output is correct
41 Correct 332 ms 168456 KB Output is correct
42 Correct 318 ms 169224 KB Output is correct
43 Correct 300 ms 168240 KB Output is correct
44 Correct 225 ms 167692 KB Output is correct
45 Correct 158 ms 167204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 604 KB Output is correct
2 Correct 1 ms 604 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 604 KB Output is correct
5 Correct 1 ms 600 KB Output is correct
6 Correct 0 ms 604 KB Output is correct
7 Correct 0 ms 604 KB Output is correct
8 Correct 0 ms 604 KB Output is correct
9 Correct 0 ms 604 KB Output is correct
10 Correct 0 ms 604 KB Output is correct
11 Correct 0 ms 604 KB Output is correct
12 Correct 0 ms 604 KB Output is correct
13 Correct 0 ms 600 KB Output is correct
14 Correct 0 ms 604 KB Output is correct
15 Correct 0 ms 604 KB Output is correct
16 Correct 1 ms 832 KB Output is correct
17 Correct 1 ms 800 KB Output is correct
18 Correct 0 ms 600 KB Output is correct
19 Correct 1 ms 832 KB Output is correct
20 Correct 1 ms 828 KB Output is correct
21 Correct 1 ms 604 KB Output is correct
22 Correct 1 ms 832 KB Output is correct
23 Correct 1 ms 832 KB Output is correct
24 Correct 1 ms 828 KB Output is correct
25 Correct 1 ms 832 KB Output is correct
26 Correct 1 ms 1088 KB Output is correct
27 Correct 1 ms 832 KB Output is correct
28 Correct 1 ms 832 KB Output is correct
29 Correct 1 ms 828 KB Output is correct
30 Correct 1 ms 828 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 604 KB Output is correct
2 Correct 1 ms 604 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 604 KB Output is correct
5 Correct 1 ms 600 KB Output is correct
6 Correct 0 ms 604 KB Output is correct
7 Correct 0 ms 604 KB Output is correct
8 Correct 0 ms 604 KB Output is correct
9 Correct 0 ms 604 KB Output is correct
10 Correct 0 ms 604 KB Output is correct
11 Correct 0 ms 604 KB Output is correct
12 Correct 0 ms 604 KB Output is correct
13 Correct 0 ms 600 KB Output is correct
14 Correct 0 ms 604 KB Output is correct
15 Correct 0 ms 604 KB Output is correct
16 Correct 7 ms 5840 KB Output is correct
17 Correct 7 ms 5844 KB Output is correct
18 Correct 3 ms 3280 KB Output is correct
19 Correct 13 ms 10804 KB Output is correct
20 Correct 12 ms 10956 KB Output is correct
21 Correct 11 ms 10952 KB Output is correct
22 Correct 5 ms 5836 KB Output is correct
23 Correct 11 ms 11032 KB Output is correct
24 Correct 10 ms 11208 KB Output is correct
25 Correct 11 ms 10816 KB Output is correct
26 Correct 11 ms 10948 KB Output is correct
27 Correct 13 ms 10952 KB Output is correct
28 Correct 10 ms 10876 KB Output is correct
29 Correct 9 ms 10920 KB Output is correct
30 Correct 6 ms 5836 KB Output is correct
31 Correct 1 ms 832 KB Output is correct
32 Correct 1 ms 800 KB Output is correct
33 Correct 0 ms 600 KB Output is correct
34 Correct 1 ms 832 KB Output is correct
35 Correct 1 ms 828 KB Output is correct
36 Correct 1 ms 604 KB Output is correct
37 Correct 1 ms 832 KB Output is correct
38 Correct 1 ms 832 KB Output is correct
39 Correct 1 ms 828 KB Output is correct
40 Correct 1 ms 832 KB Output is correct
41 Correct 1 ms 1088 KB Output is correct
42 Correct 1 ms 832 KB Output is correct
43 Correct 1 ms 832 KB Output is correct
44 Correct 1 ms 828 KB Output is correct
45 Correct 1 ms 828 KB Output is correct
46 Correct 34 ms 21180 KB Output is correct
47 Correct 33 ms 21344 KB Output is correct
48 Correct 8 ms 5836 KB Output is correct
49 Correct 29 ms 21156 KB Output is correct
50 Correct 37 ms 21184 KB Output is correct
51 Correct 24 ms 21176 KB Output is correct
52 Correct 29 ms 21288 KB Output is correct
53 Correct 34 ms 21180 KB Output is correct
54 Correct 31 ms 21192 KB Output is correct
55 Correct 21 ms 21188 KB Output is correct
56 Correct 35 ms 21188 KB Output is correct
57 Correct 32 ms 21348 KB Output is correct
58 Correct 25 ms 21444 KB Output is correct
59 Correct 39 ms 21156 KB Output is correct
60 Correct 23 ms 21172 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 604 KB Output is correct
2 Correct 1 ms 604 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 604 KB Output is correct
5 Correct 1 ms 600 KB Output is correct
6 Correct 0 ms 604 KB Output is correct
7 Correct 0 ms 604 KB Output is correct
8 Correct 0 ms 604 KB Output is correct
9 Correct 0 ms 604 KB Output is correct
10 Correct 0 ms 604 KB Output is correct
11 Correct 0 ms 604 KB Output is correct
12 Correct 0 ms 604 KB Output is correct
13 Correct 0 ms 600 KB Output is correct
14 Correct 0 ms 604 KB Output is correct
15 Correct 0 ms 604 KB Output is correct
16 Correct 7 ms 5840 KB Output is correct
17 Correct 7 ms 5844 KB Output is correct
18 Correct 3 ms 3280 KB Output is correct
19 Correct 13 ms 10804 KB Output is correct
20 Correct 12 ms 10956 KB Output is correct
21 Correct 11 ms 10952 KB Output is correct
22 Correct 5 ms 5836 KB Output is correct
23 Correct 11 ms 11032 KB Output is correct
24 Correct 10 ms 11208 KB Output is correct
25 Correct 11 ms 10816 KB Output is correct
26 Correct 11 ms 10948 KB Output is correct
27 Correct 13 ms 10952 KB Output is correct
28 Correct 10 ms 10876 KB Output is correct
29 Correct 9 ms 10920 KB Output is correct
30 Correct 6 ms 5836 KB Output is correct
31 Correct 170 ms 87680 KB Output is correct
32 Correct 180 ms 87400 KB Output is correct
33 Correct 61 ms 43920 KB Output is correct
34 Correct 252 ms 167948 KB Output is correct
35 Correct 288 ms 169992 KB Output is correct
36 Correct 232 ms 169228 KB Output is correct
37 Correct 136 ms 167412 KB Output is correct
38 Correct 306 ms 170060 KB Output is correct
39 Correct 250 ms 170020 KB Output is correct
40 Correct 294 ms 168232 KB Output is correct
41 Correct 332 ms 168456 KB Output is correct
42 Correct 318 ms 169224 KB Output is correct
43 Correct 300 ms 168240 KB Output is correct
44 Correct 225 ms 167692 KB Output is correct
45 Correct 158 ms 167204 KB Output is correct
46 Correct 1 ms 832 KB Output is correct
47 Correct 1 ms 800 KB Output is correct
48 Correct 0 ms 600 KB Output is correct
49 Correct 1 ms 832 KB Output is correct
50 Correct 1 ms 828 KB Output is correct
51 Correct 1 ms 604 KB Output is correct
52 Correct 1 ms 832 KB Output is correct
53 Correct 1 ms 832 KB Output is correct
54 Correct 1 ms 828 KB Output is correct
55 Correct 1 ms 832 KB Output is correct
56 Correct 1 ms 1088 KB Output is correct
57 Correct 1 ms 832 KB Output is correct
58 Correct 1 ms 832 KB Output is correct
59 Correct 1 ms 828 KB Output is correct
60 Correct 1 ms 828 KB Output is correct
61 Correct 34 ms 21180 KB Output is correct
62 Correct 33 ms 21344 KB Output is correct
63 Correct 8 ms 5836 KB Output is correct
64 Correct 29 ms 21156 KB Output is correct
65 Correct 37 ms 21184 KB Output is correct
66 Correct 24 ms 21176 KB Output is correct
67 Correct 29 ms 21288 KB Output is correct
68 Correct 34 ms 21180 KB Output is correct
69 Correct 31 ms 21192 KB Output is correct
70 Correct 21 ms 21188 KB Output is correct
71 Correct 35 ms 21188 KB Output is correct
72 Correct 32 ms 21348 KB Output is correct
73 Correct 25 ms 21444 KB Output is correct
74 Correct 39 ms 21156 KB Output is correct
75 Correct 23 ms 21172 KB Output is correct
76 Correct 729 ms 336880 KB Output is correct
77 Correct 798 ms 336612 KB Output is correct
78 Correct 209 ms 168460 KB Output is correct
79 Runtime error 805 ms 524288 KB Execution killed with signal 9
80 Halted 0 ms 0 KB -