题意  给出一段初始化全为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. 【C#复习总结】多线程编程

    1 基本概念 前一篇文章做了铺垫,详见:http://www.cnblogs.com/mhq-martin/p/9035640.html 2 多线程 多线程的优点:可以同时完成多个任务:可以使程序的响 ...

  2. Redis中单机数据库的实现

    1. 内存操作层 zmalloc 系接口 redis为了优化内存操作, 封装了一层内存操作接口. 默认情况下, 其底层实现就是最简朴的libc中的malloc系列接口. 如果有定制化需求, 可以通过配 ...

  3. IIS6下使用多域名和通配符证书

    由于SSL协议,在完成握手以前,都只能采用IP地址通信方式,没有办法获取访问地址中的域名信息,所以针对每个IP地址的每个端口,服务器只能返回相同的一张证书.如果要实现多个不同域名共享一个IP地址的缺省 ...

  4. flask异常处理

    对于异常,通常可以分为两类:一类是可以预知的异常,我们通常会用try...except....捕捉,第二类是未知的error,我们是无法预知的. try: code block except A: e ...

  5. 爬虫(三)之scrapy核心组件

    01-核心组件 ·五大核心组件的工作流程: 引擎(Scrapy) 用来处理整个系统的数据流处理, 触发事务(框架核心) 调度器(Scheduler) 用来接受引擎发过来的请求, 压入队列中, 并在引擎 ...

  6. Mysql权限操作、用户管理、密码操作

    Mysql的权限 mysql中存在4个控制权限的表,分别为user表,db表,tables_priv表,columns_priv表. mysql权限表的验证过程为: 先从user表中的Host,Use ...

  7. H5 58-网页的布局方式

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  8. PHP api接口和SQL数据库关联

    数据库表创建 服务器环境配置.连接 .操作.数据库 API接口  原则:

  9. 牛客练习赛38 D 题 出题人的手环 (离散化+树状数组求逆序对+前缀和)

    链接:https://ac.nowcoder.com/acm/contest/358/D来源:牛客网 出题人的手环 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 524288K,其他 ...

  10. python os模块详解

    一.Python os模块(Linux环境) 1.1 执行shell命令 os.system('cmd') 执行命令不保存结果 os.popen('command') 执行后返回结果,使用.read( ...