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. #define yes cout << "yes\n"
  17. #define no cout << "no\n"
  18.  
  19. // Consts
  20. const int INF = 1e18;
  21. const int MOD = 1e9+7;
  22. const int N = 2e5 + 5;
  23.  
  24. // Math
  25. int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); }
  26. int lcm(int a, int b) { return (a / gcd(a, b)) * b; }
  27.  
  28. int power(int a, int b, int m = MOD) {
  29. int res = 1;
  30. while (b > 0) {
  31. if (b & 1) res = res * a % m;
  32. a = a * a % m;
  33. b >>= 1;
  34. }
  35. return res;
  36. }
  37.  
  38. int modinv(int a, int m = MOD) {
  39. return power(a, m - 2, m);
  40. }
  41.  
  42. void solve() {
  43. int n, q;
  44. cin >> n >> q;
  45.  
  46. vector<int> a(n);
  47. vector<int> t(q);
  48.  
  49. for (int i = 0; i < n; i++) cin >> a[i];
  50. for (int j = 0; j < q; j++) cin >> t[j];
  51.  
  52. vector<int> b;
  53.  
  54. for (int j = 0; j < q; j++) {
  55. for (int i = 0; i < n; i++) {
  56. if (a[i] == t[j]) {
  57. b.push_back(i + 1);
  58. int val = a[i];
  59. a.erase(a.begin() + i);
  60. a.insert(a.begin(), val);
  61. break;
  62. }
  63. }
  64. }
  65.  
  66. for (int i = 0; i < sz(b); i++) cout << b[i] << " ";
  67. cout << endl;
  68. }
  69.  
  70. int32_t main() {
  71. fast_io;
  72. int t = 1;
  73. while (t--) solve();
  74. return 0;
  75. }
  76.  
Success #stdin #stdout 0.01s 5288KB
stdin
7 5
2 1 1 4 3 3 1
3 2 1 1 4
stdout
5 2 3 1 5