int N, z[500003]; double f[500003], _sqrt[500003]; std::deque<Node> q;
inlineboolcheck(int x, int y, int k){ return z[x] + _sqrt[k - x] > z[y] + _sqrt[k - y]; }
voidprocess(){ q.clear(); Node now{1, N, 1}; for (int i = 2, l, r, mid; i <= N; ++i) { if (z[i] < z[now.x]) continue; for (l = i, r = N; l <= r; ) { mid = (l + r) >> 1; if (check(now.x, i, mid)) l = mid + 1; else r = mid - 1; } if (l > N) continue; if (l < now.l) { now = q.front(); q.pop_front(); --i; continue; } now.r = r; q.push_front(now); now = {l, N, i}; } q.push_front(now); now = q.back(); q.pop_back(); for (int i = 1; i <= N; ++i) { if (now.r < i) now = q.back(), q.pop_back(); f[i] = std::max(f[i], z[now.x] + _sqrt[i - now.x]); } }
intmain(){ cin >> N; for (int i = 1; i <= N; ++i) { cin >> z[i], f[i] = z[i]; _sqrt[i] = sqrt(i); } process(); std::reverse(z + 1, z + N + 1); std::reverse(f + 1, f + N + 1); process(); for (int i = N; i >= 1; --i) cout << std::max((int)ceil(f[i]) - z[i], 0) << '\n'; cout.flush(); return0; }
boolsolve(int N, int *z){ std::sort(z + 1, z + N + 1, std::greater<int>()); for (int i = 1; i <= N; ++i) if (z[i + 1] < i + 1) { int j = i; while (z[j + 1] >= i) ++j; return ((z[i] - i) | (j - i)) & 1; } return0; }
std::bitset<20013> vis; int N, M, top, tot = 1, dft, cntDCC; iarrN U, V, s, bel, dfn, low, deg, head;
structEdge { int nxt, to; } e[20013];
voidtarjan(int u){ s[++top] = u; dfn[u] = low[u] = ++dft; for (int i = head[u], v; i; i = e[i].nxt) { if (vis[i]) continue; if (!dfn[v = e[i].to]) { vis.set(i), vis.set(i ^ 1); tarjan(v); vis.reset(i ^ 1), vis.reset(i ^ 1); dmin(low[u], low[v]); } elsedmin(low[u], dfn[v]); } if (dfn[u] == low[u]) { ++cntDCC; do bel[s[top]] = cntDCC; while (s[top--] != u); } }
intmain(){ cin >> N >> M; for (int i = 1; i <= M; ++i) { cin >> U[i] >> V[i]; addEdge(U[i], V[i]), addEdge(V[i], U[i]); } tarjan(1); for (int i = 1; i <= M; ++i) if (bel[U[i]] != bel[V[i]]) ++deg[bel[U[i]]], ++deg[bel[V[i]]]; int ans = 0; for (int i = 1; i <= cntDCC; ++i) if (deg[i] == 1) ++ans; printf("%d", (ans + 1) >> 1); return0; }