题意  给出一段初始化全为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 线段树区间修改区间和模版题的更多相关文章

  1. Just a Hook HDU - 1698Just a Hook HDU - 1698 线段树区间替换

    #include<cstdio> #include<cstring> #include<iostream> #include<algorithm> us ...

  2. I Hate It HDU - 1754 线段树 单点修改+区间最值

    #include<iostream> #include<cstring> using namespace std; ; int m,n,p; struct node{ int ...

  3. hdu 1166线段树 单点更新 区间求和

    敌兵布阵 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submis ...

  4. HDU 1698 线段树 区间更新求和

    一开始这条链子全都是1 #include<stdio.h> #include<string.h> #include<algorithm> #include<m ...

  5. HDU 1698 <线段树,区间set>

    题目连接 题意: 一条长为N的铜链子,每个结点的价值为1.有两种修改,l,r,z; z=2:表示把[l,r]区间内链子改为银质,价值为2. z=3:表示把[l,r]区间内链子改为金质,价值为3. 思路 ...

  6. Hdu 1698(线段树 区间修改 区间查询)

    In the game of DotA, Pudge's meat hook is actually the most horrible thing for most of the heroes. T ...

  7. HDU - 1698 线段树区间修改,区间查询

    这就是很简单的基本的线段树的基本操作,区间修改,区间查询,对区间内部信息打上laze标记,然后维护即可. 我自己做的时候太傻逼了...把区间修改写错了,对给定区间进行修改的时候,mid取的是节点的左右 ...

  8. hdu 1698 线段树(成段替换 区间求和)

    一条钩子由许多小钩子组成 更新一段小钩子 变成铜银金 价值分别变成1 2 3 输出最后的总价值 Sample Input11021 5 25 9 3 Sample OutputCase 1: The ...

  9. hdu 1698 线段树 区间更新 区间求和

    Just a Hook Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total ...

随机推荐

  1. 阻止form表单中的input按下回车时提交表单

    给form加属性:onsubmit="return false;"

  2. [LeetCode] 56 - Merge Intervals 合并区间

    Given a collection of intervals, merge all overlapping intervals. For example,Given [1,3],[2,6],[8,1 ...

  3. P1525 关押罪犯

    基础并查集-- #include<iostream> #include<string.h> #include<algorithm> #include<stdi ...

  4. vue的高阶组件

    探索Vue高阶组件 探索Vue高阶组件的使用 Vue高阶组件的使用方法 高阶组件应用-组件重新实例化 深入理解React 高阶组件 探索Vue高阶组件 2018-01-05 探索Vue高阶组件 Vue ...

  5. gnuplot画折线图

    之前尝试用jfreechart画自定义横坐标的折线图或时序图,发现很复杂,后来改用gnuplot了. gnuplot在网上一搜就能找到下载地址. 安装完成后,主要是命令行形式的交互界面,至少比jfre ...

  6. 敏捷与CMM的恩怨

    模式不同,一种是灵活,一种是严肃.

  7. asp.net mvc或者其他程序无法打开excel——解决方案,C#处理Excel文件

    问题描述:今天处理Excel时遇到一个问题,本地使用Microsoft.Jet.OLEDB.4.0处理,正常完成了需求, 上传到服务器后发生了异常,通过排查发现问题出现在对Excel文件的读取上,然后 ...

  8. c# winform导出Excel

    //需要注意添加引用Microsoft.Office.Interop.Excel.dll string fileName =DateTime.Now.Year+ DateTime.Now.Month+ ...

  9. [转帖] SS, SP, BP 三个寄存器

    SS, SP, BP 三个寄存器 https://blog.csdn.net/vspiders/article/details/55669265 这么看 计算机组成原理 还有 考试的很多题目非常有用啊 ...

  10. AngularJS集合数据遍历显示

    AngularJS集合数据遍历显示 <!DOCTYPE html> <html> <head> <meta charset="UTF-8" ...