额,我知道我用了一个很笨的办法,肯定会超时的,但是哪位 dalao 可以帮我解释一下为什么第一个测试点会 WA ?
代码呈上(可以顺便帮我改成不超时的吗?):
#include<iostream>
#include<stack>
using namespace std;
stack<int> s;
int main() {
int n, x, maxx, j, a[200001];
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> x;
maxx = 0;
j = 1;
if (x == 0) {
cin >> x;
s.push(x);
}
if (x == 1) {
if (s.empty() != 1) {
s.pop();
}
}
if (x == 2) {
while (s.empty() != 1) {
if (s.top() > maxx) {
maxx = s.top();
}
a[j] = s.top();
s.pop();
j++;
}
j--;
cout << maxx << endl;
while (j != 0) {
s.push(a[j]);
j--;
}
}
}
return 0;
}