【题解】洛谷P1901 发射站(栈 单调队列)

一开始做时百思不得其解,于是打了个暴力居然有60分。。

正解其实挺好理解的,不过我想不到、。。

附链接

https://www.luogu.org/blog/user41569/solution-p1901

#include
#include
#include
#include
#include
#include
#define ll long long
using namespace std;
const int maxn=1000010;
int n;
struct tower
{
	ll h;
	int w; //energy
	int num; //id
	int same; //same height
}a[maxn];
ll ans[maxn];
ll h; //height
int k; //energy 
int top; //top element of this stack
int main()
{
	scanf("%d",&n);
	scanf("%lld%d",&a[++top].h,&a[1].w);
	a[1].num=1;
	a[1].same=1;
	for(int i=2;i<=n;i++)
	{
		scanf("%lld%d",&h,&k);
		while(top!=0&&a[top].h

 

你可能感兴趣的:(题解,栈)