Run ID 作者 问题 语言 测评结果 分数 时间 内存 代码长度 提交时间
36008 andy2025 【S】T2 C++ 通过 100 185 MS 420 KB 651 2025-02-07 14:05:59

Tests(20/20):


#include <bits/stdc++.h> using namespace std; #define ll long long const int N = 1e4 + 10; int n,p[N],a[N],s[N << 1]; int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); cin >> n; ll res = 0; for(int i = 1;i <= n;i++) cin >> p[i]; for(int i = 1;i <= n;i++) { memset(s,0,sizeof(s)); a[i] = 0; for(int j = 1;j <= n;j++) { if(j == i) continue; a[j] = (p[j] < p[i]) ? 1 : -1; } int now = 0; ll ans = 0; for(int j = i;j <= n;j++) now += a[j],s[now + n] += j; now = 0; for(int j = i;j;j--) now += a[j],ans += 1ll * s[-now + n] * j; ans *= 1ll * p[i]; res += ans; } cout << res; return 0; }


测评信息: