提交时间:2021-12-07 19:14:20
运行 ID: 33727
#include <iostream> #include <cstring> #include <queue> using namespace std; struct block { int start,end,fruit; }; int a[200010]; queue<block> q,q2; bool used[200001]; int main() { cin.tie(0); cout.tie(0); ios::sync_with_stdio(false); int n,i,last,co; block x,add; cin>>n; for(i = 1;i <= n;i++) cin>>a[i]; a[n + 1] = !a[n]; for (i = 2,last = 1;i <= n + 1;i++) if(a[i] != a[i - 1]) q.push((block){last,i - 1,a[i - 1]}),last = i; co = n; while(co) { while(q.size()) { x = q.front(); q.pop(); while(used[x.start]&&x.start <= x.end) x.start++; if (x.start > x.end) continue; cout<<x.start<<' '; co--; used[x.start] = 1; if(x.end == x.start) continue; x.start++; q2.push(x); } cout<<endl; while (q2.size()) { add = q2.front(); q2.pop(); while (q2.size()) { x = q2.front(); if (x.fruit == add.fruit) { add.end = x.end; q2.pop(); } else break; } q.push(add); } } }