Once , more , you open the door , And you’re here in my heart.
把某道测试题拿出来用OGF做一做。
$ordinary ~generating ~function$
We construct a OGF for the combination of $m$ stores.
Appearantly , the money is combinated by the sum of stores. And the choices are the Multiply principle of combination.
We let $F(x) = \prod{k=1}^{m}\sum{i=0}^{w_i}x^i$
Each polymial is a choice for a store.
The coefficient of $x^k$ is the $k$ dollors ‘ number of scheme.
The $n-m$ stores could be calculated by $plate ~insertion ~method$ , which is a classical method in math.
But a store could contribute 0 dollar.
We could create imagination balls…..(I do not understand actually)
Then we just need to expand the polymial , enumerates $t$ for the dolllars the $m$ stores contributed of $f_t$ , the remain $k-t$ dollars are from $n-m$ stores , use $plate ~insertion ~method$.
the answer is $\sum{t=0}^{k}f_tC{k-t+n-m-1}^{n-m-1}$
Time complexity is $O(m^4 + k)$
firstly I think it is $O(m^3)$ , then I got TLE…
Use $NTT $ could optimize it by $O(m^2logm + k)$
70pts Code:
1 |
|
然后又开始处于待机状态。。luogu上看了几道CF黑题发现就一道不会(你谷不是人均AK IOI?)
CF891C Envy
题意翻译
给出一个nn 个点mm条边的无向图,每条边有边权,共$Q$次询问,每次给出$k_i$条边,问这些边能否同时在一棵最小生成树上。
题解
求任意最小生成树,树上倍增(或者HPD)然后每次查询边两点的链上最小值,如果相等就继续,大于就GG,不存在小于的情况,套路题?
CF893F Subtree Minimum Query
题意翻译
题目大意:
给你一颗有根树,点有权值,m次询问,每次问你某个点的子树中距离其不超过k的点的权值的最小值。(边权均为1,点权有可能重复,k值每次询问有可能不同,强制在线)
真实询问计算方法:
x=(x′+lans)modn+1;
k=(k′+lans)modn;
数据范围: n<=100000,ai<=10^9,m<=1000000
题解
时限这么长,就不能树分块直接$O(n\sqrt{n})$艹过去么呵呵。
BFS建权值主席树,二分AC
哦不,强制在线!!!
然后想了半天考虑了DFS序考虑了BFS序但是都不行。
然后正解就是两个的结合。。。DFS序为可持久化权值线段树下标,BFS序为时间轴一个一个加点。
然后对深度个数求前缀和,二分出权值线段树的时间轴区间 ,查询下标区间$[dfn_x , dfn_x+sz_x]$的最小值即可。
时间/空间复杂度$O((n+m)logn)$
这道题很棒啊。