You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

41 lines
927 B

2 years ago
#include <bits/stdc++.h>
using namespace std;
const int N = 200010;
struct Node {
int id, v;
};
int n;
queue<Node> q, p;
int main() {
scanf("%d", &n);
for (int i = 1; i <= n; i++) {
int x;
scanf("%d", &x);
q.push({i, x});
}
int cnt = 0;
while (cnt < n) {
int last = 2; //每一轮,首位都需要输出,所以这里的 flag需要每次初始化为2,黄海最初将它放在while的外面调试了近半个小时~
while (q.size()) {
auto a = q.front();
q.pop();
if (a.v != last) {
printf("%d ", a.id);
last = a.v;
cnt++;
} else
p.push(a);
}
puts("");
while (p.size()) {
auto a = p.front();
q.push(a);
p.pop();
}
}
return 0;
}