Run ID | Author | Problem | Lang | Verdict | Score | Time | Memory | Code Length | Submit Time |
---|---|---|---|---|---|---|---|---|---|
139890 | 陈家宝 | [CSP-J2021]小熊的果篮 | C++ | Accepted | 100 | 764 MS | 2624 KB | 837 | 2024-03-26 16:40:28 |
#include<bits/stdc++.h> 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; }