fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. #include <ext/pb_ds/tree_policy.hpp>
  5. #include <ext/pb_ds/assoc_container.hpp>
  6.  
  7. using namespace __gnu_pbds;
  8. template<typename T>
  9. using ordered_set = tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;
  10.  
  11. void OPEN(string s) {
  12. freopen((s + ".in").c_str(), "r", stdin);
  13. freopen((s + ".out").c_str(), "w", stdout);
  14. }
  15.  
  16. int main() {
  17. ios_base::sync_with_stdio(0);
  18. cin.tie(0);
  19. cout.tie(0);
  20. int n;
  21. cin >> n;
  22. vector<int> a(n), b(n);
  23. map<int, int> pos;
  24. for (int i = 0; i < n; ++i)
  25. cin >> a[i], pos[a[i]] = i;
  26. for (int i = 0; i < n; ++i)
  27. cin >> b[i];
  28. int ans = 0;
  29. ordered_set<int> st;
  30. for (int i = 0; i < n; ++i) {
  31. int ad = st.size() - st.order_of_key(pos[b[i]]);
  32. if (pos[b[i]] + ad > i) {
  33. ++ans;
  34. st.insert(pos[b[i]]);
  35. }
  36. }
  37. cout << ans << "\n";
  38. }
Success #stdin #stdout 0.01s 5356KB
stdin
5
5 4 3 2 1
1 2 3 4 5
stdout
4