1890

将树的每个节点都转换为区间的形式 然后再利用线段树对结点更新 这题用了延迟标记 相对普通线段树 多了dfs的转换 把所要求的转换为某段区间

RE了N次 最后没办法了 记得有个加栈的语句 拿来加上A了。。

 #pragma comment(linker, "/STACK:102400000,102400000")
#include <iostream>
#include<cstdio>
#include<cstring>
#include<stdlib.h>
#include<vector>
#include<algorithm>
using namespace std;
#define N 50010
#define LL long long
vector<int>w[N];
LL lleft[N],rright[N],po[N],c[N],cnt;
LL o[N];
LL s[N<<],te[N<<];
void up(int w)
{
s[w] = s[w<<]+s[w<<|];
}
void build(int l,int r,int w)
{
if(l==r)
{
s[w] = c[l];
return ;
}
int m = (l+r)>>;
build(l,m,w<<);
build(m+,r,w<<|);
up(w);
}
void pushdown(int w,int d)
{
if(te[w])
{
te[w<<] += te[w];
te[w<<|]+=te[w];
s[w<<] += (d-d/)*te[w];
s[w<<|]+=d/*te[w];
te[w] = ;
}
}
void update(int a,int b,LL v,int l,int r,int w)
{
if(a<=l&&b>=r)
{
te[w] += v;
s[w] += v*(r-l+);
return ;
}
pushdown(w,r-l+);
int m = (l+r)>>;
if(a<=m)
update(a,b,v,l,m,w<<);
if(b>m)
update(a,b,v,m+,r,w<<|);
up(w);
}
LL query(int a,int b,int l,int r,int w)
{
if(a<=l&&b>=r)
{
return s[w];
}
pushdown(w,r-l+);
int m = (l+r)>>;
LL re =;
if(a<=m)
re+=query(a,b,l,m,w<<);
if(b>m)
re+=query(a,b,m+,r,w<<|);
return re;
}
void dfs(int u)
{
int i;
for(i = ; i < (int)w[u].size() ; i++)
{
int v = w[u][i];
dfs(v);
if(lleft[u]==-)
lleft[u] = lleft[v];
else
lleft[u] = min(lleft[v],lleft[u]);
if(rright[u]==-)
rright[u] = rright[v];
else
rright[u] = max(rright[u],rright[v]);
}
cnt++;
c[cnt] = o[u];
po[u] = cnt;
if(lleft[u]==-)
lleft[u] = cnt;
else
lleft[u] = min(lleft[u],cnt);
if(rright[u]==-)
rright[u] = cnt;
else
rright[u] = max(rright[u],cnt);
}
int main()
{
int n,q,s0,x,u,v,i;
char ss[];
memset(lleft,-,sizeof(lleft));
memset(rright,-,sizeof(rright));
scanf("%d%d%d",&n,&q,&s0);
o[] = s0;
for(i = ; i <= n ; i++)
w[i].clear();
for(i = ; i <= n ; i++)
{
scanf("%d%d",&u,&v);
u++;
w[u].push_back(i);
o[i] = v;
}
dfs();
build(,n,);
while(q--)
{
scanf("%s%d%d%d",ss,&x,&u,&v);
x++;
if(ss[]=='e')
{
int pp = po[x];
LL tx = query(pp,pp,,n,);
if(tx<u)
update(pp,pp,v,,n,);
}
else if(ss[]=='d')
{
int ll = lleft[x];
int rr = rright[x];
int nu = rr-ll+;
LL tx = query(ll,rr,,n,);
if(1.0*tx/nu<u)
update(ll,rr,v,,n,);
}
}
for(i = ; i <= n ; i++)
printf("%lld\n",query(po[i],po[i],,n,));
return ;
}

1890. Money out of Thin Air(线段树 dfs转换区间)的更多相关文章

  1. R - Weak Pair HDU - 5877 离散化+权值线段树+dfs序 区间种类数

    R - Weak Pair HDU - 5877 离散化+权值线段树 这个题目的初步想法,首先用dfs序建一颗树,然后判断对于每一个节点进行遍历,判断他的子节点和他相乘是不是小于等于k, 这么暴力的算 ...

  2. 洛谷P2982 [USACO10FEB]慢下来Slowing down(线段树 DFS序 区间增减 单点查询)

    To 洛谷.2982 慢下来Slowing down 题目描述 Every day each of Farmer John's N (1 <= N <= 100,000) cows con ...

  3. URAL 1890 . Money out of Thin Air (dfs序hash + 线段树)

    题目链接: URAL 1890 . Money out of Thin Air 题目描述: 给出一个公司里面上司和下级的附属关系,还有每一个人的工资,然后有两种询问: 1:employee x y z ...

  4. HDU 1754 I Hate It(线段树单点替换+区间最值)

    I Hate It [题目链接]I Hate It [题目类型]线段树单点替换+区间最值 &题意: 本题目包含多组测试,请处理到文件结束. 在每个测试的第一行,有两个正整数 N 和 M ( 0 ...

  5. HDU 5692 线段树+dfs序

    Snacks Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Sub ...

  6. Tsinsen A1505. 树(张闻涛) 倍增LCA,可持久化线段树,DFS序

    题目:http://www.tsinsen.com/A1505 A1505. 树(张闻涛) 时间限制:1.0s   内存限制:512.0MB    总提交次数:196   AC次数:65   平均分: ...

  7. BZOJ_3252_攻略_线段树+dfs序

    BZOJ_3252_攻略_线段树+dfs序 Description 题目简述:树版[k取方格数] 众所周知,桂木桂马是攻略之神,开启攻略之神模式后,他可以同时攻略k部游戏.今天他得到了一款新游戏< ...

  8. 【XSY2534】【BZOJ4817】树点涂色 LCT 倍增 线段树 dfs序

    题目大意 ​ Bob有一棵\(n\)个点的有根树,其中\(1\)号点是根节点.Bob在每个点上涂了颜色,并且每个点上的颜色不同.定义一条路径的权值是:这条路径上的点(包括起点和终点)共有多少种不同的颜 ...

  9. hdu 5039 线段树+dfs序

    http://acm.hdu.edu.cn/showproblem.php?pid=5039 给定一棵树,边权为0/1.m个操作支持翻转一条边的权值或者询问树上有多少条路径的边权和为奇数. 用树形df ...

随机推荐

  1. mac下安装redis

    安装php_redis.so 首先用git从https://github.com/nicolasff/phpredis下载源码.然后依次执行以下命令 sudo /Applications/XAMPP/ ...

  2. PHP学习之开发工具

    刚接触PHP,必然需要一套完整的开发工具.每个语言都有各种各样的编辑工具.采用了相对来说比较了解的Eclipse来作为开发工具. 1.要是用Eclipse需要安装JDK或JRE(Eclipse本身就是 ...

  3. laravel扩展xls处理maatwebsite/excel

    github地址:https://github.com/Maatwebsite/Laravel-Excel 安装: sudo composer require maatwebsite/excel 配置 ...

  4. phpcmsv9全站搜索,不限模型

    简单修改一下v9默认的搜索功能,可以不按模型搜索全站内容 下面是被修改后的search模块中的index.php文件 <?php defined('IN_PHPCMS') or exit('No ...

  5. SendMessage 窗口函数

    函数功能:该函数将指定的消息发送到一个或多个窗口.此函数为指定的窗口调用窗口程序,直到窗口程序处理完消息再返回.而函数PostMessage不同,将一个消息寄送到一个线程的消息队列后立即返回. MSD ...

  6. git命令行

    cmd下运行或者 进入git bash运行 输入 exit退出切换到仓库目录后再git statusgit commit -m 注释 git pull origin1 mastergit push o ...

  7. unity3d 延迟处理方法

    Invoke("方法名", 多少秒后执行); InvokeRepeating("方法名", 多少秒后执行,开始执行后隔多长时间再次执行一次); CancelIn ...

  8. oracle分页与rownum

    Oracle分页(limit方式的运用) Oracle不支持类似于 MySQL 中的 limit. 但你还是可以rownum来限制返回的结果集的行数. 第一种 select * from a_matr ...

  9. [转]DRY原则和Shy原则

    转自:http://blog.csdn.net/hukeab/article/details/2944675   保障可维护性的主要诀窍是遵循DRY原则和Shy原则. 在一个系统的整个生命周期里,理解 ...

  10. oracle 将科学计数法数据转换为非科学计数法数据

    oracle 自定义函数: CREATE OR REPLACE FUNCTION ConvertNumeric(rawData VARCHAR2) --用于返回转换科学计算法dhx RETURN VA ...