Run ID | 作者 | 问题 | 语言 | 测评结果 | 分数 | 时间 | 内存 | 代码长度 | 提交时间 |
---|---|---|---|---|---|---|---|---|---|
33724 | Ender | [CSP-J2021]小熊的果篮 | C++ | 通过 | 100 | 751 MS | 1884 KB | 974 | 2021-12-07 19:10:06 |
#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() { 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); } } }