Run ID 作者 问题 语言 测评结果 分数 时间 内存 代码长度 提交时间
36024 申东铉 【S】T2 C++ 解答错误 0 2000 MS 80284 KB 764 2025-02-07 14:24:55

Tests(0/20):


#include <bits/stdc++.h> #define int long long using namespace std; int n,p[10004]; int ans; signed main () { cin >> n; for (int i = 1;i <= n;i++) { cin >> p[i]; } for (int l = 1;l <= n;l++) { int m = p[l]; ans += l * l * m; priority_queue <int> pq,pq2; pq.push(p[l]); for (int r = l + 2;r <= n;r += 2) { if (p[r - 1] < m) { pq.push(p[r - 1]); } else { pq2.push(p[r - 1]); } if (p[r] < m) { pq.push(p[r]); } else { pq2.push(p[r]); } if (pq2.size() < (r - l + 1) / 2) { pq2.push(-pq.top()),pq.pop(); } if (pq2.size() > (r - l + 1) / 2) { pq.push(-pq2.top()),pq2.pop(); } m = pq.top(); ans += l * r * pq.top(); } } cout << ans << endl; return 0; }


测评信息: