fork(1) download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. // Speed
  5. #define fast_io ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
  6.  
  7. // Typedefs
  8. #define int long long
  9. #define pb push_back
  10. #define ff first
  11. #define ss second
  12. #define all(x) (x).begin(), (x).end()
  13. #define rall(x) (x).rbegin(), (x).rend()
  14. #define sz(x) ((int)(x).size())
  15. #define endl '\n'
  16.  
  17. // Loops
  18. #define rep(i,a,b) for(int i=a;i<b;++i)
  19. #define each(x, a) for (auto &x : a)
  20.  
  21. // Logic
  22. void solve() {
  23. int n, q;
  24. cin >> n >> q;
  25.  
  26. vector<int> a(n), t(q);
  27.  
  28. rep(i,0,n) cin >> a[i];
  29. rep(j,0,q) cin >> t[j];
  30.  
  31. vector<int> b;
  32.  
  33. rep(j,0,q) {
  34. int x = t[j];
  35.  
  36. auto it = find(a.begin(), a.end(), x);
  37. int pos = it - a.begin();
  38. b.pb(pos + 1);
  39. rotate(a.begin(), a.begin() + pos,
  40. a.begin() + pos + 1);
  41. }
  42.  
  43. each(x, b) cout << x << " ";
  44. cout << endl;
  45. }
  46.  
  47. // Main
  48. int32_t main() {
  49. fast_io;
  50. int t = 1;
  51. while (t--) solve();
  52. return 0;
  53. }
  54.  
Success #stdin #stdout 0.01s 5284KB
stdin
7 5
2 1 1 4 3 3 1
3 2 1 1 4
stdout
5 2 3 1 5