Submission #1001563

# Submission time Handle Problem Language Result Execution time Memory
1001563 2024-06-19T05:52:41 Z amirhoseinfar1385 Sličnost (COI23_slicnost) C++17
67 / 100
3000 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*10;
 
struct segmentpersistant{
	struct node{
		int cl,cr,ted;
		int maxa,lazy;
		node(){
			ted=0;
			cl=cr=0;
			maxa=lazy=0;
		}
	};
	node seg[sz];
	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,int wtf=0){
		if(l>r||l>tr||r<tl||tl>tr){
			return i;
		}
		int u=te;
		seg[te]=seg[i];
		te++;
		if(te==sz){
			assert(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,wtf);
		seg[u].cr=upd(seg[u].cr,m+1,r,tl,tr,w,wtf);
		calc(u,l,r);
		return u;
	}
	pair<int,int> pors(int i,int l,int r,int tl,int tr){
		return make_pair(seg[i].maxa+seg[i].lazy,seg[i].ted);
	}
}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,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,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,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,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();
}
# Verdict Execution time Memory Grader output
1 Correct 117 ms 352592 KB Output is correct
2 Correct 114 ms 352596 KB Output is correct
3 Correct 111 ms 352492 KB Output is correct
4 Correct 160 ms 352724 KB Output is correct
5 Correct 109 ms 352696 KB Output is correct
6 Correct 111 ms 352596 KB Output is correct
7 Correct 143 ms 352596 KB Output is correct
8 Correct 120 ms 352592 KB Output is correct
9 Correct 110 ms 352692 KB Output is correct
10 Correct 110 ms 352596 KB Output is correct
11 Correct 120 ms 352636 KB Output is correct
12 Correct 123 ms 352596 KB Output is correct
13 Correct 117 ms 352596 KB Output is correct
14 Correct 115 ms 352596 KB Output is correct
15 Correct 151 ms 352504 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 117 ms 352592 KB Output is correct
2 Correct 114 ms 352596 KB Output is correct
3 Correct 111 ms 352492 KB Output is correct
4 Correct 160 ms 352724 KB Output is correct
5 Correct 109 ms 352696 KB Output is correct
6 Correct 111 ms 352596 KB Output is correct
7 Correct 143 ms 352596 KB Output is correct
8 Correct 120 ms 352592 KB Output is correct
9 Correct 110 ms 352692 KB Output is correct
10 Correct 110 ms 352596 KB Output is correct
11 Correct 120 ms 352636 KB Output is correct
12 Correct 123 ms 352596 KB Output is correct
13 Correct 117 ms 352596 KB Output is correct
14 Correct 115 ms 352596 KB Output is correct
15 Correct 151 ms 352504 KB Output is correct
16 Correct 133 ms 352852 KB Output is correct
17 Correct 129 ms 352848 KB Output is correct
18 Correct 131 ms 352848 KB Output is correct
19 Correct 150 ms 352820 KB Output is correct
20 Correct 152 ms 352992 KB Output is correct
21 Correct 166 ms 352872 KB Output is correct
22 Correct 136 ms 352724 KB Output is correct
23 Correct 148 ms 352964 KB Output is correct
24 Correct 139 ms 353080 KB Output is correct
25 Correct 143 ms 352760 KB Output is correct
26 Correct 146 ms 352780 KB Output is correct
27 Correct 148 ms 353072 KB Output is correct
28 Correct 133 ms 352880 KB Output is correct
29 Correct 129 ms 352852 KB Output is correct
30 Correct 134 ms 352848 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 117 ms 352592 KB Output is correct
2 Correct 114 ms 352596 KB Output is correct
3 Correct 111 ms 352492 KB Output is correct
4 Correct 160 ms 352724 KB Output is correct
5 Correct 109 ms 352696 KB Output is correct
6 Correct 111 ms 352596 KB Output is correct
7 Correct 143 ms 352596 KB Output is correct
8 Correct 120 ms 352592 KB Output is correct
9 Correct 110 ms 352692 KB Output is correct
10 Correct 110 ms 352596 KB Output is correct
11 Correct 120 ms 352636 KB Output is correct
12 Correct 123 ms 352596 KB Output is correct
13 Correct 117 ms 352596 KB Output is correct
14 Correct 115 ms 352596 KB Output is correct
15 Correct 151 ms 352504 KB Output is correct
16 Correct 133 ms 352852 KB Output is correct
17 Correct 129 ms 352848 KB Output is correct
18 Correct 131 ms 352848 KB Output is correct
19 Correct 150 ms 352820 KB Output is correct
20 Correct 152 ms 352992 KB Output is correct
21 Correct 166 ms 352872 KB Output is correct
22 Correct 136 ms 352724 KB Output is correct
23 Correct 148 ms 352964 KB Output is correct
24 Correct 139 ms 353080 KB Output is correct
25 Correct 143 ms 352760 KB Output is correct
26 Correct 146 ms 352780 KB Output is correct
27 Correct 148 ms 353072 KB Output is correct
28 Correct 133 ms 352880 KB Output is correct
29 Correct 129 ms 352852 KB Output is correct
30 Correct 134 ms 352848 KB Output is correct
31 Correct 231 ms 359896 KB Output is correct
32 Correct 229 ms 359756 KB Output is correct
33 Correct 161 ms 355316 KB Output is correct
34 Correct 272 ms 357640 KB Output is correct
35 Correct 278 ms 360084 KB Output is correct
36 Correct 227 ms 359504 KB Output is correct
37 Correct 175 ms 355512 KB Output is correct
38 Correct 277 ms 359616 KB Output is correct
39 Correct 233 ms 360020 KB Output is correct
40 Correct 256 ms 357972 KB Output is correct
41 Correct 280 ms 358480 KB Output is correct
42 Correct 290 ms 359444 KB Output is correct
43 Correct 230 ms 357712 KB Output is correct
44 Correct 234 ms 357216 KB Output is correct
45 Correct 209 ms 355672 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 117 ms 352592 KB Output is correct
2 Correct 114 ms 352596 KB Output is correct
3 Correct 111 ms 352492 KB Output is correct
4 Correct 160 ms 352724 KB Output is correct
5 Correct 109 ms 352696 KB Output is correct
6 Correct 111 ms 352596 KB Output is correct
7 Correct 143 ms 352596 KB Output is correct
8 Correct 120 ms 352592 KB Output is correct
9 Correct 110 ms 352692 KB Output is correct
10 Correct 110 ms 352596 KB Output is correct
11 Correct 120 ms 352636 KB Output is correct
12 Correct 123 ms 352596 KB Output is correct
13 Correct 117 ms 352596 KB Output is correct
14 Correct 115 ms 352596 KB Output is correct
15 Correct 151 ms 352504 KB Output is correct
16 Correct 124 ms 352740 KB Output is correct
17 Correct 130 ms 352636 KB Output is correct
18 Correct 126 ms 352596 KB Output is correct
19 Correct 133 ms 352544 KB Output is correct
20 Correct 126 ms 352592 KB Output is correct
21 Correct 155 ms 352804 KB Output is correct
22 Correct 127 ms 352592 KB Output is correct
23 Correct 123 ms 352664 KB Output is correct
24 Correct 122 ms 352596 KB Output is correct
25 Correct 133 ms 352740 KB Output is correct
26 Correct 129 ms 352592 KB Output is correct
27 Correct 121 ms 352600 KB Output is correct
28 Correct 129 ms 352848 KB Output is correct
29 Correct 131 ms 352592 KB Output is correct
30 Correct 122 ms 352592 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 117 ms 352592 KB Output is correct
2 Correct 114 ms 352596 KB Output is correct
3 Correct 111 ms 352492 KB Output is correct
4 Correct 160 ms 352724 KB Output is correct
5 Correct 109 ms 352696 KB Output is correct
6 Correct 111 ms 352596 KB Output is correct
7 Correct 143 ms 352596 KB Output is correct
8 Correct 120 ms 352592 KB Output is correct
9 Correct 110 ms 352692 KB Output is correct
10 Correct 110 ms 352596 KB Output is correct
11 Correct 120 ms 352636 KB Output is correct
12 Correct 123 ms 352596 KB Output is correct
13 Correct 117 ms 352596 KB Output is correct
14 Correct 115 ms 352596 KB Output is correct
15 Correct 151 ms 352504 KB Output is correct
16 Correct 133 ms 352852 KB Output is correct
17 Correct 129 ms 352848 KB Output is correct
18 Correct 131 ms 352848 KB Output is correct
19 Correct 150 ms 352820 KB Output is correct
20 Correct 152 ms 352992 KB Output is correct
21 Correct 166 ms 352872 KB Output is correct
22 Correct 136 ms 352724 KB Output is correct
23 Correct 148 ms 352964 KB Output is correct
24 Correct 139 ms 353080 KB Output is correct
25 Correct 143 ms 352760 KB Output is correct
26 Correct 146 ms 352780 KB Output is correct
27 Correct 148 ms 353072 KB Output is correct
28 Correct 133 ms 352880 KB Output is correct
29 Correct 129 ms 352852 KB Output is correct
30 Correct 134 ms 352848 KB Output is correct
31 Correct 124 ms 352740 KB Output is correct
32 Correct 130 ms 352636 KB Output is correct
33 Correct 126 ms 352596 KB Output is correct
34 Correct 133 ms 352544 KB Output is correct
35 Correct 126 ms 352592 KB Output is correct
36 Correct 155 ms 352804 KB Output is correct
37 Correct 127 ms 352592 KB Output is correct
38 Correct 123 ms 352664 KB Output is correct
39 Correct 122 ms 352596 KB Output is correct
40 Correct 133 ms 352740 KB Output is correct
41 Correct 129 ms 352592 KB Output is correct
42 Correct 121 ms 352600 KB Output is correct
43 Correct 129 ms 352848 KB Output is correct
44 Correct 131 ms 352592 KB Output is correct
45 Correct 122 ms 352592 KB Output is correct
46 Correct 140 ms 353104 KB Output is correct
47 Correct 140 ms 353104 KB Output is correct
48 Correct 128 ms 352852 KB Output is correct
49 Correct 142 ms 352896 KB Output is correct
50 Correct 157 ms 353000 KB Output is correct
51 Correct 134 ms 352856 KB Output is correct
52 Correct 134 ms 353088 KB Output is correct
53 Correct 145 ms 353104 KB Output is correct
54 Correct 150 ms 352908 KB Output is correct
55 Correct 135 ms 352960 KB Output is correct
56 Correct 162 ms 353108 KB Output is correct
57 Correct 143 ms 353036 KB Output is correct
58 Correct 138 ms 352920 KB Output is correct
59 Correct 143 ms 352852 KB Output is correct
60 Correct 139 ms 352912 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 117 ms 352592 KB Output is correct
2 Correct 114 ms 352596 KB Output is correct
3 Correct 111 ms 352492 KB Output is correct
4 Correct 160 ms 352724 KB Output is correct
5 Correct 109 ms 352696 KB Output is correct
6 Correct 111 ms 352596 KB Output is correct
7 Correct 143 ms 352596 KB Output is correct
8 Correct 120 ms 352592 KB Output is correct
9 Correct 110 ms 352692 KB Output is correct
10 Correct 110 ms 352596 KB Output is correct
11 Correct 120 ms 352636 KB Output is correct
12 Correct 123 ms 352596 KB Output is correct
13 Correct 117 ms 352596 KB Output is correct
14 Correct 115 ms 352596 KB Output is correct
15 Correct 151 ms 352504 KB Output is correct
16 Correct 133 ms 352852 KB Output is correct
17 Correct 129 ms 352848 KB Output is correct
18 Correct 131 ms 352848 KB Output is correct
19 Correct 150 ms 352820 KB Output is correct
20 Correct 152 ms 352992 KB Output is correct
21 Correct 166 ms 352872 KB Output is correct
22 Correct 136 ms 352724 KB Output is correct
23 Correct 148 ms 352964 KB Output is correct
24 Correct 139 ms 353080 KB Output is correct
25 Correct 143 ms 352760 KB Output is correct
26 Correct 146 ms 352780 KB Output is correct
27 Correct 148 ms 353072 KB Output is correct
28 Correct 133 ms 352880 KB Output is correct
29 Correct 129 ms 352852 KB Output is correct
30 Correct 134 ms 352848 KB Output is correct
31 Correct 231 ms 359896 KB Output is correct
32 Correct 229 ms 359756 KB Output is correct
33 Correct 161 ms 355316 KB Output is correct
34 Correct 272 ms 357640 KB Output is correct
35 Correct 278 ms 360084 KB Output is correct
36 Correct 227 ms 359504 KB Output is correct
37 Correct 175 ms 355512 KB Output is correct
38 Correct 277 ms 359616 KB Output is correct
39 Correct 233 ms 360020 KB Output is correct
40 Correct 256 ms 357972 KB Output is correct
41 Correct 280 ms 358480 KB Output is correct
42 Correct 290 ms 359444 KB Output is correct
43 Correct 230 ms 357712 KB Output is correct
44 Correct 234 ms 357216 KB Output is correct
45 Correct 209 ms 355672 KB Output is correct
46 Correct 124 ms 352740 KB Output is correct
47 Correct 130 ms 352636 KB Output is correct
48 Correct 126 ms 352596 KB Output is correct
49 Correct 133 ms 352544 KB Output is correct
50 Correct 126 ms 352592 KB Output is correct
51 Correct 155 ms 352804 KB Output is correct
52 Correct 127 ms 352592 KB Output is correct
53 Correct 123 ms 352664 KB Output is correct
54 Correct 122 ms 352596 KB Output is correct
55 Correct 133 ms 352740 KB Output is correct
56 Correct 129 ms 352592 KB Output is correct
57 Correct 121 ms 352600 KB Output is correct
58 Correct 129 ms 352848 KB Output is correct
59 Correct 131 ms 352592 KB Output is correct
60 Correct 122 ms 352592 KB Output is correct
61 Correct 140 ms 353104 KB Output is correct
62 Correct 140 ms 353104 KB Output is correct
63 Correct 128 ms 352852 KB Output is correct
64 Correct 142 ms 352896 KB Output is correct
65 Correct 157 ms 353000 KB Output is correct
66 Correct 134 ms 352856 KB Output is correct
67 Correct 134 ms 353088 KB Output is correct
68 Correct 145 ms 353104 KB Output is correct
69 Correct 150 ms 352908 KB Output is correct
70 Correct 135 ms 352960 KB Output is correct
71 Correct 162 ms 353108 KB Output is correct
72 Correct 143 ms 353036 KB Output is correct
73 Correct 138 ms 352920 KB Output is correct
74 Correct 143 ms 352852 KB Output is correct
75 Correct 139 ms 352912 KB Output is correct
76 Correct 602 ms 361164 KB Output is correct
77 Correct 635 ms 360836 KB Output is correct
78 Correct 230 ms 356692 KB Output is correct
79 Execution timed out 3015 ms 524288 KB Time limit exceeded
80 Halted 0 ms 0 KB -