Run ID | 作者 | 问题 | 语言 | 测评结果 | 分数 | 时间 | 内存 | 代码长度 | 提交时间 |
---|---|---|---|---|---|---|---|---|---|
35977 | a+qazolite | 【S】T2 | C++ | 通过 | 100 | 256 MS | 452 KB | 758 | 2025-02-07 12:44:27 |
#include <bits/stdc++.h> using namespace std; const int N = 1e4 + 5, pre = 1e4; int n, a[N], cnt[2][N + N]; __int128 ans; void write(__int128 x) { if (!x) return; write(x / 10); putchar(x % 10 + '0'); } int main() { cin >> n; for (int i = 1; i <= n; i++) scanf("%d", a + i); for (int i = 1; i <= n; i++) { // cout << "----" << i << endl; 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); // cout << x << endl; 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]; } } write(ans); return 0; }