#include <iostream> #include <queue> #include <vector> #include <algorithm> using namespace std; int main() { int n, m; cin >> n >> m; // 用vector来模拟整个队列的顺序,初始化为1到n vector<int> all_queue(n); for (int i = 0; i < n; ++i) { all_queue[i] = i + 1; } // 用一个队列来辅助操作,初始把1到n依次入队 queue<int> operate_queue; for (int num : all_queue) { operate_queue.push(num); } // 处理每一条指令 for (int i = 0; i < m; ++i) { int x; cin >> x; // 先在vector中找到x对应的位置索引 auto it = find(all_queue.begin(), all_queue.end(), x); int index = it - all_queue.begin(); // 临时存储要移到前面的元素后面的元素 vector<int> temp; for (int j = 0; j < index; ++j) { temp.push_back(all_queue[j]); } // 移除原队列中这些元素 all_queue.erase(all_queue.begin(), all_queue.begin() + index); // 将原队列中剩余元素依次入队,模拟重新构建队列 for (int num : all_queue) { operate_queue.push(num); } // 把要移到前面的元素入队 operate_queue.push(x); // 再把之前暂存的元素依次入队 for (int num : temp) { operate_queue.push(num); } // 用新的顺序更新vector表示的队列 int size = operate_queue.size(); for (int j = 0; j < size; ++j) { all_queue[j] = operate_queue.front(); operate_queue.pop(); } } // 输出最终队列 for (int num : all_queue) { cout << num << " "; } cout << endl; return 0; } /************************************************************** Problem: 1527 User: zhuangsongyu Language: C++ Result: Runtime Error ****************************************************************/