[Codeforces 877E] Danil and a Part-time Job】的更多相关文章

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|…
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…
[题目链接] 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…
CodeForces 877E DFS序+线段树 题意 就是树上有n个点,然后每个点都有一盏灯,给出初始的状态,1表示亮,0表示不亮,然后有两种操作,第一种是get x,表示你需要输出x的子树和x本身一共有几个灯是亮的.pow x,表示你需要改变x的子树和x本身上的灯的状态. 题解思路 这个题肯定是用DFS序了,为啥?因为树不好操作啊(我也不会啊),使用DFS序可以把树压成一维的一串数,这样就可以使用线段树来进行区间操作了. 话说这个题是我暑假限时训练中做的,看到这个题老开心了,但是让我万万没想…
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…
E. Danil and a Part-time Job 题目链接:http://codeforces.com/contest/877/problem/E time limit per test2 seconds memory limit per test256 megabytes Danil decided to earn some money, so he had found a part-time job. The interview have went well, so now he i…
http://codeforces.com/contest/877/problem/E 真的菜的不行,自己敲一个模板,到处都是问题.哎 #include <bits/stdc++.h> using namespace std; ; #define lson (q<<1) #define rson ((q<<1)|1) struct node { int l,r,mid; int v,lazy; }tree[maxn*]; int L[maxn],R[maxn],inde…
题目链接:http://codeforces.com/contest/877/problem/E 题解:显然一看就感觉要么树链剖分要么线段树+dfs序,题目要求的操作显然用线段树+dfs序就可以实现.然后就敲一下线段树+dfs序就行挺简单的只要dfs一遍记录当前节点的下表然后再加一个leng数组来存子树最多到达几然后更新或者求值的时候只要查询(pos[x],leng[x])即可. #include <iostream> #include <cstring> #include <…