Run ID | 作者 | 问题 | 语言 | 测评结果 | 分数 | 时间 | 内存 | 代码长度 | 提交时间 |
---|---|---|---|---|---|---|---|---|---|
36062 | 22fhq | 【S】T2 | C++ | 运行超时 | 90 | 2000 MS | 772 KB | 1083 | 2025-02-07 15:05:55 |
#include<bits/stdc++.h> #include<bits/extc++.h> #define int short using namespace std; using namespace __gnu_pbds; map<int,__int32_t>ht; int n,p[10005],a[10005],s[10005]; void read(int &x){ x=0; char c=getchar(); while(!isdigit(c))c=getchar(); while(isdigit(c))x=x*10+(c^48),c=getchar(); return; } signed main(){ read(n); for(int i=1;i<=n;i++)read(p[i]); long long ans=0; for(int i=1;i<=n;i++){ ht.clear(); // ht[0]++; for(int j=1;j<=n;j++){ if(p[j]>p[i])a[j]=1; else if(p[j]<p[i])a[j]=-1; else a[j]=0; s[j]=s[j-1]+a[j]; } // for(int j=1;j<=n;j++)cout<<a[j]<<" "; // cout<<endl; // for(int j=1;j<=n;j++)cout<<s[j]<<" "; // cout<<endl; for(int j=0;j<i;j++)ht[s[j]]+=j+1; for(int j=i;j<=n;j++){ // cout<<j<<" "<<p[i]<<" "<<s[j]<<" "<<ht[-s[j]]<<endl; ans+=1ll*j*p[i]*ht[s[j]]; } // cout<<ans<<endl; } cout<<ans<<endl; return 0; }