lucasincyber不会做他自己的题/cf
设
那么很显然对于
所以只用双指针维护一下
::::info[code]
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int N=1e6+5;
int n,a[N],b[N];
int pos[N],ans;
signed main(){
ios::sync_with_stdio(0),cin.tie(0);
cin>>n;for(int i=1;i<=n;i++) cin>>a[i];
for(int i=1;i<=n;i++) cin>>b[i];
for(int i=1;i<=n;i++) pos[b[i]]=i;
int l=1,lst=pos[a[1]];
for(int i=1;i<=n;i++){
if(pos[a[i]]<lst) l=i;
lst=pos[a[i]];ans+=i-l+1;
}
cout<<ans;
return 0;
}
::::