Run ID 作者 问题 语言 测评结果 分数 时间 内存 代码长度 提交时间
139890 陈家宝 [CSP-J2021]小熊的果篮 C++ 通过 100 764 MS 2624 KB 837 2024-03-26 16:40:28

Tests(10/10):


#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; }


测评信息: