璟雯院

珺璟如晔,雯华若锦

用户工具

站点工具


icpc:problems:luogup1165
problems
名称日志分析
题目编号P1165
题目链接luogu.com.cn/…
来源Luogu
算法分类, 栈_例题
难易程度容易

日志分析

想法

维护最大值栈,入栈时比较,最大值才有价值。

代码实现

#include<cstdio>
#include<algorithm>
using namespace std;
const int N = 1e5*2+10;
int sta[N], top;
int main() {
	int T, mod, temp;
	scanf("%d", &T);
	while(T--) {
		scanf("%d", &mod);
		if(mod == 0) {
			scanf("%d", &temp);
			sta[top+1] = max(sta[top], temp);
			top++;
		}
		else if(mod == 1) {
			top--;
		}
		else if(mod == 2) {
			printf("%d\n", sta[top]);
		}
	}
	return 0;
}
/app/www/public/data/pages/icpc/problems/luogup1165.txt · 最后更改: 2024/01/30 11:50 由 温婕莺