Run ID 作者 问题 语言 测评结果 分数 时间 内存 代码长度 提交时间
28495 gaochunzhen 【BJ】T1 C++ 运行超时 85 2000 MS 125256 KB 1635 2024-04-14 20:03:24

Tests(51/60):


#include <bits/stdc++.h> using namespace std; typedef long long ll; const int N = 1e6 + 9, C = 30; int n, a[N], nxt[N], lst[N], _nxt[N], _lst[N], p[N]; set<int> st, _st; void del(int u) { nxt[lst[u]] = nxt[u], lst[nxt[u]] = lst[u]; st.erase(u); } void _del(int u) { _nxt[_lst[u]] = _nxt[u], _lst[_nxt[u]] = _lst[u]; _st.erase(u); } double ans, pw[N]; bool cmp(int x, int y) { return a[x] < a[y]; } int main() { scanf("%d", &n); pw[0] = 1, pw[1] = 0.5; for (int i = 2; i <= n + 1; i++) { scanf("%d", &a[i]); pw[i] = 0.5 * pw[i - 1], p[i] = i; nxt[i] = _nxt[i] = i + 1, lst[i] = _lst[i] = i - 1; st.insert(i), _st.insert(i); } a[1] = a[n + 2] = 1e9, lst[1] = nxt[n + 2] = _lst[1] = _nxt[n + 2] = 0; st.insert(1), st.insert(n + 2), _st.insert(1), _st.insert(n + 2); sort(p + 2, p + n + 2, cmp); for (int id = 2; id <= n + 1; id++) { int i = p[id], lt = i; double s1 = 0, s2 = 0; auto it = _st.upper_bound(i); for (int j = *--it, c = 1; j && c <= C; j = _lst[j]) { if (a[j] <= a[i]) { if (a[j] < a[i]) del(j); _del(j); continue; } s1 += (lt - j) * pw[c++], lt = j; } lt = i; for (int j = *st.upper_bound(i), c = 1; j && c <= C; j = nxt[j]) { if (a[j] < a[i]) {del(j); continue;} else if (a[j] == a[i]) _del(j); s2 += (j - lt) * pw[c++], lt = j; } ans += 2.0 * a[i] * s1 * s2; } printf("%.15f\n", ans / n / n); return 0; }


测评信息: