Run ID | 作者 | 问题 | 语言 | 测评结果 | 分数 | 时间 | 内存 | 代码长度 | 提交时间 |
---|---|---|---|---|---|---|---|---|---|
33452 | _ | [CSP-J2021]小熊的果篮 | C++ | 通过 | 100 | 752 MS | 2624 KB | 888 | 2021-12-06 13:49:42 |
#include <iostream> #include <vector> #include <queue> using namespace std; int main() { int N(0); cin >> N; vector<int> num(N), nxt(N, -1), head, tail; queue<int> heads; for (int i(0), cur(0); i != N; ++i) { cin >> num[i]; if (!i || num[i - 1] != num[i]) { heads.push(head.size()); if (i) tail.push_back(i - 1); head.push_back(i); } else nxt[i - 1] = i; } tail.push_back(N - 1); while (!heads.empty()) { int sz = heads.size(); while (sz--) { int cur(heads.front()); heads.pop(); cout << head[cur] + 1 << ' '; head[cur] = nxt[head[cur]]; if (~head[cur] && heads.back() < cur && num[head[cur]] == num[head[heads.back()]]) { nxt[tail[heads.back()]] = head[cur]; tail[heads.back()] = tail[cur]; head[cur] = -1; } if (~head[cur]) { heads.push(cur); } } cout << endl; } return 0; }