'commit'
This commit is contained in:
27
TangDou/LuoGuBook/P2866_3.cpp
Normal file
27
TangDou/LuoGuBook/P2866_3.cpp
Normal file
@@ -0,0 +1,27 @@
|
||||
#include<bits/stdc++.h>
|
||||
|
||||
using namespace std;
|
||||
typedef long long LL;
|
||||
const int N=80010;
|
||||
int a[N];
|
||||
int res[N];
|
||||
stack<int> stk;
|
||||
int n;
|
||||
LL ans;
|
||||
int main() {
|
||||
cin >> n;
|
||||
for (int i = 1; i <= n; i++) {
|
||||
cin >> a[i];
|
||||
while (!stk.empty() && a[stk.top()] <= a[i]) {
|
||||
res[stk.top()] = i;
|
||||
stk.pop();
|
||||
}
|
||||
stk.push(i);
|
||||
}
|
||||
|
||||
for (int i = 1; i <= n; i++) {
|
||||
if (res[i] == 0) ans += n - i;
|
||||
else ans += res[i] - i - 1;
|
||||
}
|
||||
cout << ans;
|
||||
}
|
||||
Reference in New Issue
Block a user