12 2018 档案
摘要:题目大意 给定一个$n \times m$的黑白矩阵,设点$(i,j)$的权值$w_{(i,j)}$为包含该点的全白矩阵的个数,求$\sum_{i=1}^n \sum_{j=1}^m w_{(i,j)}$ 题解 首先转化问题为全部白色子矩阵的面积和 然后考虑统计答案 我们计算以某点为右下角的矩阵的贡
阅读全文
摘要:留个坑慢慢填 概念 生成函数——用多项式表示数列的形式幂级数,其中函数的$i$次项系数对应数列的第$i$项 即$A \to \sum_{i=0}^{\infty} a_ix^i$ 例如: $[1,1,1,1,1,...] \to 1+x+x^2+x^3+x^4+ ... $ $[1,a,a^2,a^
阅读全文
摘要:关键点的最小生成树? 关键点初始化为0,跑多源最短路,然后重构整个图,用Kruskal跑最小生成树 然后跑树链剖分在线回答询问 对树上每个点维护到链顶的最大值,结合线段树可以做到$\Theta(n \log n)$的复杂度
阅读全文
摘要:离散化+矩阵快速幂 首先看数据范围可以确定该题的算法为矩阵快速幂 然后易得转移矩阵 $$\begin{bmatrix} 1 & 1 & 0 \\ 1 & 1 & 1 \\ 0 & 1 & 1 \end{bmatrix}$$ 然后把障碍离散下来重构,获取每段区间内障碍的情况(共$2^3=8$种) 重构
阅读全文
摘要:fhq treap+lazy标记 就是几个题拼起来而已 cpp include"cstdio" include"cstring" include"iostream" include"algorithm" include"ctime" using namespace std; const int MA
阅读全文
摘要:矩阵快速幂+扩展欧拉定理 对于一个矩阵$A$,我们有$A^n \equiv A^{n\% \phi(m)+\phi(m)}(\%m)$ 经过简单的列举或推导可得 设目前进行了$x$轮,$f(x)$为分子,$g(x)$为分母 则有$f(x)=g(x 1) f(x 1),g(x)=2g(x 1)$ 由此
阅读全文
摘要:"题目链接" 我们离线处理这些询问 在右端点所在的位置用 来`push_back`询问 维护每个数值最后出现的位置 从左往右扫,边走边回答询问 对于每个询问我们回答第一个`p[x] vec[MAXN]; void ins(int x,int v) { if(x =n) return; p[x]=v;
阅读全文
摘要:线段树优化建图 开一棵儿子向父亲连0边的线段树1 另一棵父亲向儿子连0边的线段树0 0向1的对应节点连0边 对于点向区间加边,我们从1对应的节点向0对应的区间连边 对于区间向点加边,我们从1对应的区间向0对应的节点连边 然后跑手写堆优化Dijkstra即可 时间复杂度$\Theta ((n+m\lo
阅读全文
摘要:fhq treap 开俩哨兵节点,然后插入、删除、前驱、后继,统计即可 cpp include"cstdio" include"cstring" include"iostream" include"algorithm" include"ctime" using namespace std; cons
阅读全文
摘要:显然题目要我们求 $2\sum_{i=1}^N \sum_{j=1}^M (i,j) NM$ 即 $2\sum_{i=1}^{\min(N,M)} \phi(i)\lfloor \frac{N}{i} \rfloor \lfloor \frac{M}{i} \rfloor NM$ 线筛+前缀和+整除
阅读全文
摘要:树状数组维护前缀最大值+扫描线DP cpp include"cstdio" include"cstring" include"iostream" include"algorithm" using namespace std; const int MAXN=1e5+5; int n,m,c,maxn;
阅读全文
摘要:fhq treap 开个 和`maxn`作排序标准 置顶就更新 ,垫底就更新 改变位置就相当于找前驱后继 找排名为 的编号就是二叉查找树的模板 找编号为 前面的书个数就拆树取左边的 cpp include"cstdio" include"cstring" include"iostream" incl
阅读全文
摘要:线性DP预处理+分组背包 首先设 表示该木板前 个格刷了 次且最后一次颜色为 的最大正确数 做下 的前缀和然后转移状态 然后对每个木板跑分组背包就可以了 cpp include"cstdio" include"cstring" include"iostream" include"algorithm"
阅读全文
摘要:考虑 运算的自反性 我们可以直接枚举二进制位异或来进行转移 这样边数大约是$n \log n$级别的 总复杂度$\Theta((n\log n+m)\log n)$ cpp include"cstdio" include"cstring" include"iostream" include"algo
阅读全文
摘要:状压DP $dp[i]$表示当前选人状态为$i$且选择了前$i.count()$个物品时最大的概率 cpp include"cstdio" include"cstring" include"iostream" include"algorithm" using namespace std; const
阅读全文
摘要:裸的二维数点 cpp include"cstdio" include"cstring" include"iostream" include"algorithm" using namespace std; const int MAXN=5e5+5; int n,m,maxn; int Tib[MAXN
阅读全文
摘要:单点修改+区间合并 若该区间最大值小于base, 若该区间为单点, 若该区间左区间最大值小于base, 否则 cpp include"cstdio" include"cstring" include"iostream" include"algorithm" using namespace std;
阅读全文
摘要:AC自动机在预处理fail的时候预处理下节点对应的匹配串的长度 这样复杂度就是严格$\Theta(n)$的 只需要一个栈,在trie图上跑就可以了 cpp include"cstdio" include"cstring" include"iostream" include"algorithm" us
阅读全文
摘要:为什么不试试手写bitset呢QAQ 存在字符 对应二进制第 位为1 这样就是线段树维护区间或了 cpp include"cstdio" include"cstring" include"iostream" include"algorithm" using namespace std; const
阅读全文
摘要:暴力枚举跑三遍堆优化Dijkstra即可 手写堆记得清零 cpp include"cstdio" include"cstring" include"iostream" include"algorithm" using namespace std; const int MAXN=155; const
阅读全文
摘要:$F[i]=\min\{ F[j]+(lis[i] lis[j]+i j 1 L)^2 \}$ $f(i)=lis[i]+i,g(i)=f(i)+L+1$ $F[i]=F[j]+(f(i) g(j))^2$ $F[i]=F[j]+f(i)^2 2f(i)g(j)+g(j)^2$ $F[j]=2f(i
阅读全文
摘要:题目大意:求十进制下x!的位数 这题其实就是要求$\lg$函数值的前缀和啊 对于一个数x,若$\lg x=y$,则其位数为$\lfloor y+1 \rfloor$ 然后对于对数,我们有$\lg \prod_{i=1}^x i= \sum_{i=1}^x \lg i$ 预处理前缀和之后在线$\The
阅读全文

浙公网安备 33010602011771号