提交时间:2022-07-20 11:51:15
运行 ID: 52727
#include <bits/stdc++.h> using namespace std; deque<pair<int,int> >q,qq; int ans = 0,n; main(){ scanf("%d",&n); for (int i=1;i<=n;i++){; int x; scanf("%d",&x); while (!q.empty()&&q.front().first<=x) { qq.push_back(q.front()); q.pop_front(); } q.push_back(make_pair(x,i)); ans+=(i-q.front().second); while(!qq.empty()){ q.push_front(qq.back()); qq.pop_back(); } } printf("%d",ans); return 0; }