'commit'
This commit is contained in:
59
TangDou/CSP-J/J2-2021/4_Queue_AC.cpp
Normal file
59
TangDou/CSP-J/J2-2021/4_Queue_AC.cpp
Normal file
@@ -0,0 +1,59 @@
|
||||
#include <bits/stdc++.h>
|
||||
using namespace std;
|
||||
const int N = 200010;
|
||||
|
||||
struct Node {
|
||||
int l, r, v;
|
||||
};
|
||||
|
||||
int w[N];
|
||||
bool st[N];
|
||||
int n;
|
||||
queue<Node> q, p;
|
||||
|
||||
int main() {
|
||||
scanf("%d", &n);
|
||||
for (int i = 1; i <= n; i++) scanf("%d", &w[i]);
|
||||
|
||||
w[n + 1] = 2;
|
||||
for (int i = 1, start = 1; i <= n; i++)
|
||||
if (w[i] != w[i + 1]) {
|
||||
q.push({start, i, w[i]});
|
||||
start = i + 1;
|
||||
}
|
||||
|
||||
int cnt = 0;
|
||||
while (cnt < n) {
|
||||
while (q.size()) {
|
||||
auto a = q.front();
|
||||
q.pop();
|
||||
|
||||
while (st[a.l] && a.l <= a.r) a.l++;
|
||||
if (a.l > a.r) continue;
|
||||
|
||||
printf("%d ", a.l);
|
||||
cnt++;
|
||||
st[a.l] = true;
|
||||
a.l++;
|
||||
if (a.l > a.r) continue;
|
||||
p.push(a);
|
||||
}
|
||||
|
||||
while (p.size()) {
|
||||
auto a = p.front();
|
||||
p.pop();
|
||||
|
||||
while (p.size()) {
|
||||
auto b = p.front();
|
||||
if (b.v == a.v) {
|
||||
a.r = b.r;
|
||||
p.pop();
|
||||
} else
|
||||
break;
|
||||
}
|
||||
q.push(a);
|
||||
}
|
||||
puts("");
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user