提交时间:2025-02-07 13:56:21

运行 ID: 35997

#include <bits/stdc++.h> #include <bits/extc++.h> #define int long long using namespace std; using namespace __gnu_pbds; int a[10005], n; // #define mid ((l + r) >> 1) // #define ed (t.size() - 1) // struct node // { // int val = 0, ls = 0, rs = 0; // } ; // vector <node> t; // inline void pu(int x) // { // t[x].val = 0; // if (t[x].ls) // t[x].val += t[t[x].ls].val; // if (t[x].rs) // t[x].val += t[t[x].rs].val; // } // inline void upd(int x, int l, int r, int k, int val) // { // if (l == r) // { // t[x].val = val; // return ; // } // if (k <= mid) // { // if (t[x].ls == 0) // t.emplace_back((node){}), t[x].ls = ed; // upd(t[x].ls, l, mid, k, val); // } // else // { // if (t[x].rs == 0) // t.emplace_back((node){}), t[x].rs = ed; // upd(t[x].rs, mid + 1, r, k, val); // } // pu(x); // } tree <int, null_type, less <int>, rb_tree_tag, tree_order_statistics_node_update> TREE; signed main() { scanf("%lld", &n); for (int i = 1; i <= n; i++) { scanf("%lld", &a[i]); } __int128_t ans = 0; for (int l = 1; l <= n; l++) { for (int r = l; r <= n; r++) { TREE.insert(a[r]); if (((r - l) & 1) == 0) { int z = (*(TREE.find_by_order((r - l + 1) / 2))); // printf("[%lld, %lld] %lld\n", l, r, z); ans += l * r * z; } } TREE.clear(); } if (ans == 0) { putchar('0'); return 0; } stack <char> st; while (ans) { st.push(ans % 10 + '0'); ans /= 10; } while (st.size()) putchar(st.top()), st.pop(); return 0; }