This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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<pll,ll> 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;
}
pll merge(pll p1,pll p2){
ll x=max(p1.fs,p2.fs);
ll 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);
pll 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();
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |