//Subtask 2
#include<bits/stdc++.h>
using namespace std;
int a[100005], b[100005], sparse[100005][20];
int query(int l, int r)
{
if(l > r) swap(l, r);
int x = __lg(r-l+1);
return max(sparse[l][x], sparse[r-(1<<x)+1][x]);
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
int n; 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++) sparse[i][0] = a[i];
for(int j = 0; j < 19; j++){
for(int i = 1; i <= n; i++){
sparse[i][j+1] = sparse[i][j];
if(i+(1 << j) <= n) sparse[i][j+1] = max(sparse[i][j+1], sparse[i+(1 << j)][j]);
}
}
int ans = 0;
map<int, int> f;
for(int i = 1; i <= n; i++) f[b[i]] = i;
for(int i = 1; i <= n; i++) if(query(i, f[a[i]]) == a[i]) ans++;
cout<<ans;
}
# | 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... |