Run ID | 作者 | 问题 | 语言 | 测评结果 | 分数 | 时间 | 内存 | 代码长度 | 提交时间 |
---|---|---|---|---|---|---|---|---|---|
36173 | 22级廖思学 | 【S】T2 | C++ | 通过 | 100 | 645 MS | 4520 KB | 759 | 2025-02-07 21:43:01 |
#include<bits/stdc++.h> using namespace std; #define int long long const int N=10010; int n,a[N],txt[N],ans; vector<int>cnt[N<<1]; signed main(){ // freopen("book.in","r",stdin); // freopen("book.out","w",stdout); scanf("%lld",&n); for(int i=1;i<=n;i++)scanf("%lld",&a[i]); for(int i=1;i<=n;i++){ for(int j=1;j<=n;j++){if(a[j]>a[i])txt[j]=1;else txt[j]=-1;}txt[i]=0; int sum=0;cnt[n].push_back(i); for(int j=i-1;j>=1;j--){sum+=txt[j];cnt[sum+n].push_back(j);} sum=0; for(int j=i;j<=n;j++){ sum+=txt[j]; for(auto l:cnt[-sum+n]){ans+=l*j*a[i];} } for(int j=0;j<=20000;j++)cnt[j].clear(); } printf("%lld\n",ans); return 0; }