#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pll pair<ll, ll>
#define pii pair<int, int>
#define fs first
#define sc second
#define pb push_back
const int maxn=1e5;
int n,k,q,a[maxn],b[maxn],idx[maxn];
pair<pii,int> seg[4*maxn+31];
void build(int v,int l,int r){
seg[v]={{0,1},0};
if(l==r)return;
int m=(l+r)/2;
build(2*v+1,l,m);
build(2*v+2,m+1,r);
}
void prop(int v){
seg[2*v+1].fs.fs+=seg[v].sc;
seg[2*v+1].sc+=seg[v].sc;
seg[2*v+2].fs.fs+=seg[v].sc;
seg[2*v+2].sc+=seg[v].sc;
seg[v].sc=0;
}
pii merge(pii p1,pii p2){
int x=max(p1.fs,p2.fs);
int y=0;
if(p1.fs==x)y+=p1.sc;
if(p2.fs==x)y+=p2.sc;
return {x,y};
}
void upd(int v,int l,int r,int l2,int r2,int x){
if(l>r2||r<l2)return;
if(l2<=l&&r<=r2){
seg[v].fs.fs+=x;
seg[v].sc+=x;
return;
}
prop(v);
int m=(l+r)/2;
upd(2*v+1,l,m,l2,r2,x);
upd(2*v+2,m+1,r,l2,r2,x);
seg[v].fs=merge(seg[2*v+1].fs,seg[2*v+2].fs);
}
void upd(int i,int x){
i=idx[a[i]];
upd(0,0,n-k,max(0,i-(k-1)),min(i,n-k),x);
}
void calc(){
build(0,0,n-k);
pii ans={0,0};
for(int i=0;i<k-1;i++){
upd(i,1);
}
for(int i=0;i<=n-k;i++){
upd(i+k-1,1);
ans=merge(ans,seg[0].fs);
upd(i,-1);
}
cout<<ans.fs<<' '<<ans.sc<<'\n';
}
void solve(){
cin>>n>>k>>q;
for(int i=0;i<n;i++){
cin>>a[i];
a[i]--;
}
for(int i=0;i<n;i++){
cin>>b[i];;
idx[--b[i]]=i;
}
calc();
while(q--){
int idx;
cin>>idx;
swap(a[idx],a[idx-1]);
calc();
}
}
int main(){
ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
solve();
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
344 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
10 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
344 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
10 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
344 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
10 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
344 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
10 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
344 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
10 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
344 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
10 |
Halted |
0 ms |
0 KB |
- |