单调栈模板 POJ3250
上次二分st表大法失败以后的又一次尝试233333
封装,封装,封装!!!!!!
#include <bits/stdc++.h> using namespace std; #define limit (500000 + 5)//防止溢出 #define INF 0x3f3f3f3f #define inf 0x3f3f3f3f3f #define lowbit(i) i&(-i)//一步两步 #define EPS 1e-6 #define FASTIO ios::sync_with_stdio(false);cin.tie(0); #define ff(a) printf("%d\n",a ); #define pi(a,b) pair<a,b> #define rep(i, a, b) for(ll i = a; i <= b ; ++i) #define per(i, a, b) for(ll i = b ; i >= a ; --i) #define MOD 998244353 #define traverse(u) for(int i = head[u]; ~i ; i = edge[i].next) #define FOPEN freopen("C:\\Users\\tiany\\CLionProjects\\acm_01\\data.txt", "rt", stdin) #define FOUT freopen("C:\\Users\\tiany\\CLionProjects\\acm_01\\dabiao.txt", "wt", stdout) #define debug(x) cout<<x<<endl typedef long long ll; typedef unsigned long long ull; inline ll read(){ ll sign = 1, x = 0;char s = getchar(); while(s > '9' || s < '0' ){if(s == '-')sign = -1;s = getchar();} while(s >= '0' && s <= '9'){x = (x << 3) + (x << 1) + s - '0';s = getchar();} return x * sign; }//快读 void write(ll x){ if(x < 0) putchar('-'),x = -x; if(x / 10) write(x / 10); putchar(x % 10 + '0'); } int n; int a[limit]; struct m_stack{ stack<int>s; m_stack():s(){} int operator[](const int & element){ for(; !s.empty() && s.top() <= element; s.pop()); int ans = s.size(); s.push(element); return ans; } void clear(){ while (s.size())s.pop(); } }stk; int main() { #ifdef LOCAL FOPEN; #endif while (cin>>n){ ll ans = 0; stk.clear(); stk[-INF]; rep(i ,1,n){ cin>>a[i]; } rep(i,1,n){ ans += stk[a[i]]; } cout<<ans<<endl; } return 0; }
天才选手zerol的主页:https://zerol.me/
|
WeepingDemon的个人主页:https://weepingdemon.gitee.io/blog/