版本比较
格雷码 括号树 划分 Emiya 家今天的饭 树的重心 树上的数
正文
增加 10 行删除 10 行
19 行未改动2021222324242526272864 行未改动939495969797989910010110210310410510610710610710810911011110 行未改动12212312412512612612712812912913013113213313413513613713713813913914014114114214314414529 行未改动17517617717817917918018118218321 行未改动19 行未改动ll k[N];inline void dfs(int pos) { if (s[pos] == '(') p[pos] = -1, stk.push(pos); else { if (stk.empty()) p[pos] = -1; if (stk.empty()) p[pos] = -1; else p[pos] = stk.top(), stk.pop(); } r[pos] = p[pos] == -1 ? 0 : r[fa[p[pos]]] + 1; k[pos] = k[fa[pos]] + r[pos];64 行未改动 return ; #endif cout << arg << ' '; dbg(args...);} }int n, typ, a[N], las[N], b[N], m, p[M], q[N];ll x, y, z, s[N];ll calc(int i) { return (s[i] << 1) - s[las[i]]; }
int stk[60], top;void print(i128 num) { while (num) { stk[++top] = num % 10; num /= 10; } while (top) cout << stk[top--]; cout << '\n'; } cout << '\n';}
int main() { // freopen("data.in", "r", stdin); // freopen("data.out", "w", stdout);10 行未改动 a[j] = b[j] % (r - l + 1) + l; } } }
s[0] = 0; for (int i = 1; i <= n; i++) s[i] = s[i - 1] + a[i];
int fr = 1, re = 0; q[++re] = 0; for (int i = 1; i <= n; i++) { while (fr < re && calc(q[fr + 1]) <= s[i]) fr++; las[i] = q[fr]; while (fr <= re && calc(q[re]) >= calc(i)) re--; q[++re] = i; }
i128 ans = 0; int pos = n;
while (pos) { i128 num = s[pos] - s[las[pos]]; num = num * num; ans += num; pos = las[pos]; }
print(ans); return 0;}```29 行未改动 return ; #endif cout << arg << ' '; dbg(args...);} }int n, m, a[N][M];ll s[M], f[N][N << 1], ans = 1;int main() { // freopen("data.in", "r", stdin);21 行未改动