fork download
  1. #include <bits/stdc++.h>
  2. #include <ext/pb_ds/assoc_container.hpp>
  3. #include <ext/pb_ds/tree_policy.hpp>
  4.  
  5. using namespace std;
  6. using namespace __gnu_pbds;
  7.  
  8. #define fi first
  9. #define se second
  10. #define mp make_pair
  11. #define pb push_back
  12. #define fbo find_by_order
  13. #define ook order_of_key
  14.  
  15. typedef long long ll;
  16. typedef pair<int,int> ii;
  17. typedef vector<int> vi;
  18. typedef long double ld;
  19. typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
  20. typedef set<int>::iterator sit;
  21. typedef map<int,int>::iterator mit;
  22. typedef vector<int>::iterator vit;
  23.  
  24. int p[300001];
  25. int q[300001];
  26. int q2[300001];
  27. int r[300001];
  28.  
  29. int main()
  30. {
  31. ios_base::sync_with_stdio(0); cin.tie(0);
  32. int n; cin >> n;
  33. for(int i = 0; i < n; i++)
  34. {
  35. cin>>p[i];
  36. p[i]--;
  37. }
  38. for(int i = 0; i < n; i++)
  39. {
  40. cin>>q[i];
  41. q[i]--;
  42. }
  43.  
  44. for(int i = 0; i < n; i++)
  45. {
  46. q2[q[i]] = i;
  47. }
  48. for(int i = 0; i < n; i++)
  49. {
  50. r[i] = q2[p[i]];
  51. }
  52. int ans = 0;
  53. for(int i = 0; i < n; i++)
  54. {
  55. //cerr<<r[i]<<' ';
  56. if(i == 0)
  57. {
  58. ans++;
  59. continue;
  60. }
  61. else if(r[i]-r[i-1]==1)
  62. {
  63.  
  64. }
  65. else
  66. {
  67. ans++;
  68. }
  69. }
  70. cout<<ans;
  71. }
  72.  
Success #stdin #stdout 0s 20752KB
stdin
Standard input is empty
stdout
Standard output is empty