Run ID 作者 问题 语言 测评结果 分数 时间 内存 代码长度 提交时间
36032 22fhq 【S】T2 C++ 内存超限 90 1321 MS 524656 KB 1081 2025-02-07 14:45:46

Tests(18/20):


#include<bits/stdc++.h> #include<bits/extc++.h> #define int long long using namespace std; using namespace __gnu_pbds; gp_hash_table<int,int>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]); int 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+=j*p[i]*ht[s[j]]; } // cout<<ans<<endl; } cout<<ans<<endl; return 0; }


测评信息: