fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. #define TASK "test"
  5.  
  6. #define ll long long
  7. #define fi first
  8. #define sc second
  9. #define ii pair <int, int>
  10.  
  11. #define rep(i,s,e) for (int i = (s), _e = (e); i <= _e; i++)
  12. #define reo(i,s,e) for (int i = (s), _e = (e); i >= _e; i--)
  13. #define all(v) (v).begin(),(v).end()
  14.  
  15. const int maxn = 1e5 + 5;
  16. const int mod = 1e9 + 7;
  17. const int inf = 1e9;
  18.  
  19. int n, m;
  20. int a[maxn], pos[maxn];
  21. ll cnt[maxn];
  22.  
  23. signed main ()
  24. {
  25. cin.tie(0)->sync_with_stdio(false);
  26. if (fopen(TASK".inp","r"))
  27. {
  28. freopen(TASK".inp","r",stdin);
  29. freopen(TASK".out","w",stdout);
  30. }
  31.  
  32. cin >> n >> m;
  33. rep (i, 1, n) cin >> a[i];
  34. rep (i, 1, m)
  35. {
  36. int x; cin >> x;
  37. pos[x] = i;
  38. }
  39.  
  40. cnt[0] = 1;
  41. rep (i, 1, n)
  42. {
  43. int x = pos[a[i]];
  44. // if (x != 0)
  45. cnt[x] += cnt[x - 1];
  46. }
  47.  
  48. cout << cnt[m];
  49.  
  50. return 0;
  51. }
  52.  
  53.  
  54.  
Success #stdin #stdout 0.01s 5288KB
stdin
5 2
1 3 3 1 2
1 2
stdout
2