Run ID | 作者 | 问题 | 语言 | 测评结果 | 分数 | 时间 | 内存 | 代码长度 | 提交时间 |
---|---|---|---|---|---|---|---|---|---|
36118 | zqqq | 【S】T2 | C++ | 通过 | 100 | 426 MS | 668 KB | 740 | 2025-02-07 16:14:40 |
#include<bits/stdc++.h> using namespace std; #define ll long long const int N = 1e4 + 5, pre = 1e4; ll n, a[N], cnt[2][N + N],ans; int main(){ //freopen("book10.in","r",stdin); //freopen("book10.out","w",stdout); ios::sync_with_stdio(0); cin>>n; for (int i = 1; i <= n; i++) { cin>>a[i]; } for (int i = 1; i <= n; i++) { memset(cnt, 0, sizeof(cnt)); int x = 0; for (int j = i; j >= 1; j--) { x += a[j] < a[i] ? -1 : (a[j] > a[i] ? 1 : 0); cnt[j & 1][pre + x] += j; } x = 0; for (int j = i; j <= n; j++) { x += a[j] < a[i] ? 1 : (a[j] > a[i] ? -1 : 0); ans += 1ll * cnt[j & 1][pre + x] * j * a[i]; } } cout<<ans; return 0; }