随笔分类 - 数据结构
摘要:构建 void build() { for (int i = 1, top = 0, pos = 0; i <= n; ++i) { top = pos;//pos为当前栈顶,top为操作前栈顶 while (pos && p[s[pos]] > p[i]) pos--;//单调栈 if (pos)
阅读全文
摘要:const int inf = 2e9; const double alpha = 0.75; bool o;//当前维度 struct point { int p[3]; friend bool operator <(point A, point B) { return A.p[o] < B.p[
阅读全文
摘要:重链剖分 int dep[Z], siz[Z], dad[Z], kid[Z];//kid[rt]:rt的重儿子编号 int tim, dfn[Z], rnk[Z], top[Z];//rnk[rt]:dfs序为rt的节点编号; top[rt]:rt所在重链的顶部节点 void search(int
阅读全文
摘要:一颗二叉搜索树应该做到的事情 int get_pre(int rt, int val)//前驱节点 { int ans; while (rt)//不断向右逼近 { if (bt[rt].val < val) ans = rt, rt = rk; else rt = lk; } return bt[a
阅读全文
摘要:基础区间加法分块 int L[Z], R[Z], bel[Z]; int a[Z], sum[Z], add[Z]; void modify(int l, int r, int val) { int ll = bel[l], rr = bel[r]; if (ll == rr)//l和r在同一块 {
阅读全文