暴力居然ac了??!!
  • 板块P1165 日志分析
  • 楼主h1yo
  • 当前回复1
  • 已保存回复1
  • 发布时间2024/11/24 18:57
  • 上次更新2024/11/24 20:39:04
查看原帖
暴力居然ac了??!!
1323263
h1yo楼主2024/11/24 18:57

代码如下

#include<iostream>
using namespace std;
const int N = 2000006;
int s[N];
int n;
int top=0;
int maxi=0;
void stack_in(int x) {
	s[++top] = x;
	if (s[top] > s[maxi])maxi = top;
}
void stack_out() {
	if (top == 0)return;
	if (maxi == top) {
		maxi= 0;
		for (int i = 1; i < top; i++) {
			if (s[i] > s[maxi])maxi = i;
		}
	}
	s[top--] = 0;
}
int stack_query(){
	if (top == 0)return 0;
	return s[maxi];
}
int main() {
	cin >> n;
	while (n--) {
		int q;
		cin >> q;
		if (q == 0) {
			int x;
			cin >> x;
			stack_in(x);
		}
		if (q == 1)stack_out();
		if (q == 2)cout << stack_query()<<endl;
	}
	return 0;
}
2024/11/24 18:57
加载中...