1 条题解
-
0
#include<bits/stdc++.h> using namespace std; #define ll long long const int nmax=80005; ll n,a[nmax]; stack<ll>q; int main() { scanf("%lld",&n); for(ll i=1;i<=n;i++) scanf("%lld",&a[i]); q.push(a[1]); ll ans=0,cur=1; for(ll i=2;i<=n;i++) { if(a[i]>=q.top()) { while(!q.empty()&&a[i]>=q.top()) { q.pop(); cur--; } q.push(a[i]); ans+=cur; cur++; } else { ans+=cur; q.push(a[i]); cur++; } } printf("%lld\n",ans); return 0; }
- 1
信息
- ID
- 1660
- 时间
- 1000ms
- 内存
- 256MiB
- 难度
- 10
- 标签
- (无)
- 递交数
- 8
- 已通过
- 5
- 上传者