
数据结构
文章平均质量分 53
c_cl
这个作者很懒,什么都没留下…
展开
-
Manthan, Codefest 16(G. Yash And Trees(dfs序+线段树+bitset))
题意:给你一棵树, 根结点为1, q组操作, 每组操作有两种, 一种是对一个结点的所有子树结点的值全部+1, 另一种是查询一个结点的子树结点上值%m的余数为素数的个数。思路:对于第一个操作, 我们可以想到用dfs序给树重新标号, 使得一个结点的子树结点为相邻的一条线段, 这样,就可以很容易的用线段树进行处理了。 对于第二个操作, 为了维护一个区间内的值, 我们可以用bitset作为结点信转载 2018-04-02 23:19:25 · 152 阅读 · 0 评论 -
cf/Codeforces Round #373 div1-C/div2-E Sasha and Array 线段树 + 维护矩阵快速幂
http://codeforces.com/contest/718/problem/C题意: n个数,维护两个操作,操作1,【l,r】区间每个位置+x,操作2,【l,r】区间内,以每个位置上的数字为下标的斐波那契数列的和,%1e9+7 那么线段树的节点都换成一个2X2的矩阵 sum【i】节点维护的是i所管辖的区间的答案(也就是A[l...r]里每一个Fib(A[i])的矩阵...转载 2018-09-29 00:54:10 · 258 阅读 · 1 评论 -
Codeforces Round #381 (Div. 1) B. Alyona and a tree dfs序 二分 前缀和
B. Alyona and a tree题目连接:http://codeforces.com/contest/739/problem/BDescriptionAlyona has a tree with n vertices. The root of the tree is the vertex 1. In each vertex Alyona wrote an positi...原创 2018-10-29 10:14:53 · 144 阅读 · 0 评论 -
Codeforces Round #381 (Div. 1) C. Alyona and towers(线段树)
Alyona has built n towers by putting small cubes some on the top of others. Each cube has size 1 × 1 × 1. A tower is a non-zero amount of cubes standing on the top of each other. The towers are next t...原创 2018-10-30 23:10:23 · 203 阅读 · 0 评论 -
Codeforces Round #388 (Div. 2)D. Leaving Auction(set)
题意:有有许多人参加拍卖,问当假定某些人不参加的时候剩余的人当中谁是最终的赢家,输出他的编号和最终竞价,注:每个人都不能和自己竞价,即若某人连续竞价两次,以第一次价格为准。输入数据保证竞价递增。思路:我们只要把每个人竞价的最大值存起来, 并且把每个人的所有竞价维护在一个有序数组(方便二分), 对于一组询问, 我们从大到小遍历这k个数,把不在这k个数的最终竞价最大的两个人找到(复杂度O(K...原创 2018-11-01 22:30:15 · 168 阅读 · 0 评论 -
codeforces-777E Hanoi Factory 树状数组+dp
codeforces-777E Hanoi Factory 题目传送门题目大意:现在一共有N个零件,如果存在:bi>=bj&&bj>ai的两个零件i,j,那么此时我们就可以将零件j放在零件i上。我们现在要组成一个大零件,使得高度最高,问这个最高高度。n2 dp的优化,树状数组维护前缀max(当修改一直变大,或一直变小可以用树状数组维护;一开始看错成bi&...原创 2018-11-20 15:03:39 · 236 阅读 · 0 评论 -
Codeforces-786B-Legacy (线段树+最短路)
看到区间很容易就能想到线段树。 对于操作2,我们可以建立一棵线段树,线段树的某一个结点表示区间 [l,r] ,那么在图中建立一个结点 u 表示区间 [l,r] ,新建点u 指向 l,l+1,l+2...r的边,权值为 0 。 当得到一个操作 (v,l,r,w) 时,查询一次线段树,把所有符合 [ql,qr]∈[l,r] 的极大区间结点建立一条被 v 指向的边,权值为 w 。这样就能表示 v指向...原创 2018-11-23 19:03:22 · 245 阅读 · 0 评论 -
Codeforces Round #404 (Div. 2) E. Anton and Permutation(树状数组套主席树 求出指定数的排名)
题意很简单,就是动态的求区间逆序数。树状数组套主席树(内层主席树外层树状数组)好像就是个线段树https://www.cnblogs.com/jianrenfang/p/6568645.htmlhttps://blog.youkuaiyun.com/qq_33183401/article/details/65451604...转载 2018-11-22 15:06:35 · 143 阅读 · 0 评论 -
Codeforces - 811E - Vladik and Entertaining Flags(线段树+并查集)
题目连接:Codeforces - 811E - Vladik and Entertaining Flags线段树结点[L,R]维护区间 [L,R]的答案和第 L 列与第 R 列中所有结点的连通关系。 两个相邻区间 [L1,R1] 和 [L2,R2]合并时,第 R1 列与第 L2 列相邻的结点颜色相同的用并查集连接起来,同时答案-1就行。然后更新新结点的连通关系。 这样相当于线段树维护区间...转载 2018-12-05 00:41:44 · 185 阅读 · 0 评论 -
codeforces 840D 主席树
D. Destinytime limit per test 2.5 secondsmemory limit per test 512 megabytesinput standard inputoutput standard outputOnce, Leha found in the left pocket an array consisting of n integers, and in...转载 2018-12-26 22:59:18 · 270 阅读 · 0 评论 -
Codeforces 833B - The Bakery 【DP+线段树】
B. The Bakerytime limit per test 2.5secondsmemory limit per test 256megabytes Some time ago Slastyona the Sweetmaid decided to open her ownbakery! She bought required ingredients and a wonde...转载 2018-12-22 15:37:41 · 192 阅读 · 0 评论 -
【Codeforces 715C&716E】Digit Tree【树分治】
题意:给你一棵树,每条边有一个权值[0,9],让你找出所有点对(u,v)使得u到v路径组成的数能被m整除(像字符串一样组成)题解:这题的思路,对这棵树进行点分治,每次分治算经过根节点的满足条件的点对数有几个,每次分治时在dfs时记录下每个节点的d1(从该节点到根组成的数),d2(从根到该节点组成的数),并且我们用map来存d1的个数,用pair<int,int>来存d2和d...转载 2018-09-27 01:17:44 · 169 阅读 · 0 评论 -
Codeforces Round #371 (Div. 1) D. Animals and Puzzle 二维倍增
D. Animals and Puzzle题目连接:http://codeforces.com/contest/713/problem/DDescriptionOwl Sonya gave a huge lake puzzle of size n × m to hedgehog Filya as a birthday present. Friends immediately ...转载 2018-09-24 01:00:16 · 166 阅读 · 0 评论 -
Codeforces 629D Babaei and Birthday Cake 【线段树+离散化】
D. Babaei and Birthday Caketime limit per test 2 secondsmemory limit per test 256 megabytesinput standard inputoutput standard outputAs you know, every birthday转载 2018-03-27 23:37:18 · 176 阅读 · 0 评论 -
codeforces Codeforces Round #345 (Div. 1) C. Table Compression 排序+并查集
Little Petya is now fond of data compression algorithms. He has already studied gz, bz, zip algorithms and many others. Inspired by the new knowledge, Petya is now developing the new compression alg转载 2018-04-11 00:20:57 · 226 阅读 · 0 评论 -
Codeforces Round 650E Clockwork Bomb(并查集)
题意:有两棵树,现在可以将第一棵树的边去除,然后在两个节点之间连一条新边使得第一棵树变成第二棵树,但是这种操作有一个限制条件,就是任何时刻,图中不能出现环,问操作数最少的步骤。思路:首先可以明确一点,就是一定存在某种操作序列,使得第一棵树变成第二棵树。考虑两棵树之间相同的边,可以把这些边包含的点缩成一个点考虑,要在这两个缩点后的图上进行操作,只需要每次从树的叶子节点开始改边就能保证满足题目转载 2018-04-12 22:38:53 · 170 阅读 · 0 评论 -
CF 671D Roads in Yusland 线段树维护代价合并的思想
题目大意给定一颗N个节点的树,现在有M个工人,每个工人有三个属性ui,vi,Ci,表示这名工人可以维修节点ui到节点vi的所有路径,花费为Ci,并且保证vi是ui的祖先。问最少花费多少使得树上的每条边都有人维修。N,M≤300000 Ci≤109解题思路这题有个特殊的性质,就是每个工人只会修一条指向祖先的路径。我们设vi为一开始工人所处的位置,那么我们就可以从下往上做,设Fi表...转载 2018-04-24 01:40:50 · 421 阅读 · 0 评论 -
SPOJ COT Count on a tree 树上第k大(主席树)
题意:http://www.spoj.com/problems/COT/en/题意:给定一棵树,树上每个节点都有一个权值,问两点之间路径上第K大值思路:树上的第k大值,跟区间第k大有些不同,区间第k大每个值在前一个值的基础上新建一棵树,而树上第k大则是在父亲节点的基础上新建一棵树。查询的时候,答案就是root[v] + root[u] - root[lca(v, u)] - roo转载 2018-04-21 11:32:01 · 272 阅读 · 0 评论 -
Codeforces Round #352 ——Ultimate Weirdness of an Array
题意:一个数组的weirdness是这个数组中所有最大公约数的最大值。给出一个数组a,将a中[i,j]之间的部分去掉,剩下的部分的weirdness就是f(i,j),求所有的i,j的组合的weirdness的和。 思路按照官方的题解就好了: 如果我们计算出一个数组H,Hi代表了有多少个(l-r)使得f(l,r)≤i,这样我们就可以很容易得到解。 下面计算H。维护一个vector,vi以升序...转载 2018-04-21 22:53:41 · 176 阅读 · 0 评论 -
codeforces DIV2 E. Garlands (离线、二维树状数组)
题意:给出你一个n*m矩阵,矩阵中有一些灯泡,这些灯泡连成了k条互不重叠的链。每个灯泡都有一定的权值w,但是只有当灯泡打开的时候,才会产生贡献,刚开始所有的灯泡都是开着的。共有q次询问,有两种操作:①Switchi——表示将编号为i的链所有的灯泡取反(即开变关,关变开)。②Ask x1,y1,x2,y2——表示询问以(x1,y1)和(x2,y2)为两个端点的子矩形所产生的贡献。数据范围...转载 2018-09-09 00:25:03 · 350 阅读 · 0 评论 -
Codeforces 706E Working routine十字链表
题目大意给定一个N∗MNM的矩阵和QQ个操作。每个操作将矩阵中的两个子矩阵交换,保证这两个子矩阵没有重叠部分。 输出QQ次操作后的矩阵。Data Constraint N,M≤1000,Q≤10000NM1000Q10000题解矩阵的每个位置维护一个向右和向下的类似链表指针的东西,然后交换两个子矩阵的时候实际上就是交换边界上的指针。时间复杂度:O(NQ) // 十...转载 2018-09-06 00:57:10 · 223 阅读 · 0 评论 -
codeforces 703D D. Mishka and Interesting sum(树状数组)
D. Mishka and Interesting sumtime limit per test3.5 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputLittle Mishka enjoys programming. Since her birth...转载 2018-09-04 00:58:08 · 204 阅读 · 0 评论 -
Codeforces Round 370 (Div 2) E】【线段树 等比数列 区间合并】
E. Memory and Casinostime limit per test 4 secondsmemory limit per test 512 megabytesinput standard inputoutput standard outputThere are n casinos lined in a row. If Memory plays at ...转载 2018-09-19 00:44:33 · 246 阅读 · 0 评论 -
DNA Evolution CodeForces - 828E 树状数组
题意:给你一个DNA串,有两种操作1 a e:把位置a的字符换成字符e2 a b e:问[ a, b ]的区间内eeeeee..(e循环串)与相同的的字符有几个,并输出。思路:用线段树来保存每个字母在每个区间处于每种循环串位置的数量,node[ 字母种类 ] [ e的长度 ] [ 长度取模(相对e的长度位置) ] [ 位置 ],然后就是基本的树状数组插入和查询线段树T了,up里4...转载 2018-12-17 20:04:10 · 283 阅读 · 0 评论 -
CF869 E. The Untended Antiquity 二位树状数组+hash
题意一个地图,然后三种操作 1.一个矩阵四周加上障碍 2.一个矩阵四周的障碍消除 3.问你两个点之间是否纯在一条路径不经过障碍题解我们可以给每一个矩阵一个hash值 然后将矩阵里面的点都加上这个数 如果是撤销障碍就减去 然后判断两个点是否连通就看一下他的数是多少 至于怎么维护这个矩阵加上,我们可以用一个类似差分的思想,然后用树状数组维护一下 就像下图: 然后对于一个点...转载 2019-01-25 21:17:31 · 177 阅读 · 0 评论 -
Codeforces Round #442 (Div. 2) E. Danil and a Part-time Job dfs序+xdtree
E. Danil and a Part-time Jobtime limit per test 2 secondsmemory limit per test 256 megabytesinput standard inputoutput standard outputDanil decided to earn some money, so he had found a part-time...原创 2019-02-02 13:41:02 · 381 阅读 · 0 评论 -
Codeforces Round #484 (Div. 2) D. Shark
题意:有一只鲨鱼每天游ai公里,如果它一天游的距离大于等于k,我们就认为它游到了一个新的地方;否则认为它这一天停留在原来的地方。这只鲨鱼到过的地方不会重复。现在给出它n天游的距离(每天都不相等),我们要求出一个k,满足:1.鲨鱼停留在每个地方的天数相等。(一天游的距离大于等于k时不算停留)。2.停留过的地方尽可能多。3.有多个解时k取最小值。基于每个a都不相同这个条件我们可...转载 2019-04-24 22:16:23 · 122 阅读 · 0 评论 -
Codeforces Round #504 D. Array Restoration xdtree
题目描述:有一个长度为n的序列a,有q次操作,第i次选择一个区间,将区间里的数全部改为i,序列a的每个位置至少被改一次。得到最终的序列,然后将序列里的某些位置变成0,输出一种可能的置零之前的最终序列,或无解线段树维护区间0数,在数i的区间中i的个数+0数要等于区间长,然后即可把区间全置0;注意细节,q得有#include <iostream>#include <cst...原创 2019-05-09 00:09:03 · 173 阅读 · 0 评论 -
cf1062e E. Company xdtree+最近公共祖先
题意:在一棵树中,每次选择一个区间[l,r]最多删除一个点,使得这个区间内所有点的lca的深度最大。思路:首先有一个点,就是一颗树中一堆点的LCA其实就是这堆点DFS序最小和最大的两个点的LCA,线段树维护区间max1,max2,min1,min2,然后倍增求LCA#include <iostream>#include <cstdio>#include...原创 2019-06-08 23:21:09 · 238 阅读 · 0 评论 -
Codeforces 1070C - Cloud Computing 贪心set
题意:有n天,每天需要用k个cpu, 然后给定m个计划,对于每个计划包含L,R, c, p表示,从第L天到第R天期间,每天你都可以选用c个cpu,每个cpu的花费为p;问n天的最小花费;(当某天不能得到k个cpu时,就把能选的全选)#include <iostream>#include <cstdio>#include <algorithm&g...原创 2019-06-19 23:00:14 · 222 阅读 · 0 评论 -
Codeforces Round #510 (Div. 2) D. Petya and Array
题意:给出一个序列a,求区间[i,j]的个数,使得和小于t树状数组维护前缀和#include <iostream>#include <cstdio>#include <algorithm>#include <cstring>#include <set>#include <cmath>#include &...原创 2019-06-04 16:36:49 · 143 阅读 · 0 评论 -
Cf1108E2 xdtree
枚举minn+维护变化+线段树区间最大#include <iostream>#include <cstdio>#include <cmath>#include <algorithm>#include <cstring>#include <vector>using namespace std;int n,...原创 2019-07-14 22:06:33 · 168 阅读 · 0 评论 -
CF1108f 并查集
每种w一起考虑,与同层冲突就加#include <iostream>#include <cstdio>#include <cstring>#include <string>#include <algorithm>#include <queue>using namespace std;int n,m;s...原创 2019-07-15 13:14:39 · 228 阅读 · 0 评论 -
Cf1114f xdtree bitmark
维护一个乘积和一个bitmark表示有那些质因子注意 mp[i]|=(1ll<<j); 1后面加ll;#include <iostream>#include <cstdio>#include <algorithm>#include <cmath>#include <cstring>using namesp...原创 2019-07-18 22:57:26 · 203 阅读 · 0 评论 -
Cf1142b 倍增+离线
//根据顺序,连向最近下一个,然后倍增,找到长度n的位置,然后离线排序优先队列优先就行了#include <iostream>#include <cstdio>#include <algorithm>#include <cstring>#include <cmath>#include <queue>using...原创 2019-07-30 13:13:40 · 181 阅读 · 0 评论 -
cf1136e sdtree
https://blog.youkuaiyun.com/heucodesong/article/details/88529248https://www.cnblogs.com/pkgunboat/p/10527569.html利用前缀和的前缀和维护转载 2019-07-25 23:28:30 · 176 阅读 · 0 评论 -
E. The Number Games 倍增
The nation of Panel holds an annual show called The Number Games, where each district in the nation will be represented by one contestant.The nation has ndistricts numbered from 1 to n, each distr...转载 2019-04-24 17:38:50 · 114 阅读 · 0 评论 -
Codeforces #495 Div2 problem E. Sonya and Ice Cream(1004E)
首先用set数组维护每一个节点所连接的边的信息,然后遍历一遍所有的点,把度为1的点放入集合s,(把距离作为第一要素);然后把集合s中的点从小到大枚举,每个点存储的信息是该点及其该点的子节点中到该点的父亲节点的最大距离;枚举一个点后,把它从集合s和它父亲节点中删除。如果这个时候父节点的度变成1了,说明这个节点是父亲节点到所有子节点中距离的最大值(比这个距离小的肯定比它先删除)。然后就可以...转载 2019-05-04 20:48:22 · 111 阅读 · 0 评论 -
codeforces 878B B. Teams Formation 模拟
B. Teams Formationtime limit per test 2 secondsmemory limit per test 256 megabytesinput standard inputoutput standard outputThis time the Berland Team Olympiad in Informatics is held in a remote ...原创 2019-02-03 19:12:31 · 213 阅读 · 0 评论 -
Codeforces Round #443 (Div. 1) C. Tournament set
C. Tournamentlinkhttp://codeforces.com/contest/878/problem/CdescriptionRecently a tournament in k kinds of sports has begun in Berland. Vasya wants to make money on the bets.The scheme of...转载 2019-02-04 13:52:18 · 247 阅读 · 0 评论