E - Just a Hook HDU - 1698 线段树区间修改区间和模版题
题意 给出一段初始化全为1的区间 后面可以一段一段更改成 1 或 2 或3 问最后整段区间的和是多少
思路:标准线段树区间和模版题
#include<cstdio>
#include<algorithm>
#include<set>
#include<vector>
#include<cstring>
#include<iostream>
using namespace std;
const int maxn=1e5+;
struct Node{
int l,r,sum;
int lazy;
void update(int val){
sum=(r-l+)*val;
lazy=val; }
}tree[maxn*];
void push_up(int x){
tree[x].sum=tree[x<<].sum+tree[x<<|].sum;
}
void push_down(int x){
if(tree[x].lazy!=){
tree[x<<].update(tree[x].lazy);
tree[x<<|].update(tree[x].lazy);
tree[x].lazy=;
}
}
void build(int x,int l,int r){
tree[x].l=l,tree[x].r=r;
tree[x].sum=tree[x].lazy=;
if(l==r){
tree[x].sum=;
}
else {
int mid=l+r>>;
build(x<<,l,mid);
build(x<<|,mid+,r);
push_down(x);
}
}
void update(int x,int l,int r,int c){
int L=tree[x].l,R=tree[x].r;
if(R<=r&&L>=l){
tree[x].update(c);
}
else {
int mid=L+R>>;
push_down(x);
if(mid>=l)update(x<<,l,r,c);
if(mid<r)update(x<<|,l,r,c);
push_up(x);
}
}
long long query(int x,int l,int r){
int L=tree[x].l,R=tree[x].r;
if(R<=r&&L>=l){
return tree[x].sum;
}
else {
int mid=L+R>>;
long long ans=;
//push_down(x);
if(mid>=l)ans+=query(x<<,l,r);
if(mid<r)ans+=query(x<<|,l,r);
return ans;
}
}
int main(){
int t,kase=;
scanf("%d",&t);
while(t--){
int n,q;
scanf("%d%d",&n,&q);
build(,,n);
for(int i=;i<q;i++){
int x,y,z;
scanf("%d%d%d",&x,&y,&z);
update(,x,y,z);
}
printf("Case %d: The total value of the hook is %lld.\n",kase++,query(,,n));
}
return ;
}
E - Just a Hook HDU - 1698 线段树区间修改区间和模版题的更多相关文章
- Just a Hook HDU - 1698Just a Hook HDU - 1698 线段树区间替换
#include<cstdio> #include<cstring> #include<iostream> #include<algorithm> us ...
- I Hate It HDU - 1754 线段树 单点修改+区间最值
#include<iostream> #include<cstring> using namespace std; ; int m,n,p; struct node{ int ...
- hdu 1166线段树 单点更新 区间求和
敌兵布阵 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submis ...
- HDU 1698 线段树 区间更新求和
一开始这条链子全都是1 #include<stdio.h> #include<string.h> #include<algorithm> #include<m ...
- HDU 1698 <线段树,区间set>
题目连接 题意: 一条长为N的铜链子,每个结点的价值为1.有两种修改,l,r,z; z=2:表示把[l,r]区间内链子改为银质,价值为2. z=3:表示把[l,r]区间内链子改为金质,价值为3. 思路 ...
- Hdu 1698(线段树 区间修改 区间查询)
In the game of DotA, Pudge's meat hook is actually the most horrible thing for most of the heroes. T ...
- HDU - 1698 线段树区间修改,区间查询
这就是很简单的基本的线段树的基本操作,区间修改,区间查询,对区间内部信息打上laze标记,然后维护即可. 我自己做的时候太傻逼了...把区间修改写错了,对给定区间进行修改的时候,mid取的是节点的左右 ...
- hdu 1698 线段树(成段替换 区间求和)
一条钩子由许多小钩子组成 更新一段小钩子 变成铜银金 价值分别变成1 2 3 输出最后的总价值 Sample Input11021 5 25 9 3 Sample OutputCase 1: The ...
- hdu 1698 线段树 区间更新 区间求和
Just a Hook Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total ...
随机推荐
- Python股票分析系列——数据整合.p7
欢迎来到Python for Finance教程系列的第7部分. 在之前的教程中,我们为整个标准普尔500强公司抓取了雅虎财经数据. 在本教程中,我们将把这些数据组合到一个DataFrame中. 到此 ...
- Python股票分析系列——数据整理和绘制.p2
该系列视频已经搬运至bilibili: 点击查看 欢迎来到Python for Finance教程系列的第2部分. 在本教程中,我们将利用我们的股票数据进一步分解一些基本的数据操作和可视化. 我们将要 ...
- WebApi集成Swagger
1.新建一个WebApi空项目 2.新建一个Person实体类: public class Person { public int ID { get; set; } public string Use ...
- 如何向微软 Docs 和本地化社区提交翻译贡献
Docs (docs.microsoft.com)是微软新版的文档网站,重新规划了各项技术栈的文档结构,看起来比 MSDN 可读性更好.虽然 Docs 提供了各种语言的版本,但大多是机器翻译,某些中文 ...
- java 浅克隆 深克隆
对象的克隆是java的一项高级技术,他可以根据给定的对象,获得与其完全相同的另一个对象. 1.浅克隆主要是复制对象的值 2.深克隆:当类存在聚合关系的时候,克隆就必须考虑聚合对象的克隆,可以复制引用类 ...
- BeautifulSoup库
'''灵活又方便的网页解析库,处理高效,支持多种解析器.利用它不用编写正则表达式即可方便的实现网页信息的提取.''' BeautifulSoup库包含的一些解析库: 解析库 使用方法 优势 劣势 py ...
- 大神教你Debian GNU/Linux 9.7 “Stretch” Live和安装镜像开放下载
Debian项目团队于昨天发布了Debian GNU/Linux 9 "Stretch" 的第7个维护版本更新,重点修复了APT软件管理器中存在的安全漏洞.在敦促每位用户尽快升级系 ...
- vue echarts 动态数据
安装echarts依赖 npm install echarts -S 或者使用国内的淘宝镜像: 安装 npm install -g cnpm --registry=https://registry.n ...
- 软件工程(FZU2015) 赛季得分榜,第9回合
SE_FZU目录:1 2 3 4 5 6 7 8 9 10 11 12 13 积分规则 积分制: 作业为10分制,练习为3分制:alpha30分: 团队项目分=团队得分+个人贡献分 个人贡献分: 个人 ...
- 配置nginx反向代理服务器,解决浏览器跨域调用接口的限制问题
配置nginx反向代理服务器,解决浏览器跨域调用接口的限制问题 - 大venn的博客 - CSDN博客https://blog.csdn.net/u011135260/article/details/ ...