1409.cpp (452B)
1 class Solution { 2 public: 3 vector<int> processQueries(const vector<int> &queries, int m) { 4 vector<int> vec(m), res; 5 res.reserve(queries.size()); 6 iota(vec.begin(), vec.end(), 1); 7 for (const int query : queries) { 8 int i = 0, tmp = query; 9 while (vec[i] != query) 10 swap(tmp, vec[i++]); 11 vec[i] = tmp; 12 res.push_back(i); 13 } 14 return res; 15 } 16 };