题目链接:http://codeforces.com/contest/877/problem/E 题解:显然一看就感觉要么树链剖分要么线段树+dfs序,题目要求的操作显然用线段树+dfs序就可以实现.然后就敲一下线段树+dfs序就行挺简单的只要dfs一遍记录当前节点的下表然后再加一个leng数组来存子树最多到达几然后更新或者求值的时候只要查询(pos[x],leng[x])即可. #include <iostream> #include <cstring> #include <…
Codeforces 题目传送门 & 洛谷题目传送门 看到集合的合并,可以本能地想到并查集. 不过这题的操作与传统意义上的并查集不太一样,传统意义上的并查集一般是用来判断连通性的,而此题还需支持赋值.集合内整体加等操作,似乎就有些难处理. 我们不妨考虑此题的弱化版:没有第二类集合的版本.也就是要求支持合并两个集合,集合整体加某个数 \(x\),单点查询三个操作. 很明显集合整体加某个数 \(x\) 就相当于在并查集根节点处打一个 \(+x\) 的标记,查询就暴力跳父亲求出待询问点到根节点路径上所…
给一个有根树,1e5个节点,每个节点有权值0/.1,1e5操作:1.将一个点的子树上所有点权值取反2.查询一个点的子树的权值和   题解: 先深搜整颗树,用dfs序建立每个点对应的区间,等于把树拍扁成一个数列,每次操作从就对点变成了对区间然后就是裸线段树 注意拍扁后的节点标号和原来的树节点标号是不等价的,要映射一下 #include <bits/stdc++.h> #define endl '\n' #define ll long long #define fi first #define s…
Description Translated by @Nishikino_Maki from Luogu 行吧是我翻的 Mad scientist Mike has constructed a rooted tree, which consists of n n vertices. Each vertex is a reservoir which can be either empty or filled with water. The vertices of the tree are numb…
Codeforces Round #620 F2. Animal Observation (hard version) (dp + 线段树) 题目链接 题意 给定一个nm的矩阵,每行取2k的矩阵,求总共矩阵里的数的和最大值,重复取到的数不算 题解 dp[i]表示当前行从第i个数开始取矩阵的最大值 dp[i] = 上一行中最大数 + 当前行第i个数到第i+k-1个数的和 - 当前行重复的 + 下一行第i个数到第i+k-1个数的和 用线段树维护 上一行中最大数 + 当前行第i个数到第i+k-1个数的…
C. Drazil and Park 题目连接: http://codeforces.com/contest/516/problem/C Description Drazil is a monkey. He lives in a circular park. There are n trees around the park. The distance between the i-th tree and (i + 1)-st trees is di, the distance between t…
题目链接: http://codeforces.com/problemset/problem/444/C J. DZY Loves Colors time limit per test:2 secondsmemory limit per test:256 megabytes 问题描述 DZY loves colors, and he enjoys painting. On a colorful day, DZY gets a colorful ribbon, which consists of…
D. Vika and Segments 题目连接: http://www.codeforces.com/contest/610/problem/D Description Vika has an infinite sheet of squared paper. Initially all squares are white. She introduced a two-dimensional coordinate system on this sheet and drew n black hor…
题目链接:http://codeforces.com/contest/610/problem/D 就是给你宽度为1的n个线段,然你求总共有多少单位的长度. 相当于用线段树求面积并,只不过宽为1,注意y和x的最大都要+1,这样才相当于求面积. #include <iostream> #include <cstdio> #include <cstring> #include <map> #include <algorithm> using names…
题目链接:http://codeforces.com/problemset/problem/242/E 给你n个数,m个操作,操作1是查询l到r之间的和,操作2是将l到r之间的每个数xor与x. 这题是线段树成段更新,但是不能直接更新,不然只能一个数一个数更新.这样只能把每个数存到一个数组中,长度大概是20吧,然后模拟二进制的位操作.仔细一点就行了. #include <iostream> #include <cstdio> #include <cmath> #incl…