题目

代码
#include <bits/stdc++.h>
using namespace std;
using ll = long long;const int N = 1e5+10;struct node
{int w, pos;
};node stk[N];
int p, cnt;
int stk0[N], p0;int main()
{int n;cin >> n;while(n--){int op;cin >> op;if(op == 1){int x;cin >> x;if(x == 1){cnt++;continue;}stk[++p] = {x, ++cnt};if(x == 0) stk0[++p0] = cnt;}else if(op == 2){if(cnt) cnt--;if(stk[p].pos > cnt){int x = stk[p--].w;if(x == 0) p0--;}}else if(op == 3){int x;cin >> x;if(cnt < x) puts("ERROR");else if(stk0[p0] >= cnt - x + 1) puts("0");else{ll t = 1;for(int i = p; stk[i].pos >= cnt - x + 1; i--){t *= stk[i].w;if(t >= (1ll << 32)) break;}if(t >= (1ll << 32)) puts("OVERFLOW");else cout << t << '\n';}}}}