Link: CF679 D Shurikens
栈 + 模拟,巧妙的限制标记
Code
#include <iostream>
#include <algorithm>
using namespace std;
const int N = 1e5 + 5;
int s[N], num[N], ord[N];
char str[N][5];
int main()
{
int n, top = 0, pos = 0, bad = 0;
cin >> n;
for (int i = 0; i < 2 * n; i++) {
string str;
cin >> str;
if (str[0] == '+') s[++top] = ++pos;
else {
int x; cin >> x;
if (top == 0) { bad = 1; break; }
if (x < num[s[top]]) { bad = 1; break; }
ord[s[top]] = x;
num[s[--top]] = max(x, num[s[top]]);
}
if (bad) break;
}
if (bad) cout << "NO" << endl;
else {
cout << "YES" << endl;
for (int i = 1; i <= n; i++)
{
if (i == 1) cout << ord[i];
else cout << " " << ord[i];
}
cout << endl;
}
return 0;
}