P1823 72pts 求助。。
  • 板块学术版
  • 楼主uFTvL9
  • 当前回复0
  • 已保存回复0
  • 发布时间2022/7/20 14:11
  • 上次更新2023/10/27 19:20:17
查看原帖
P1823 72pts 求助。。
411963
uFTvL9楼主2022/7/20 14:11

https://www.luogu.com.cn/record/80380657

/*
#pragma GCC optimize (3, "Ofast", "inline")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target   ("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize ("no-stack-protector")
*/

/*
---------------------------* T I P S *-----------------------------
    Date:			Jul.20th
	Author:			uFTvL9(xwzy)
    message:
    Title:		    line.cpp/.in/.out
    Score:          72(Stack)
    Score':
    tips:			Croatian Olympiad in Informatics 2007.(COI2007)
_  					Task PATRIK.
-------------------------------------------------------------------
*/
#include <bits/stdc++.h>
using namespace std;

inline int read() {
	int x = 0, f = 1;
	char ch = getchar();
	while(ch < '0' or ch > '9') {
		if(ch == '-')
			f = -1;
		ch = getchar();
	}
	while(ch >= '0' and ch <= '9') {
		x = (x << 1) + (x << 3) + (ch ^ 48);
		ch = getchar();
	}
	return x * f;
}
int main(void) {
	stack<pair<short, int>> S;//pair<height, amount>
	
	unsigned int N;
	N = read();
	
	unsigned long long ans = 0;
	
	for(register unsigned int i = 0; i < N; i++) {
		short h = read();
		pair<short, int> vec(h, 1);
		for(; !S.empty() and S.top().first <= h; S.pop()) {
			ans += S.top().second;
			if(S.top().first == h)
				vec.second += S.top().second;
		}
		if(!S.empty())
			ans++;
		S.push(vec);
	}
	printf("%lld\n", ans);
	return 0;
}
2022/7/20 14:11
加载中...