codeforces 877e】的更多相关文章

CodeForces 877E DFS序+线段树 题意 就是树上有n个点,然后每个点都有一盏灯,给出初始的状态,1表示亮,0表示不亮,然后有两种操作,第一种是get x,表示你需要输出x的子树和x本身一共有几个灯是亮的.pow x,表示你需要改变x的子树和x本身上的灯的状态. 题解思路 这个题肯定是用DFS序了,为啥?因为树不好操作啊(我也不会啊),使用DFS序可以把树压成一维的一串数,这样就可以使用线段树来进行区间操作了. 话说这个题是我暑假限时训练中做的,看到这个题老开心了,但是让我万万没想…
877E - Danil and a Part-time Job 思路:dfs序+线段树 dfs序:http://blog.csdn.net/qq_24489717/article/details/50569644 代码: #include<bits/stdc++.h> using namespace std; #define ll long long #define pb push_back #define ls rt<<1,l,m #define rs rt<<1|…
[题目链接] https://codeforces.com/contest/877/problem/E [算法] 首先求出这棵树的DFS序 一棵子树的DFS序为连续的一段 , 根据这个性质 , 用线段树维护区间中1的个数即可 时间复杂度 : O(NlogN) [代码] #include<bits/stdc++.h> using namespace std; ; typedef long long ll; typedef long double ld; struct edge { int to…
给一个有根树,1e5个节点,每个节点有权值0/.1,1e5操作:1.将一个点的子树上所有点权值取反2.查询一个点的子树的权值和   题解: 先深搜整颗树,用dfs序建立每个点对应的区间,等于把树拍扁成一个数列,每次操作从就对点变成了对区间然后就是裸线段树 注意拍扁后的节点标号和原来的树节点标号是不等价的,要映射一下 #include <bits/stdc++.h> #define endl '\n' #define ll long long #define fi first #define s…
E. Danil and a Part-time Job time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Danil decided to earn some money, so he had found a part-time job. The interview have went well, so now he is a…
Danil decided to earn some money, so he had found a part-time job. The interview have went well, so now he is a light switcher. Danil works in a rooted tree (undirected connected acyclic graph) with n vertices, vertex 1 is the root of the tree. There…
题目链接   Danil and a Part-time Job 题意    给出一系列询问或者修改操作 $pow$ $x$表示把以$x$为根的子树的所有结点的状态取反($0$变$1$,$1$变$0$) $get$  $x$表示求以$x$为根的子树中状态为$1$的结点数. 首先大力$dfs$序,然后线段树操作一下. 具体问题转化为:区间翻转,区间求和. #include <bits/stdc++.h> using namespace std; #define rep(i, a, b) for…
上一次我们拿学校的URP做了个小小的demo.... 其实我们还可以把每个学生的证件照爬下来做成一个证件照校花校草评比 另外也可以写一个物理实验自动选课... 但是出于多种原因,,还是绕开这些敏感话题.. 今天,我们来扒一下cf的题面! PS:本代码不是我原创 1. 必要的分析 1.1 页面的获取 一般情况CF的每一个 contest 是这样的: 对应的URL是:http://codeforces.com/contest/xxx 还有一个Complete problemset页面,它是这样的:…
http://codeforces.com/contest/738/problem/D Galya is playing one-dimensional Sea Battle on a 1 × n grid. In this game a ships are placed on the grid. Each of the ships consists of bconsecutive cells. No cell can be part of two ships, however, the shi…
http://codeforces.com/contest/738/problem/C Vasya is currently at a car rental service, and he wants to reach cinema. The film he has bought a ticket for starts in t minutes. There is a straight road of length s from the service to the cinema. Let's…