Codechef Chef Cuts Tree】的更多相关文章

该思博的时候就思博到底,套路的时候不能再套路的一道题 首先我们将联通块的大小平方和进行转化,发现它就等价于连通点对数,而这个可以转化为连接两点的边数(距离)和 所以我们考虑第\(i\)天时,一个点对\((x,y)\)能产生贡献,当且仅当连接它们的边一条都没断,故贡献为: \[\frac{(n-1-\operatorname{dis}(x,y))^{\underline i}}{(n-1)^{\underline i}}\] 因此我们发现这个东西对于所有距离相同的点对是一样的,因此我们可以直接统计…
Codechef Union on Tree https://www.codechef.com/problems/BTREE 简要题意: 给你一棵树,\(Q\)次询问,每次给出一个点集和每个点的\(r_i\),每个点可以覆盖距离小于等于\(r_i\)的点. 问有多少点会被覆盖. 分析: 建出虚树,然后我们做两边\(dp​\)把所有点的\(r_i​\)更新成从这个点能覆盖的最远距离或从其他点出来经过这个点后能够覆盖的最远距离. 这样做的好处是对于一条边\((x,y)\),一定存在一个点\(z\),…
CodeChef:Chef and Problems 题目大意 有一个长度为n的序列$a_1,a_2,……,a_n$,每次给出一个区间[l,r],求在区间内两个相等的数的最远距离($max(j-i,满足a_i==a_j且l\le i,j \le r)$) 思路: 分块将序列分成sqrt(n)块预处理出每个数在每个块之后出现的最早位置和在每个块之前出现的最晚位置O(msqrt(n)) 然后就可以按块进行区间DP,求出所有块之间的最大值 O(nsqrt(n)) 答案就是max(f[L][R](两个数…
Home » Practice(Hard) » Observing the Tree   https://www.codechef.com/problems/QUERY Observing the Tree Problem Code: QUERY Submit Tweet All submissions for this problem are available. Chef gives you a tree, consisting of N nodes. The nodes are numbe…
[CODECHEF]Chef and Churus Description 有一个长度为\(n\)的数组\(A\),有\(n\)个函数,第\(i\)个函数的值为\(\sum_{j=l_i}^{r_i}A_j\) 有两种操作: ①修改\(A_i\) ②询问第\(l\)~\(r\)个函数值的和. Input First Line is the size of the array i.e. N Next Line contains N space separated numbers Ai denoti…
Chef and The Right Triangles The Chef is given a list of N triangles. Each triangle is identfied by the coordinates of its three corners in the 2-D cartesian plane. His job is to figure out how many of the given triangles are right triangles. A right…
题目链接 Chef and Triangles 先排序,然后得到$m - 1$个区间: $(a[2] - a[1], a[2] + a[1])$ $(a[3] - a[2], a[3] + a[2])$ $……$ $(a[n] - a[n - 1], a[n] + a[n - 1])$ 对这些区间求交集  再和$[L, R]$求并集,最后的元素个数就是答案. #include <bits/stdc++.h> using namespace std; #define rep(i,a,b) for…
题意: 单点修改$a$ 询问$a$的区间和$f$的区间和 原来普通计算机是这道题改编的吧... 对$f$分块,预处理$c[i][j]$为块i中$a_j$出现几次,$O(NH(N))$,只要每个块差分加上然后扫一遍就行了不用树状数组之类的 修改,整块直接改,还要单点修改$a$ 查询,整块直接查,两边暴力查询$a$的区间和 对$a$的操作可以用树状数组,也可以再分块维护前缀和实现$O(N)-O(1)$ 这样不用带一个log总复杂度$O(NH(N))$ 实测快了0.4s #include <iostr…
做法:我们考虑前缀异或和,修改操作就变成了区间[i,n]都异或x 查询操作就变成了:区间[1,x]中有几个k 显然的分块,每个块打一个tag标记表示这个块中所有的元素都异或了tag[x] 然后处理出这个块中每种数的个数 注意查询的时候零散的块要下放标记 代码: #include<bits/stdc++.h> #define N 100005 #define M 334 using namespace std; int cnt[M][N*14],sum[N],tag[M],ll[M],rr[M]…
传送门 题意:现在有nnn个位置,每个位置上有一个值aia_iai​. 要求支持如下两种操作: 区间乘vvv 求区间的(1−ai)(1-a_i)(1−ai​)之积 思路: 考虑转换式子: Ans=∏i=lr(1−ai)=e∑i=lrln(1−ai)Ans=\prod_{i=l}^r(1-a_i)=e^{\sum_{i=l}^rln(1-a_i)}Ans=∏i=lr​(1−ai​)=e∑i=lr​ln(1−ai​) 于是只需维护∑i=lrln(1−ai)\sum_{i=l}^rln(1-a_i)∑…