2014北京网络预选赛1008(线段树区间操作)HDU5039
来源:互联网 发布:日系男装淘宝店推荐 编辑:程序博客网 时间:2024/04/20 11:47
Hilarity
Time Limit: 12000/6000 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others)Total Submission(s): 211 Accepted Submission(s): 51
Problem Description
After June 1st, elementary students of Ted Land are still celebrating "The Sacred Day of Elementary Students”. They go to the streets and do some elementary students stuff. So we call them "elementary students". There are N cities in Ted Land. But for simplicity, the mayor Matt only built N - 1 roads so that all cities can reach each other. Some of the roads are occupied by the "elementary students". They will put an celebration hat on everyone who goes through the road without one. But if someone goes through the road with a celebration hat on his head, "elementary students" will steal the hat for no reason. Since Matt doesn’t have a celebration hat, he wants to know how many different paths in his land that he can end up with a hat. Two paths are considered to be different if and only if they have different start city or end city. As the counsellor of the mayor Matt, you have to answer this question for him. The celebration elementary students are not stable: sometimes a new crowd of elementary students go to an empty road; sometimes the elementary students on a road will go back home and remain the road empty. Matt will send you the monitor about the change of elementary students on road and ask you the question above. You will be fired if you answer wrong.
Input
The first line of the input contains an integer T, denoting the number of testcases. Then T test cases follow.
For each test case, the first line contains N (1<=N<=30000) describing the number of cities.
Then N lines follow. The ith line of these contains the name of the ith city, it’s a string containing only letters and will not be longer than 10.
The following N - 1 lines indicate the N - 1 edges between cities. Each of these lines will contain two strings for the cities’ name and a integer for the initial status of the edge (0 for empty, 1 for crowded).
Then an integer M (1<=M<=60000) describes the number of queries. There are two kinds of query:
● "M i" means the status changing of the ith (starting from 1) road (0 to 1, 1 to 0);
● "Q" means that Matt asks you the number of different paths.
For each test case, the first line contains N (1<=N<=30000) describing the number of cities.
Then N lines follow. The ith line of these contains the name of the ith city, it’s a string containing only letters and will not be longer than 10.
The following N - 1 lines indicate the N - 1 edges between cities. Each of these lines will contain two strings for the cities’ name and a integer for the initial status of the edge (0 for empty, 1 for crowded).
Then an integer M (1<=M<=60000) describes the number of queries. There are two kinds of query:
● "M i" means the status changing of the ith (starting from 1) road (0 to 1, 1 to 0);
● "Q" means that Matt asks you the number of different paths.
Output
For each test case, first output one line “Case #x:”, where x is the case number (starting from 1).
Then for each “Q” in input, output a line with the answer.
Then for each “Q” in input, output a line with the answer.
Sample Input
15abcdea b 1b c 0c d 1d e 17QM 1QM 3QM 4Q
Sample Output
Case #1:12880
题意:给出一棵n个点的树,边权为0或1,可以修改任何一条边的值,查询整棵树上有多少对u,v之间路径的异或值为1
思路:首先根据异或的性质不难发现求xor(u,v)=xor(1,u)^xor(1,v)
所以可以用线段树维护每个xor(1,u)
1.修改操作,假如要修改u与其父亲的边,则以u为根的子树的xor全都改变了,即取反
所以可以先将整棵树的用DFS序列化,也就是所谓的树形转线性,每个节点及其子树都是一段连续的线段
2.查询,直接查询整个线段就好了
0 0
- 2014北京网络预选赛1008(线段树区间操作)HDU5039
- dfs+线段树(hdu5039 - Hilarity)
- 2014牡丹江网络预选赛E题(线段树)zoj3813
- 2014北京网络预选赛1006(贪心)HDU5037
- 天津网络预选赛 1007-Giant_For(线段树+set)
- ICPC2017网络赛(北京)Minimum(线段树or树状数组区间最值维护)
- 2017 acmicpc 北京网络赛 IMinimum(线段树求区间最值)
- 2014北京网络预选赛1005(强连通缩点+期望)HDU5036
- ACM-ICPC国际大学生程序设计竞赛北京赛区(2017)网络赛 I.Minimum(线段树区间极值+分类讨论)
- 线段树区间操作
- 2014广州网络预选赛1008(树链剖分)HDU5029
- 2017ICPC北京网络赛Minimum(线段树+区间最值)
- hdu4578(线段树多种区间操作)
- 北京赛区(2017)网络赛 之 Minimum(线段树)
- 【POJ3468】区间操作 线段树
- HihoCoder-1586 Minimum(线段树,区间最值,ACM-ICPC国际大学生程序设计竞赛北京赛区(2017)网络赛)
- hdu 3577 线段树区间操作(带有懒操作)
- poj3667 Hotel (线段树--区间合并)转自网络
- Android 外部存储权限分析
- android 一个textview里设置字体的样式
- Mongodb在Windows下安装及配置
- 将一个整数在计算机中的二进制表示打印出来
- 编码规范与工作心得
- 2014北京网络预选赛1008(线段树区间操作)HDU5039
- iOS中代码支持多国语言切换的实现(Xcode5+iOS7)
- Unity 3D www 请求 集成
- 内存泄露
- Receiver not registered: android.widget.ViewFlipper 问题
- jstl 或者el表达式如何读取request中的对象
- TIPTOP——p_qry动态查询程序介绍
- android应用开发相关资源下载
- qemu 迁移使用方法