Submission #791727

# Submission time Handle Problem Language Result Execution time Memory
791727 2023-07-24T09:08:42 Z 이종영(#10079) Sličnost (COI23_slicnost) C++17
57 / 100
3000 ms 5716 KB
#pragma GCC optimize("O3")
//#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,sse4.1,sse4.2,popcnt,abm,mmx,avx,avx2,fma")
#include <bits/stdc++.h>
using namespace std;
//#include <atcoder/all>
//using namespace atcoder;
//#include <bits/extc++.h>
//using namespace __gnu_pbds;
#ifdef LOCAL
#include "debug.h"
#else
#define debug(...) 42
#endif
using ll=long long;
using pll=array<ll,2>;
const ll inf=1e18;
const int N=1e5+5,B=333;
pll mrg(pll L,pll R){
	if(L[0]<R[0]) swap(L,R);
	if(L[0]==R[0]) return {L[0],L[1]+R[1]};
	return L;
}
struct SEG{
	pll T[2*N]; int D[2*N];
	void init(int nd,int l,int r){
		T[nd]={0,r-l+1};
		D[nd]=0;
		if(l==r) return;
		int m=(l+r)>>1,ln=nd+1,rn=nd+2*(m-l+1);
		init(ln,l,m); init(rn,m+1,r);
	}
	void upd(int nd,int l,int r,int s,int e,int v){
		if(r<s||e<l) return;
		if(s<=l&&r<=e){
			T[nd][0]+=v;
			D[nd]+=v;
			return;
		}
		int m=(l+r)>>1,ln=nd+1,rn=nd+2*(m-l+1);
		upd(ln,l,m,s,e,v); upd(rn,m+1,r,s,e,v);
		T[nd]=mrg(T[ln],T[rn]);
		T[nd][0]+=D[nd];
	}
	pll qry(int nd,int l,int r,int s,int e){
		if(r<s||e<l) return {(ll)-1e9,0};
		if(s<=l&&r<=e) return T[nd];
		int m=(l+r)>>1,ln=nd+1,rn=nd+2*(m-l+1);
		pll ret=mrg(qry(ln,l,m,s,e),qry(rn,m+1,r,s,e));
		ret[0]+=D[nd];
		return ret;
	}
}T;
int n,k,q,a[N],b[N],inva[N],invb[N],t[N];
pll ans[N];
pll solve(){
	pll ret={0,0};
	T.init(1,1,n-k+1);
	for(int y=1;y<=n-k+1;y++){
		if(y==1){
			for(int i=1;i<=k;i++){
				int j=inva[b[i]];
				T.upd(1,1,n-k+1,max(1,j-k+1),min(j,n-k+1),1);
			}
		} else{
			int j=inva[b[y+k-1]];
			T.upd(1,1,n-k+1,max(1,j-k+1),min(j,n-k+1),1);
			{
				int j=inva[b[y-1]];
				T.upd(1,1,n-k+1,max(1,j-k+1),min(j,n-k+1),-1);
			}
		}
		pll val=T.qry(1,1,n-k+1,1,n-k+1);
		ret=mrg(ret,val);
	}
	return ret;
}
int main(){
	ios::sync_with_stdio(false); cin.tie(0);
	cin>>n>>k>>q;
	for(int i=1;i<=n;i++){
		cin>>a[i];
		inva[a[i]]=i;
	}
	for(int i=1;i<=n;i++){
		cin>>b[i];
		invb[b[i]]=i;
	}
	ans[0]=solve();
	for(int i=1;i<=q;i++){
		cin>>t[i];
		swap(a[t[i]],a[t[i]+1]);
		swap(inva[a[t[i]]],inva[a[t[i]+1]]);
		ans[i]=solve();
	}
	for(int i=0;i<=q;i++) cout<<ans[i][0]<<" "<<ans[i][1]<<"\n";
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 0 ms 340 KB Output is correct
15 Correct 0 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 0 ms 340 KB Output is correct
15 Correct 0 ms 340 KB Output is correct
16 Correct 2 ms 596 KB Output is correct
17 Correct 2 ms 596 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 3 ms 468 KB Output is correct
20 Correct 5 ms 596 KB Output is correct
21 Correct 2 ms 596 KB Output is correct
22 Correct 2 ms 340 KB Output is correct
23 Correct 5 ms 596 KB Output is correct
24 Correct 4 ms 596 KB Output is correct
25 Correct 3 ms 468 KB Output is correct
26 Correct 4 ms 468 KB Output is correct
27 Correct 3 ms 596 KB Output is correct
28 Correct 2 ms 468 KB Output is correct
29 Correct 2 ms 468 KB Output is correct
30 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 0 ms 340 KB Output is correct
15 Correct 0 ms 340 KB Output is correct
16 Correct 2 ms 596 KB Output is correct
17 Correct 2 ms 596 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 3 ms 468 KB Output is correct
20 Correct 5 ms 596 KB Output is correct
21 Correct 2 ms 596 KB Output is correct
22 Correct 2 ms 340 KB Output is correct
23 Correct 5 ms 596 KB Output is correct
24 Correct 4 ms 596 KB Output is correct
25 Correct 3 ms 468 KB Output is correct
26 Correct 4 ms 468 KB Output is correct
27 Correct 3 ms 596 KB Output is correct
28 Correct 2 ms 468 KB Output is correct
29 Correct 2 ms 468 KB Output is correct
30 Correct 1 ms 340 KB Output is correct
31 Correct 68 ms 5708 KB Output is correct
32 Correct 53 ms 5656 KB Output is correct
33 Correct 20 ms 1812 KB Output is correct
34 Correct 57 ms 3804 KB Output is correct
35 Correct 82 ms 5716 KB Output is correct
36 Correct 65 ms 5392 KB Output is correct
37 Correct 19 ms 2016 KB Output is correct
38 Correct 84 ms 5548 KB Output is correct
39 Correct 58 ms 5716 KB Output is correct
40 Correct 61 ms 4192 KB Output is correct
41 Correct 69 ms 4564 KB Output is correct
42 Correct 88 ms 5340 KB Output is correct
43 Correct 51 ms 3924 KB Output is correct
44 Correct 39 ms 3412 KB Output is correct
45 Correct 16 ms 2108 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 0 ms 340 KB Output is correct
15 Correct 0 ms 340 KB Output is correct
16 Correct 1 ms 368 KB Output is correct
17 Correct 2 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 2 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 2 ms 340 KB Output is correct
26 Correct 2 ms 344 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 1 ms 340 KB Output is correct
29 Correct 1 ms 340 KB Output is correct
30 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 0 ms 340 KB Output is correct
15 Correct 0 ms 340 KB Output is correct
16 Correct 2 ms 596 KB Output is correct
17 Correct 2 ms 596 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 3 ms 468 KB Output is correct
20 Correct 5 ms 596 KB Output is correct
21 Correct 2 ms 596 KB Output is correct
22 Correct 2 ms 340 KB Output is correct
23 Correct 5 ms 596 KB Output is correct
24 Correct 4 ms 596 KB Output is correct
25 Correct 3 ms 468 KB Output is correct
26 Correct 4 ms 468 KB Output is correct
27 Correct 3 ms 596 KB Output is correct
28 Correct 2 ms 468 KB Output is correct
29 Correct 2 ms 468 KB Output is correct
30 Correct 1 ms 340 KB Output is correct
31 Correct 1 ms 368 KB Output is correct
32 Correct 2 ms 340 KB Output is correct
33 Correct 1 ms 340 KB Output is correct
34 Correct 1 ms 340 KB Output is correct
35 Correct 2 ms 340 KB Output is correct
36 Correct 1 ms 340 KB Output is correct
37 Correct 1 ms 340 KB Output is correct
38 Correct 1 ms 340 KB Output is correct
39 Correct 1 ms 340 KB Output is correct
40 Correct 2 ms 340 KB Output is correct
41 Correct 2 ms 344 KB Output is correct
42 Correct 1 ms 340 KB Output is correct
43 Correct 1 ms 340 KB Output is correct
44 Correct 1 ms 340 KB Output is correct
45 Correct 1 ms 340 KB Output is correct
46 Execution timed out 3060 ms 636 KB Time limit exceeded
47 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 0 ms 340 KB Output is correct
15 Correct 0 ms 340 KB Output is correct
16 Correct 2 ms 596 KB Output is correct
17 Correct 2 ms 596 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 3 ms 468 KB Output is correct
20 Correct 5 ms 596 KB Output is correct
21 Correct 2 ms 596 KB Output is correct
22 Correct 2 ms 340 KB Output is correct
23 Correct 5 ms 596 KB Output is correct
24 Correct 4 ms 596 KB Output is correct
25 Correct 3 ms 468 KB Output is correct
26 Correct 4 ms 468 KB Output is correct
27 Correct 3 ms 596 KB Output is correct
28 Correct 2 ms 468 KB Output is correct
29 Correct 2 ms 468 KB Output is correct
30 Correct 1 ms 340 KB Output is correct
31 Correct 68 ms 5708 KB Output is correct
32 Correct 53 ms 5656 KB Output is correct
33 Correct 20 ms 1812 KB Output is correct
34 Correct 57 ms 3804 KB Output is correct
35 Correct 82 ms 5716 KB Output is correct
36 Correct 65 ms 5392 KB Output is correct
37 Correct 19 ms 2016 KB Output is correct
38 Correct 84 ms 5548 KB Output is correct
39 Correct 58 ms 5716 KB Output is correct
40 Correct 61 ms 4192 KB Output is correct
41 Correct 69 ms 4564 KB Output is correct
42 Correct 88 ms 5340 KB Output is correct
43 Correct 51 ms 3924 KB Output is correct
44 Correct 39 ms 3412 KB Output is correct
45 Correct 16 ms 2108 KB Output is correct
46 Correct 1 ms 368 KB Output is correct
47 Correct 2 ms 340 KB Output is correct
48 Correct 1 ms 340 KB Output is correct
49 Correct 1 ms 340 KB Output is correct
50 Correct 2 ms 340 KB Output is correct
51 Correct 1 ms 340 KB Output is correct
52 Correct 1 ms 340 KB Output is correct
53 Correct 1 ms 340 KB Output is correct
54 Correct 1 ms 340 KB Output is correct
55 Correct 2 ms 340 KB Output is correct
56 Correct 2 ms 344 KB Output is correct
57 Correct 1 ms 340 KB Output is correct
58 Correct 1 ms 340 KB Output is correct
59 Correct 1 ms 340 KB Output is correct
60 Correct 1 ms 340 KB Output is correct
61 Execution timed out 3060 ms 636 KB Time limit exceeded
62 Halted 0 ms 0 KB -