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.
53 lines
1.2 KiB
53 lines
1.2 KiB
#include <bits/stdc++.h>
|
|
using namespace std;
|
|
const int N = 200010;
|
|
// 60% TLE 4个点
|
|
// 循环队列,数组资源不会用尽,但性能不是太好。
|
|
struct Node {
|
|
int id, v;
|
|
};
|
|
|
|
int n;
|
|
|
|
int hhq, ttq;
|
|
int hhp, ttp; // 循环队列需要考虑初始值,与++tt,tt++等区别,这东西害人不浅
|
|
Node q[N], p[N];
|
|
|
|
int main() {
|
|
scanf("%d", &n);
|
|
for (int i = 1; i <= n; i++) {
|
|
int x;
|
|
scanf("%d", &x);
|
|
q[ttq++] = {i, x};
|
|
if (ttq == N) ttq = 0;
|
|
}
|
|
|
|
int cnt = 0;
|
|
while (cnt < n) {
|
|
int flag = 2;
|
|
while (hhq != ttq) {
|
|
auto a = q[hhq];
|
|
hhq++;
|
|
if (hhq == N) hhq = 0;
|
|
|
|
if (a.v != flag) {
|
|
printf("%d ", a.id);
|
|
flag = a.v;
|
|
cnt++;
|
|
} else {
|
|
p[ttp++] = a;
|
|
if (ttp == N) ttp = 0;
|
|
}
|
|
}
|
|
puts("");
|
|
while (hhp != ttp) {
|
|
auto a = p[hhp];
|
|
q[ttq++] = a;
|
|
if (ttq == N) ttq = 0;
|
|
|
|
hhp++;
|
|
if (hhp == N) hhp = 0;
|
|
}
|
|
}
|
|
return 0;
|
|
} |