提交时间:2022-07-20 13:17:37
运行 ID: 52996
#include <iostream> #include <vector> #include <algorithm> #define ll long long using namespace std; int a[1000010],b[1000010]; int main() { int n,top = 0; ll ans = 0; cin>>n; for(int i(1);i <= n;i++) { int x; cin>>x; if(x > a[top]) { a[++top] = x; b[top] = i; } else { int pos = upper_bound(a + 1,a + top + 1,x) - a; if(pos > top) continue; ans+=i - b[pos]; } } cout<<ans; return 0; }