http://codeforces.com/contest/877/problem/E

真的菜的不行,自己敲一个模板,到处都是问题。哎

 #include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5+;
#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],index;
int vis[maxn] = {};
int a[maxn];
vector<int> g[maxn];
void dfs(int x)
{
L[x] = index;
for(int i=;i<g[x].size();i++)
{
int v = g[x][i];
if(!vis[v])
{
vis[v] = ;
index++;
dfs(v);
}
}
R[x] = index;
}
void push_up(int q)
{
tree[q].v = tree[lson].v+tree[rson].v;
}
void build(int l,int r,int q)
{
tree[q].l = l,tree[q].r = r,tree[q].mid = (l+r)/;
tree[q].lazy = ;
if(l==r)
{
tree[q].v = a[l];
//printf("%d %d\n",l,tree[q].v);
return;
}
build(l,tree[q].mid,lson);
build(tree[q].mid+,r,rson);
push_up(q);
}
void push_down(int q)
{
if(tree[q].lazy)
{
tree[lson].v = (tree[lson].r-tree[lson].l+)-tree[lson].v;
tree[rson].v = (tree[rson].r-tree[rson].l+)-tree[rson].v;
tree[q].lazy ^= ;
tree[lson].lazy ^= ;
tree[rson].lazy ^= ;
}
}
void update(int l,int r,int q)
{
if(tree[q].l>=l&&tree[q].r<=r)
{
tree[q].lazy ^= ;
tree[q].v = (tree[q].r-tree[q].l+)-tree[q].v;
return;
}
push_down(q);
if(l<=tree[q].mid) update(l,r,lson);
if(r>=tree[q].mid+) update(l,r,rson);
push_up(q); ///v值由下往上更新
}
int query(int l,int r,int q) ///由上及下
{
if(tree[q].l>=l&&tree[q].r<=r)
{
// printf("%d %d %d %d\n",tree[q].l,tree[q].r,tree[q].v,tree[q].lazy);
return tree[q].v;
}
push_down(q);
int sum = ;
if(l<=tree[q].mid) sum += query(l,r,lson);
if(r>=tree[q].mid+) sum += query(l,r,rson);
return sum;
}
int main()
{
int n;scanf("%d",&n);
for(int i=;i<=n;i++)
{
int x;scanf("%d",&x);
g[x].push_back(i);
g[i].push_back(x);
}
index = ;vis[] = ;
dfs();
for(int i=;i<=n;i++)
{
int cc;
scanf("%d",&cc);
a[L[i]] = cc; ///按dfs序来赋值
}
build(,n,);
int q;scanf("%d",&q);
while(q--)
{
char s[];
int v;
scanf("%s %d",s,&v);
if(s[]=='g')
{
printf("%d\n",query(L[v],R[v],));
}
else
{
update(L[v],R[v],);
}
}
return ;
}
/*
10
1 2 3 3 5 5 7 7 8
0 0 0 0 1 1 1 1 0 0
10
pow 3
get 3
*/

Codeforces Round #442 (Div. 2) Danil and a Part-time Job的更多相关文章

  1. Codeforces Round #442 (Div. 2) E Danil and a Part-time Job (dfs序加上一个线段树区间修改查询)

    题意: 给出一个具有N个点的树,现在给出两种操作: 1.get x,表示询问以x作为根的子树中,1的个数. 2.pow x,表示将以x作为根的子树全部翻转(0变1,1变0). 思路:dfs序加上一个线 ...

  2. Codeforces Round #442 Div.2 A B C D E

    A. Alex and broken contest 题意 判断一个字符串内出现五个给定的子串多少次. Code #include <bits/stdc++.h> char s[110]; ...

  3. Codeforces Round #442 (Div. 2)

    A. Alex and broken contest time limit per test 2 seconds memory limit per test 256 megabytes input s ...

  4. Codeforces Round #442 (Div. 2)A,B,C,D,E(STL,dp,贪心,bfs,dfs序+线段树)

    A. Alex and broken contest time limit per test 2 seconds memory limit per test 256 megabytes input s ...

  5. 【Codeforces Round #442 (Div. 2) A】Alex and broken contest

    [链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 注意是所有的名字里面,只出现了其中某一个名字一次. [代码] #include <bits/stdc++.h> usin ...

  6. 【Codeforces Round #442 (Div. 2) D】Olya and Energy Drinks

    [链接] 我是链接,点我呀:) [题意] 给一张二维点格图,其中有一些点可以走,一些不可以走,你每次可以走1..k步,问你起点到终点的最短路. [题解] 不能之前访问过那个点就不访问了.->即k ...

  7. 【Codeforces Round #442 (Div. 2) C】Slava and tanks

    [链接] 我是链接,点我呀:) [题意] 有n个位置,每个位置都可能有不定数量的tank; 你每次可以选择一个位置投掷炸弹. 并且,这个位置上的所有tank都会受到你的攻击. 并且失去一点体力. 然后 ...

  8. 【Codeforces Round #442 (Div. 2) B】Nikita and string

    [链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 枚举中间那一段从哪里开始.哪里结束就好 注意为空的话,就全是a. 用前缀和优化一下. [代码] #include <bits/ ...

  9. Codeforces Round #442 (Div. 2) B题【一道模拟题QAQ】

    B. Nikita and string One day Nikita found the string containing letters "a" and "b&qu ...

随机推荐

  1. docker镜像下载

    获得CentOS的Docker CE 预计阅读时间: 10分钟 要在CentOS上开始使用Docker CE,请确保 满足先决条件,然后 安装Docker. 先决条件 Docker EE客户 要安装D ...

  2. 配置wamp开发环境之mysql的配置

    此前我已经将wamp配置的Apache.PHP.phpmyadmin全部配置完成,以上三种配置参照 配置wamp开发环境 下面我们来看看mysql的配置,这里用的是mysql5.5.20,下载地址: ...

  3. Solr 中的 docValues=true

    前言:  在Lucene4.x之后,出现一个重大的特性,就是索引支持DocValues,这对于广大的solr和elasticsearch用户,无疑来说是一个福音,这玩意的出现通过牺牲一定的磁盘空间带来 ...

  4. SQL防止重复提交和Filter

    /class User package com.neuedu.bean; import java.io.Serializable; public class User implements Seria ...

  5. Python中re(正则表达式)模块使用方法

    Python中常用的正则表达式处理函数: re.match re.match 尝试从字符串的开始匹配一个模式,如:下面的例子匹配第一个单词. import re text = "JGood ...

  6. NOIP 2017 小凯的疑惑

    # NOIP 2017 小凯的疑惑 思路 a,b 互质 求最大不能表示出来的数k 则k与 a,b 互质 这里有一个结论:(网上有证明)不过我是打表找的规律 若 x,y(设x<y) 互质 则 : ...

  7. 像玩魔兽一样编程——谈VS2010键盘流

    早年在学校里的时候,经常玩War3,那时候很痴迷,也经常看sky.moon的一些第一视角,有的时候也会模仿模仿...好吧,往事不堪回首,现在工作了,谈一谈.Net程序猿使用VS的键盘流,如果你不知道s ...

  8. 28、editText只输入英文字母和'-',用于授权码输入

    InputFilter filter = new InputFilter() { @Override public CharSequence filter(CharSequence source, i ...

  9. day04_02 知识回顾、赋值运算符

    input命令输出的是字符串 数字转换成字符串 字符串转换成数字 以上成为类型的强制转换 运算符

  10. tornado中文教程

    http://docs.pythontab.com/tornado/introduction-to-tornado/ch2.html#ch2-1 python的各种库的中文教程 http://docs ...