自定义博客皮肤VIP专享

*博客头图:

格式为PNG、JPG,宽度*高度大于1920*100像素,不超过2MB,主视觉建议放在右侧,请参照线上博客头图

请上传大于1920*100像素的图片!

博客底图:

图片格式为PNG、JPG,不超过1MB,可上下左右平铺至整个背景

栏目图:

图片格式为PNG、JPG,图片宽度*高度为300*38像素,不超过0.5MB

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+

huantwofat

自己都改变不了,如何改变世界。

  • 博客(230)
  • 收藏
  • 关注

原创 Codeforces Round #395 (Div. 1) D Timofey and a flat tree (树hash)

裸的树hash,map维护一下答案即可。 int main() { int n; cin>>n; for(int i=0;i<=2*n+2;i++){ seed[i]=((LL)rand()<<40)+((LL)rand()<<20)+rand(); } for(int i=1;i<n;i++){ int x,y;

2017-02-21 10:44:05 651 1

原创 Codeforces Round #397 F Souvenirs(线段树)

考虑离线,我们从左往右扫,对于现在的点i,我们先找到离i最近的j使得a[j]>=a[i],然后我们可以知道询问左区间在1~j的询问的答案小于等于a[j]-a[i],我们可以用线段树更新答案,然后还可能存在f=a[i],a[f]-a[i] #include #include #include #include #include #include using namespace std; const

2017-02-20 14:39:45 455

原创 hdu 5905 Black White Tree 树dp

我们可以思考对一个子树如果他节点数固定那么黑点数一定是连续变化的,那我们可以很容易想到找到每个子树大小的黑点最大值和最小值也就是dp[i]表示子树大小为i的黑点最大值,dp1[i]为最小值,剩下的就是dp。 #include #include #include #include #include using namespace std; const int maxn=2004; int dp[m

2016-09-27 20:52:02 618

原创 hdu 5854 K-th value (2016多校第九场1011) 树形dp

我们二分一下答案,然后发现如果小于等于答案的个数x,剩下的是y个那么一定满足:x>(x+y)/k也就是(k-1)*x-y>0所以我们只需要把小于等于答案的变成k-1,其他的变成-1跑一遍树形dp即可。 #include #include #include #include #include using namespace std; const int maxn=100004; struct pi

2016-08-17 21:57:56 659

原创 hdu 5852 Intersection is not allowed! (2016多校第九场1009)组合

这是一道公式题,虽然想了半天也想不出来,https://en.wikipedia.org/wiki/Lindström–Gessel–Viennot_lemma看这个就行了。 #include #include #include #include using namespace std; typedef long long LL; const int maxn=200005; const int

2016-08-16 22:33:10 903

原创 hdu 5840 This world need more Zhu (2016CCPC 网络赛1009) 分块+线段树

很明显分块,但是如果k>block我们不能用倍增,那怎么做?很简单dfs记录队列中的顺序即可。然后k #include #include #include #include #include #include #define mp(a,b) make_pair(a,b) using namespace std; const int maxn=410005; const int N=100005;

2016-08-16 22:31:30 745

原创 hdu 5838 Mountain(2016 CCPC网络赛1007) 状压

因为X的个数不超过9所以我们压X的个数就行,然后从小到大分配数字,但是如果‘.'变成了山谷怎么办,所以我们容斥搜出'.'变成X的所有情况,情况也不超过2^9,然后就写完了。 #include #include #include #include using namespace std; typedef long long LL; const int maxn=1<<9; const int mo

2016-08-16 22:29:07 753

原创 hdu 5829 Rikka with Subset (2016多校第八场1009) FFT

公式非常好求,我们只需要求每个点第k大的时候的贡献,排好序后第二个元素的贡献zuhe(i-1,k-1)*a[i]*2^(n-i),我们观察可知(i-1)!*a[i]*2^(n-i)是不变的,1/k!每次都一样也很容易所以就剩下1/(i-k)!,我们用b[i]/(i-k)!表示我们注意到把i-k倒过来变成(n-i+k)然后(n-i+k+i)=n+k所以这可以用FFT处理,注意要取模。 #inclu

2016-08-12 20:35:32 883

原创 hdu 5823 color II 状压(2016多校第八场1003)

我们直接状压表示最小值,然后我们状态里面枚举最后一个点所在的相同颜色的集合,复杂度为3^17=10^8。 #include #include #include #include using namespace std; typedef unsigned un; const int maxn=1<<18; un uo[maxn]; un mm(un n,int m){ un s=1;

2016-08-12 20:31:18 375

原创 Codeforces Round #270 G. Design Tutorial: Increase the Constraints 分块+FFT

我们如果要求两个串的哈密顿距离我们可以这样把第二个串反向,然后字母为1的地方系数为1,字母为0的系数为-1,所以我们可以算出x-y=a[n-1](x是相同的点数,y是不同的点数)有因为x+y=n所以y=(n-a[n-1])/2,所以我们可以用多项式求出a[n-1]即可,这可以用FFT实现,然后对于原题我们只需要把A分块,对于每块与B串FFT一下保存一下答案即可。 注意sqrt分块会超时,因为FF

2016-08-11 10:55:28 505

原创 Codeforces Round #270 F Design Tutorial: Change the Goal 高斯消元

因为操作是可逆的而且可以随意交换,那么我们把每n个数消掉其他位保留最高位即可,然后判断一下。 #include #include #include #include #include #define mp(a,b) make_pair(a,b) using namespace std; const int maxn=10005; typedef pairp1; vectorg,g1; int a

2016-08-11 10:49:53 354

原创 Codeforces Round #275 (Div. 1) D Random Function and Tree 树形dp

http://codeforces.com/contest/482 其实我们只需要考虑三种情况一种从左到右成立,一种从右到左成立,一种两边都成立,答案就是前两种相加减去后一种,前两种好球,后一种用dp[i][j][k]便是第i个儿子前面的取得点的个数%2后的值,后面是这个点后面的所有取得点%2后的值,然后就写完了。 #include #include #include #include #in

2016-08-10 16:44:15 291

原创 Codeforces Round #366 (Div. 1) D Captain America 网络流

对于x和y我们建立二分图,一个点将相应的xy相连,那么我们也就是要给边分配红还是蓝,加入给T分个红,如果横坐标为x的点位z个那么|2*T-z| #include #include #include #include #include #include #include #define maxn 200015 #define inf 100000000 using namespace std; s

2016-08-10 16:40:55 297

原创 bzoj 4025: 二分图 (分治+图论)

我们注意到如果出现奇环就爆炸,所以我们维护并查集即可,但是如果要连u,v我们考虑u、v到根的距离分别为x,y如果(x+y)%2==0那么根直接合并,但是如果是奇数那么久新建一个点变成x和y的父亲,注意用深度维护平衡。 #include #include #include #include #include #include #include #include #include

2016-08-09 21:26:31 530

原创 bzoj 4237: 稻草人 树状数组+分治

分治的时候我们只需要右上点在右半个,左下点在左半个即可,然后左边每个点可以用set求出它所能贡献的y的区间,对于右半边可以求出他能取到的区间,然后排个序用two points+树状数组维护一下即可。 #include #include #include #include #include #include #include using namespace std; typedef pa

2016-08-08 21:03:43 490

原创 hdu 5808 Price List Strike Back 分治

考虑分治,对于横跨中点的我们用dp处理,dp[i][j]表示从mid到i里面和为j的最大值里的最小值,dp1[i][j]表示从mid+1到i里面和为j的最大值的最小值,然后判断一下max(dp[l][j],dp1[r][s-j])时候小于等于c即可。 #include #include #include #include #include using namespace std; const i

2016-08-08 21:01:05 396

原创 bzoj 3261最大异或和 可持久化字典树

裸的可持久化字典树。 #include #include #include #include using namespace std; const int maxn=600005; int root[maxn]; int cnt; int fa[30]; namespace Trie{ int sum[maxn*25]; int ch[maxn*25][2]; void

2016-08-07 12:58:14 358

原创 bzoj 3166 [Heoi2013]Alo 可持久化字典树

次大值可以用过二分加rmq方法求出,左右边求出后会形成两个区间,然后直接上可持久化字典树。 #include #include #include #include #include using namespace std; const int maxn=50005; int root[maxn]; int cnt; int fa[50]; namespace Trie{ int sum

2016-08-07 12:56:35 316

原创 bzoj 2741 【FOTILE模拟赛】L 可持久化字典树+分块

分成sqrtn块r然后,简历可持久化字典数,然后查询即可。 #include #include #include #include #include using namespace std; typedef long long LL; const int maxn=32005; int root[maxn]; int cnt; LL fa[80]; namespace Trie{ in

2016-08-07 12:54:24 424

原创 hdu 5801 Up Sky,Mr.Zhu(2016多校第六场1009) 可持久化字典树

因为只有20,所以我们按长度建可持久化字典树,然后询问时枚举长度即可,长度为奇数和偶数可以分开求。 #include #include #include #include #include using namespace std; const int maxn=100105; int root[2][10][maxn]; int cnt; namespace Trie{ int sum

2016-08-07 12:52:29 755

原创 hdu 5803 Zhu’s Math Problem (2016多校第六场1011)数位dp

对于不等式a+c-b-d我们思考,如果分解成二进制a1+c1-b1-d1>=2的话后面不用看了,同样a1+c1-b1-d1 #include #include #include #include #include using namespace std; const int mod=1000000007; typedef long long LL; int dp[66][16][5][5]; L

2016-08-05 22:10:16 772

原创 hdu 5799 This world need more Zhu(2016多校第六场1007)莫队

裸莫队,对于路劲上的查询直接树上莫队,没学过的人可以去写写bzoj的苹果树,子树查询用dfs序后用莫队处理。 #include #include #include #include #include #include #include #define maxn 100005 using namespace std; typedef long long LL; int deap[maxn],vis

2016-08-05 22:07:26 643

原创 hdu 5798 Stabilization(2016多校第六场1006)

我们仔细想想可以发现如果两个相邻的数某个最高位不同的话,就直接影响到下面的所有位,我们社最高位为p,不妨设a[i-1][p]>a[i][p],如果下面有一位j使得a[i-1][j]!=a[i][j],那么我们想如果a[i-1][j]>a[i][j] 如果x[p]和x[j](x的第p和第j为)相同,那么他们同向,也就是a[i-1][j]-a[i][j]对答案有正贡献,同理x[p]与x[j]不同,那a

2016-08-05 22:05:21 565

原创 hdu5790 Prefix(2016多校第五场1009)trie+主席树

如果不强制在线可以莫队乱搞,但是现在我们就想怎么把trie可持久化,其实我们只要记录一个点的存在范围即可,即从小到大建立主席树,对于每个点我们在主席树里面记录最右边的位置,也就是对于r记录的是最大的l,那就好办了,只求求和即可。 #include #include #include #include #include #include using namespace std; const int

2016-08-03 21:27:21 468

原创 hdu5788 Level Up (2016多校第五场1008) 主席树

很显然如果改变一个点,那么如果这个点的值小于等于某个父亲的中位数的值,那么这个父亲的值就要变成比中位数大的最小的值,那么每个点对应了两个值,我们求这两个值的时候只需要用dfs来作为序号扔到主席树里,然后查找就行。奇怪的是用第k小的log^2的方法居然比直接找log的方法还快。 下面给出复杂度为log的代码 #include #include #include #include #include

2016-08-03 21:23:18 593

原创 hdu 5782 Cycle (2016多校第五场1002) 后缀数组

我们想如果匹配到第二个串的i的位置,第一个串可以匹配到哪,也就是说我们需要知道a[s]..a[.s+i-1]等于b[1]..b[i]的所有的s,可以用bitset存,然后就就枚举i用后缀数组判断一下就行。 #include #include #include #include #include #include #include #include #include #inc

2016-08-03 21:14:18 672

原创 hdu 5760 Palindrome Bo DP

可以发现最后一个字母一定是最左最有,那么dp方程很好转移,但是是3方的,如果先减1话,我们想到每次扫到的结果可以重复利用,于是每次维护当前数的第一个位置在哪即可。 #include #include #include #include #include using namespace std; const int maxn=5005; const int mod=1000000007; int

2016-07-29 20:04:56 346

原创 hdu 5772 String problem(2016多校第四场1009)最大权闭合图

每个w[i][j]+w[j][i]存在依赖于字母i,j的存在,i,j的存在依赖于0~9对应数字的存在,明显的最大权闭合图。 #include #include #include #include #include #include #define maxn 10005 #define inf 100000000 using namespace std; struct pi { int t

2016-07-29 15:01:12 301

原创 hdu 5764 After a Sleepless Night(2016多校第四场1002) 线段树

显然对于值为n的点一定构成链,然后我们只需要把两端最小的点作为根(为了字典序),然后就好办了,对于每棵子树根一定是最大值,然后最大值也一定形成链,这样我们就能把所有能确定的点确定下来(根的底端),然后不能确定的点的值一定小于等于输入的全值,下面介绍个人的处理方法: 我们从没有分配的最小的权值开始,因为字典序所以要分配给序号小的点,那么怎么办,我们可以先把所有未分配的店按输入的权值从小到大排序,对

2016-07-29 14:58:38 444

原创 hdu 5751 Eades FFT(BC Round 84 E)

我们可以用优先队列什么的随便搞搞,但是由于连续的需要枚举个数,所以复杂度是n^2的,但是呢我们发现用twopoint时移动相当于一个卷积,一直一个从前往后,一个从后往前,然后这个问题就解决了。 #include #include #include #include #include #include using namespace std ; typedef long long LL ; con

2016-07-24 14:28:51 547

原创 hdu 5737 Differencia (2016多校第二场1004)

线段树log^2的复杂度很显然,怎么优化?其实我们知道一个有序的数组从根往下传是依然有序,只是位置变化了而已,那么我们从根开始维护每个有序数组往下传的时候每个位置在子树中的位置,所以只需要开始的时候二分一下即可。 #include #include #include #include #include using namespace std; const int maxn=100005; c

2016-07-23 10:53:41 624

原创 hdu 5739 Fantasia (2016多校第二场1006)

本人解法是CDQ+并查集。 折半的时候我们用非路径压缩的并查集来维护,但是需要用深度来维护并查集使得复杂度减小很多,接下来就先连后一半的边然后分治前一半,然后撤销后一半的边,然后枚举前一半然后递归后一半 #include #include #include #include using namespace std; const int maxn=200005; const int mod=10

2016-07-23 10:50:13 444

原创 hdu 5735 Born Slippy(2016多校第二场1002) dp

思路源于camp一道题,很容易想到dp[u]=max(dp[v]+w[u] opt w[v]),但是u太大无法枚举,我们想到可以折半,用后一半更新当前dp值,用前一半来更新数组,假如我已经求出dp[u],那么我们枚举前一半,我们用dp[u]+(i OPT w[u])*256来更新数组 bit[i][w[u&255],然后求dp的时候因为前一半已经更行好所以只要枚举后一半  dp[u]=max(d

2016-07-23 10:46:02 394

原创 hdu4728 PowMod(2016多校第一场1006)

欧拉函数是积性函数,所以从质数入手,对于n的每一个质数我们考虑如果1~m中不是p的倍数那么直接乘(p-1),否则乘以(p-1)之后因为里面也多乘了,所以应该加上sigma(eula(i*n))*(1/p),其中i=1~m/p最后公式等于sum(n,m)=φ(p)∗sum(​p​​n​​,m)+sum(n,​p​​m​​)。 k求出来后用欧拉定理递归求值。 #include #include #

2016-07-20 17:28:01 444

原创 hdu 5727 Necklace(2016多校第一场1005)

圆排列一种宝石的排列为8!复杂度,接着对于那个yang宝石每个宝石与不会变暗的位置连边,跑一遍匈牙利 #include #include #include #include #include using namespace std; //************************************************ const int MAXN=9;//这个值要超过两边

2016-07-20 15:16:00 436

原创 hdu 5730 Shell Necklace(2016多校第一场)FFT+分治

dp[i]=sigma(dp[j]*a[i-j]) 具有多项式形式可以考虑fft,但是直接会T,考虑cdq分治,每次分治时跑fft即可 #include #include #include #include #include using namespace std ; typedef long long LL ; #define clr( a , x ) memset ( a , x ,

2016-07-20 15:13:14 1769

原创 codechef Prime Distance On Tree FFT

先树分治,对于每个点为根处理一下,然后对这个点的子树构成的多项式平方一下求一下素数个数即可。 #include #include #include #include #include #include using namespace std; const int maxn=100005; const double eps(1e-8); typedef long long LL; const do

2016-06-01 16:53:02 373

原创 hdu 4609 3-idiots (FFT)

被每个长度生成一个函数,个数作为系数,然后FFT一下,然后把每条边作为最长边算一下,注意减去他不是最长边的情况。 #include #include #include #include #include using namespace std; const int maxn=220005; const double eps(1e-8); typedef long long LL; const d

2016-06-01 08:39:13 292

原创 FFT

#include #include #include #include #include using namespace std; const int maxn=220005; const double eps(1e-8); typedef long long LL; const double PI = acos(-1.0); struct Complex { double real,

2016-06-01 08:36:09 322

原创 Codeforces Round #345 (Div. 1) E Clockwork Bomb

非常好的一道题 首先很容易想到当你拆一条边后加边的次序是随意的 然后我们可以这么想:如果在两个图中都存在的边没有任何意义,所以我们可以在结果图中先把相同边留下,把其他边删去,怎么弄呢,如果是一棵树就好办了,所以剩下就是把一堆树连起来。然后考虑开始的图,对于在结束图中不存在的边我们把它也删了,然后就是从当前节点出发有联通快,这些联通块在第二张图里面也存在,所以下面很简单了,我们只要把当前联通块的

2016-03-17 21:08:11 571

空空如也

空空如也

TA创建的收藏夹 TA关注的收藏夹

TA关注的人

提示
确定要删除当前文章?
取消 删除