# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
791794 |
2023-07-24T10:07:41 Z |
이종영(#10079) |
Sličnost (COI23_slicnost) |
C++17 |
|
1036 ms |
524288 KB |
#pragma GCC optimize("O3")
#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;
#ifdef LOCAL
#include "debug.h"
#else
#define debug(...) 42
#endif
using ll=long long;
using pii=array<int,2>;
using pll=array<ll,2>;
const ll inf=1e18;
const int N=1e5+5;
pii mrg(pii L,pii R){
if(L[0]<R[0]) swap(L,R);
if(L[0]==R[0]) return {L[0],L[1]+R[1]};
return L;
}
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 node{
pii v={0,0}; int d=0;
int l=0,r=0;
node(){}
}; int C=1;
vector<node> T;
int D[N];
void init(int nd,int l,int r){
T[nd].d=0;
if(l==r){
T[nd].v={D[l],1};
return;
}
int m=(l+r)>>1;
T[nd].l=++C;
T[nd].r=++C;
T.emplace_back();
T.emplace_back();
init(T[nd].l,l,m); init(T[nd].r,m+1,r);
T[nd].v=mrg(T[T[nd].l].v,T[T[nd].r].v);
}
int upd(int n1,int l,int r,int s,int e,int v){
if(r<s||e<l) return n1;
int n2=++C;
T.emplace_back();
T[n2]=T[n1];
if(s<=l&&r<=e){
T[n2].v[0]+=v;
T[n2].d+=v;
return n2;
}
int m=(l+r)>>1;
T[n2].l=upd(T[n1].l,l,m,s,e,v);
T[n2].r=upd(T[n1].r,m+1,r,s,e,v);
T[n2].v=mrg(T[T[n2].l].v,T[T[n2].r].v);
T[n2].v[0]+=T[n2].d;
return n2;
}
int n,k,q,a[N],b[N],invb[N],t[N];
int root[N];
struct ST{
pll S[2*N];
void init(int nd,int l,int r){
if(l==r){
S[nd]={T[root[l]].v[0],T[root[l]].v[1]};
return;
}
int m=(l+r)>>1,ln=nd+1,rn=nd+2*(m-l+1);
init(ln,l,m); init(rn,m+1,r);
S[nd]=mrg(S[ln],S[rn]);
}
void upd(int nd,int l,int r,int x){
if(l==r){
S[nd]={T[root[l]].v[0],T[root[l]].v[1]};
return;
}
int m=(l+r)>>1,ln=nd+1,rn=nd+2*(m-l+1);
if(x<=m) upd(ln,l,m,x);
else upd(rn,m+1,r,x);
S[nd]=mrg(S[ln],S[rn]);
}
}S;
int main(){
ios::sync_with_stdio(false); cin.tie(0);
cin>>n>>k>>q;
for(int i=1;i<=n;i++) cin>>a[i];
for(int i=1;i<=n;i++){
cin>>b[i];
invb[b[i]]=i;
}
for(int i=1;i<=k;i++){
int j=invb[a[i]];
D[max(1,j-k+1)]++;
D[min(j,n-k+1)+1]--;
}
for(int i=1;i<=n-k+1;i++) D[i]+=D[i-1];
T.emplace_back();
T.emplace_back();
root[1]=1;
init(1,1,n-k+1);
for(int x=2;x<=n-k+1;x++){
root[x]=root[x-1];
int j=invb[a[x+k-1]];
root[x]=upd(root[x],1,n-k+1,max(1,j-k+1),min(j,n-k+1),1);
{
int j=invb[a[x-1]];
root[x]=upd(root[x],1,n-k+1,max(1,j-k+1),min(j,n-k+1),-1);
}
}
S.init(1,1,n-k+1);
cout<<S.S[1][0]<<" "<<S.S[1][1]<<"\n";
for(int i=1;i<=q;i++){
cin>>t[i];
if(k<=t[i]){
int j=invb[a[t[i]]];
root[t[i]-k+1]=upd(root[t[i]-k+1],1,n-k+1,max(1,j-k+1),min(j,n-k+1),-1);
j=invb[a[t[i]+1]];
root[t[i]-k+1]=upd(root[t[i]-k+1],1,n-k+1,max(1,j-k+1),min(j,n-k+1),1);
S.upd(1,1,n-k+1,t[i]-k+1);
}
if(t[i]<=n-k){
int j=invb[a[t[i]]];
root[t[i]+1]=upd(root[t[i]+1],1,n-k+1,max(1,j-k+1),min(j,n-k+1),1);
j=invb[a[t[i]+1]];
root[t[i]+1]=upd(root[t[i]+1],1,n-k+1,max(1,j-k+1),min(j,n-k+1),-1);
S.upd(1,1,n-k+1,t[i]+1);
}
swap(a[t[i]],a[t[i]+1]);
cout<<S.S[1][0]<<" "<<S.S[1][1]<<"\n";
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 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 |
0 ms |
468 KB |
Output is correct |
6 |
Correct |
0 ms |
468 KB |
Output is correct |
7 |
Correct |
0 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
468 KB |
Output is correct |
9 |
Correct |
0 ms |
468 KB |
Output is correct |
10 |
Correct |
0 ms |
340 KB |
Output is correct |
11 |
Correct |
0 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
468 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 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 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 |
0 ms |
468 KB |
Output is correct |
6 |
Correct |
0 ms |
468 KB |
Output is correct |
7 |
Correct |
0 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
468 KB |
Output is correct |
9 |
Correct |
0 ms |
468 KB |
Output is correct |
10 |
Correct |
0 ms |
340 KB |
Output is correct |
11 |
Correct |
0 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
468 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 |
5 ms |
5636 KB |
Output is correct |
17 |
Correct |
5 ms |
5700 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
4 ms |
3016 KB |
Output is correct |
20 |
Correct |
7 ms |
5700 KB |
Output is correct |
21 |
Correct |
7 ms |
5700 KB |
Output is correct |
22 |
Correct |
1 ms |
596 KB |
Output is correct |
23 |
Correct |
7 ms |
5676 KB |
Output is correct |
24 |
Correct |
6 ms |
5700 KB |
Output is correct |
25 |
Correct |
4 ms |
3140 KB |
Output is correct |
26 |
Correct |
5 ms |
5700 KB |
Output is correct |
27 |
Correct |
7 ms |
5700 KB |
Output is correct |
28 |
Correct |
4 ms |
3144 KB |
Output is correct |
29 |
Correct |
3 ms |
1772 KB |
Output is correct |
30 |
Correct |
1 ms |
468 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 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 |
0 ms |
468 KB |
Output is correct |
6 |
Correct |
0 ms |
468 KB |
Output is correct |
7 |
Correct |
0 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
468 KB |
Output is correct |
9 |
Correct |
0 ms |
468 KB |
Output is correct |
10 |
Correct |
0 ms |
340 KB |
Output is correct |
11 |
Correct |
0 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
468 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 |
5 ms |
5636 KB |
Output is correct |
17 |
Correct |
5 ms |
5700 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
4 ms |
3016 KB |
Output is correct |
20 |
Correct |
7 ms |
5700 KB |
Output is correct |
21 |
Correct |
7 ms |
5700 KB |
Output is correct |
22 |
Correct |
1 ms |
596 KB |
Output is correct |
23 |
Correct |
7 ms |
5676 KB |
Output is correct |
24 |
Correct |
6 ms |
5700 KB |
Output is correct |
25 |
Correct |
4 ms |
3140 KB |
Output is correct |
26 |
Correct |
5 ms |
5700 KB |
Output is correct |
27 |
Correct |
7 ms |
5700 KB |
Output is correct |
28 |
Correct |
4 ms |
3144 KB |
Output is correct |
29 |
Correct |
3 ms |
1772 KB |
Output is correct |
30 |
Correct |
1 ms |
468 KB |
Output is correct |
31 |
Correct |
138 ms |
84224 KB |
Output is correct |
32 |
Correct |
151 ms |
84260 KB |
Output is correct |
33 |
Correct |
13 ms |
1496 KB |
Output is correct |
34 |
Correct |
132 ms |
83996 KB |
Output is correct |
35 |
Correct |
273 ms |
166432 KB |
Output is correct |
36 |
Correct |
199 ms |
166360 KB |
Output is correct |
37 |
Correct |
16 ms |
6796 KB |
Output is correct |
38 |
Correct |
284 ms |
166324 KB |
Output is correct |
39 |
Correct |
200 ms |
166408 KB |
Output is correct |
40 |
Correct |
136 ms |
83932 KB |
Output is correct |
41 |
Correct |
209 ms |
166244 KB |
Output is correct |
42 |
Correct |
284 ms |
166268 KB |
Output is correct |
43 |
Correct |
124 ms |
84020 KB |
Output is correct |
44 |
Correct |
62 ms |
42884 KB |
Output is correct |
45 |
Correct |
14 ms |
4168 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 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 |
0 ms |
468 KB |
Output is correct |
6 |
Correct |
0 ms |
468 KB |
Output is correct |
7 |
Correct |
0 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
468 KB |
Output is correct |
9 |
Correct |
0 ms |
468 KB |
Output is correct |
10 |
Correct |
0 ms |
340 KB |
Output is correct |
11 |
Correct |
0 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
468 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 |
596 KB |
Output is correct |
17 |
Correct |
1 ms |
596 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
0 ms |
468 KB |
Output is correct |
20 |
Correct |
1 ms |
596 KB |
Output is correct |
21 |
Correct |
1 ms |
340 KB |
Output is correct |
22 |
Correct |
1 ms |
596 KB |
Output is correct |
23 |
Correct |
1 ms |
596 KB |
Output is correct |
24 |
Correct |
1 ms |
596 KB |
Output is correct |
25 |
Correct |
0 ms |
468 KB |
Output is correct |
26 |
Correct |
1 ms |
596 KB |
Output is correct |
27 |
Correct |
1 ms |
596 KB |
Output is correct |
28 |
Correct |
0 ms |
340 KB |
Output is correct |
29 |
Correct |
0 ms |
596 KB |
Output is correct |
30 |
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 |
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 |
0 ms |
468 KB |
Output is correct |
6 |
Correct |
0 ms |
468 KB |
Output is correct |
7 |
Correct |
0 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
468 KB |
Output is correct |
9 |
Correct |
0 ms |
468 KB |
Output is correct |
10 |
Correct |
0 ms |
340 KB |
Output is correct |
11 |
Correct |
0 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
468 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 |
5 ms |
5636 KB |
Output is correct |
17 |
Correct |
5 ms |
5700 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
4 ms |
3016 KB |
Output is correct |
20 |
Correct |
7 ms |
5700 KB |
Output is correct |
21 |
Correct |
7 ms |
5700 KB |
Output is correct |
22 |
Correct |
1 ms |
596 KB |
Output is correct |
23 |
Correct |
7 ms |
5676 KB |
Output is correct |
24 |
Correct |
6 ms |
5700 KB |
Output is correct |
25 |
Correct |
4 ms |
3140 KB |
Output is correct |
26 |
Correct |
5 ms |
5700 KB |
Output is correct |
27 |
Correct |
7 ms |
5700 KB |
Output is correct |
28 |
Correct |
4 ms |
3144 KB |
Output is correct |
29 |
Correct |
3 ms |
1772 KB |
Output is correct |
30 |
Correct |
1 ms |
468 KB |
Output is correct |
31 |
Correct |
1 ms |
596 KB |
Output is correct |
32 |
Correct |
1 ms |
596 KB |
Output is correct |
33 |
Correct |
1 ms |
340 KB |
Output is correct |
34 |
Correct |
0 ms |
468 KB |
Output is correct |
35 |
Correct |
1 ms |
596 KB |
Output is correct |
36 |
Correct |
1 ms |
340 KB |
Output is correct |
37 |
Correct |
1 ms |
596 KB |
Output is correct |
38 |
Correct |
1 ms |
596 KB |
Output is correct |
39 |
Correct |
1 ms |
596 KB |
Output is correct |
40 |
Correct |
0 ms |
468 KB |
Output is correct |
41 |
Correct |
1 ms |
596 KB |
Output is correct |
42 |
Correct |
1 ms |
596 KB |
Output is correct |
43 |
Correct |
0 ms |
340 KB |
Output is correct |
44 |
Correct |
0 ms |
596 KB |
Output is correct |
45 |
Correct |
0 ms |
340 KB |
Output is correct |
46 |
Correct |
14 ms |
10992 KB |
Output is correct |
47 |
Correct |
15 ms |
10944 KB |
Output is correct |
48 |
Correct |
2 ms |
460 KB |
Output is correct |
49 |
Correct |
9 ms |
5700 KB |
Output is correct |
50 |
Correct |
27 ms |
21216 KB |
Output is correct |
51 |
Correct |
3 ms |
1868 KB |
Output is correct |
52 |
Correct |
14 ms |
10944 KB |
Output is correct |
53 |
Correct |
30 ms |
21176 KB |
Output is correct |
54 |
Correct |
24 ms |
21304 KB |
Output is correct |
55 |
Correct |
7 ms |
5700 KB |
Output is correct |
56 |
Correct |
29 ms |
21308 KB |
Output is correct |
57 |
Correct |
30 ms |
21256 KB |
Output is correct |
58 |
Correct |
4 ms |
1868 KB |
Output is correct |
59 |
Correct |
24 ms |
21284 KB |
Output is correct |
60 |
Correct |
5 ms |
1868 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 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 |
0 ms |
468 KB |
Output is correct |
6 |
Correct |
0 ms |
468 KB |
Output is correct |
7 |
Correct |
0 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
468 KB |
Output is correct |
9 |
Correct |
0 ms |
468 KB |
Output is correct |
10 |
Correct |
0 ms |
340 KB |
Output is correct |
11 |
Correct |
0 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
468 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 |
5 ms |
5636 KB |
Output is correct |
17 |
Correct |
5 ms |
5700 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
4 ms |
3016 KB |
Output is correct |
20 |
Correct |
7 ms |
5700 KB |
Output is correct |
21 |
Correct |
7 ms |
5700 KB |
Output is correct |
22 |
Correct |
1 ms |
596 KB |
Output is correct |
23 |
Correct |
7 ms |
5676 KB |
Output is correct |
24 |
Correct |
6 ms |
5700 KB |
Output is correct |
25 |
Correct |
4 ms |
3140 KB |
Output is correct |
26 |
Correct |
5 ms |
5700 KB |
Output is correct |
27 |
Correct |
7 ms |
5700 KB |
Output is correct |
28 |
Correct |
4 ms |
3144 KB |
Output is correct |
29 |
Correct |
3 ms |
1772 KB |
Output is correct |
30 |
Correct |
1 ms |
468 KB |
Output is correct |
31 |
Correct |
138 ms |
84224 KB |
Output is correct |
32 |
Correct |
151 ms |
84260 KB |
Output is correct |
33 |
Correct |
13 ms |
1496 KB |
Output is correct |
34 |
Correct |
132 ms |
83996 KB |
Output is correct |
35 |
Correct |
273 ms |
166432 KB |
Output is correct |
36 |
Correct |
199 ms |
166360 KB |
Output is correct |
37 |
Correct |
16 ms |
6796 KB |
Output is correct |
38 |
Correct |
284 ms |
166324 KB |
Output is correct |
39 |
Correct |
200 ms |
166408 KB |
Output is correct |
40 |
Correct |
136 ms |
83932 KB |
Output is correct |
41 |
Correct |
209 ms |
166244 KB |
Output is correct |
42 |
Correct |
284 ms |
166268 KB |
Output is correct |
43 |
Correct |
124 ms |
84020 KB |
Output is correct |
44 |
Correct |
62 ms |
42884 KB |
Output is correct |
45 |
Correct |
14 ms |
4168 KB |
Output is correct |
46 |
Correct |
1 ms |
596 KB |
Output is correct |
47 |
Correct |
1 ms |
596 KB |
Output is correct |
48 |
Correct |
1 ms |
340 KB |
Output is correct |
49 |
Correct |
0 ms |
468 KB |
Output is correct |
50 |
Correct |
1 ms |
596 KB |
Output is correct |
51 |
Correct |
1 ms |
340 KB |
Output is correct |
52 |
Correct |
1 ms |
596 KB |
Output is correct |
53 |
Correct |
1 ms |
596 KB |
Output is correct |
54 |
Correct |
1 ms |
596 KB |
Output is correct |
55 |
Correct |
0 ms |
468 KB |
Output is correct |
56 |
Correct |
1 ms |
596 KB |
Output is correct |
57 |
Correct |
1 ms |
596 KB |
Output is correct |
58 |
Correct |
0 ms |
340 KB |
Output is correct |
59 |
Correct |
0 ms |
596 KB |
Output is correct |
60 |
Correct |
0 ms |
340 KB |
Output is correct |
61 |
Correct |
14 ms |
10992 KB |
Output is correct |
62 |
Correct |
15 ms |
10944 KB |
Output is correct |
63 |
Correct |
2 ms |
460 KB |
Output is correct |
64 |
Correct |
9 ms |
5700 KB |
Output is correct |
65 |
Correct |
27 ms |
21216 KB |
Output is correct |
66 |
Correct |
3 ms |
1868 KB |
Output is correct |
67 |
Correct |
14 ms |
10944 KB |
Output is correct |
68 |
Correct |
30 ms |
21176 KB |
Output is correct |
69 |
Correct |
24 ms |
21304 KB |
Output is correct |
70 |
Correct |
7 ms |
5700 KB |
Output is correct |
71 |
Correct |
29 ms |
21308 KB |
Output is correct |
72 |
Correct |
30 ms |
21256 KB |
Output is correct |
73 |
Correct |
4 ms |
1868 KB |
Output is correct |
74 |
Correct |
24 ms |
21284 KB |
Output is correct |
75 |
Correct |
5 ms |
1868 KB |
Output is correct |
76 |
Correct |
644 ms |
334476 KB |
Output is correct |
77 |
Correct |
754 ms |
334204 KB |
Output is correct |
78 |
Correct |
28 ms |
2644 KB |
Output is correct |
79 |
Correct |
423 ms |
168116 KB |
Output is correct |
80 |
Runtime error |
1036 ms |
524288 KB |
Execution killed with signal 9 |
81 |
Halted |
0 ms |
0 KB |
- |