fork download
  1. #include <iostream>
  2. #include <cstdio>
  3. #include <algorithm>
  4. #include <vector>
  5. using namespace std;
  6. typedef long long ll;
  7. #define SZ(a) (int)(a).size()
  8.  
  9. int main() {
  10. cin.sync_with_stdio(false);
  11. int n;
  12. cin >> n;
  13. vector<int> h(n);
  14. for (int i = 0; i < n; i++) {
  15. int x;
  16. cin >> x;
  17. x--;
  18. h[x] = i;
  19. }
  20. int prv = -2;
  21. int ans = n;
  22. for (int i = 0; i < n; i++) {
  23. int x;
  24. cin >> x;
  25. x--;
  26. auto cur = h[x];
  27. if (cur == prv+1) {
  28. ans--;
  29. }
  30. prv = cur;
  31. }
  32. printf("%d\n", ans);
  33. return 0;
  34. }
  35.  
Time limit exceeded #stdin #stdout 5s 6279168KB
stdin
Standard input is empty
stdout
Standard output is empty