답안 #791738

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
791738 2023-07-24T09:25:10 Z 이종영(#10079) Sličnost (COI23_slicnost) C++17
57 / 100
3000 ms 5780 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 x=1;x<=n-k+1;x++){
		if(x==1){
			for(int i=1;i<=k;i++){
				int j=invb[a[i]];
				T.upd(1,1,n-k+1,max(1,j-k+1),min(j,n-k+1),1);
			}
		} else{
			int j=invb[a[x+k-1]];
			T.upd(1,1,n-k+1,max(1,j-k+1),min(j,n-k+1),1);
			{
				int j=invb[a[x-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;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 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 0 ms 340 KB Output is correct
8 Correct 0 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 0 ms 340 KB Output is correct
12 Correct 0 ms 340 KB Output is correct
13 Correct 0 ms 340 KB Output is correct
14 Correct 0 ms 340 KB Output is correct
15 Correct 0 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 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 0 ms 340 KB Output is correct
8 Correct 0 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 0 ms 340 KB Output is correct
12 Correct 0 ms 340 KB Output is correct
13 Correct 0 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 2 ms 468 KB Output is correct
20 Correct 4 ms 596 KB Output is correct
21 Correct 4 ms 596 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 4 ms 496 KB Output is correct
24 Correct 6 ms 632 KB Output is correct
25 Correct 3 ms 468 KB Output is correct
26 Correct 3 ms 576 KB Output is correct
27 Correct 4 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
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 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 0 ms 340 KB Output is correct
8 Correct 0 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 0 ms 340 KB Output is correct
12 Correct 0 ms 340 KB Output is correct
13 Correct 0 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 2 ms 468 KB Output is correct
20 Correct 4 ms 596 KB Output is correct
21 Correct 4 ms 596 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 4 ms 496 KB Output is correct
24 Correct 6 ms 632 KB Output is correct
25 Correct 3 ms 468 KB Output is correct
26 Correct 3 ms 576 KB Output is correct
27 Correct 4 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 60 ms 5688 KB Output is correct
32 Correct 55 ms 5652 KB Output is correct
33 Correct 17 ms 1876 KB Output is correct
34 Correct 49 ms 3784 KB Output is correct
35 Correct 103 ms 5780 KB Output is correct
36 Correct 55 ms 5388 KB Output is correct
37 Correct 17 ms 2004 KB Output is correct
38 Correct 95 ms 5548 KB Output is correct
39 Correct 61 ms 5744 KB Output is correct
40 Correct 62 ms 4120 KB Output is correct
41 Correct 75 ms 4592 KB Output is correct
42 Correct 96 ms 5336 KB Output is correct
43 Correct 57 ms 3932 KB Output is correct
44 Correct 40 ms 3412 KB Output is correct
45 Correct 16 ms 2060 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 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 0 ms 340 KB Output is correct
8 Correct 0 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 0 ms 340 KB Output is correct
12 Correct 0 ms 340 KB Output is correct
13 Correct 0 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 348 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 2 ms 340 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 1 ms 364 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 1 ms 344 KB Output is correct
29 Correct 1 ms 340 KB Output is correct
30 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 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 0 ms 340 KB Output is correct
8 Correct 0 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 0 ms 340 KB Output is correct
12 Correct 0 ms 340 KB Output is correct
13 Correct 0 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 2 ms 468 KB Output is correct
20 Correct 4 ms 596 KB Output is correct
21 Correct 4 ms 596 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 4 ms 496 KB Output is correct
24 Correct 6 ms 632 KB Output is correct
25 Correct 3 ms 468 KB Output is correct
26 Correct 3 ms 576 KB Output is correct
27 Correct 4 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 348 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 2 ms 340 KB Output is correct
39 Correct 1 ms 340 KB Output is correct
40 Correct 1 ms 364 KB Output is correct
41 Correct 1 ms 340 KB Output is correct
42 Correct 1 ms 340 KB Output is correct
43 Correct 1 ms 344 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 3048 ms 656 KB Time limit exceeded
47 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 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 0 ms 340 KB Output is correct
8 Correct 0 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 0 ms 340 KB Output is correct
12 Correct 0 ms 340 KB Output is correct
13 Correct 0 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 2 ms 468 KB Output is correct
20 Correct 4 ms 596 KB Output is correct
21 Correct 4 ms 596 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 4 ms 496 KB Output is correct
24 Correct 6 ms 632 KB Output is correct
25 Correct 3 ms 468 KB Output is correct
26 Correct 3 ms 576 KB Output is correct
27 Correct 4 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 60 ms 5688 KB Output is correct
32 Correct 55 ms 5652 KB Output is correct
33 Correct 17 ms 1876 KB Output is correct
34 Correct 49 ms 3784 KB Output is correct
35 Correct 103 ms 5780 KB Output is correct
36 Correct 55 ms 5388 KB Output is correct
37 Correct 17 ms 2004 KB Output is correct
38 Correct 95 ms 5548 KB Output is correct
39 Correct 61 ms 5744 KB Output is correct
40 Correct 62 ms 4120 KB Output is correct
41 Correct 75 ms 4592 KB Output is correct
42 Correct 96 ms 5336 KB Output is correct
43 Correct 57 ms 3932 KB Output is correct
44 Correct 40 ms 3412 KB Output is correct
45 Correct 16 ms 2060 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 348 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 2 ms 340 KB Output is correct
54 Correct 1 ms 340 KB Output is correct
55 Correct 1 ms 364 KB Output is correct
56 Correct 1 ms 340 KB Output is correct
57 Correct 1 ms 340 KB Output is correct
58 Correct 1 ms 344 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 3048 ms 656 KB Time limit exceeded
62 Halted 0 ms 0 KB -