hdu1698(线段树的区间替换)
#include <bits/stdc++.h> using namespace std; #define Maxn 1001000*4 struct Node{ int lt,rt,val; }A[Maxn]; int j = 1; void Build(int i,int lt,int rt){ A[i].lt = lt; A[i].rt = rt; A[i].val = 1; if( lt == rt ){ return ; } int mid = (lt+rt) >> 1; Build(i<<1,lt,mid); Build(i<<1|1,mid+1,rt); } void update(int i,int lt,int rt,int val){ if( A[i].val == val ){ return ; } if( A[i].lt == lt && A[i].rt == rt ){ A[i].val = val; return ; } if( A[i].val != -1 ){ A[i<<1].val = A[i<<1|1].val = A[i].val; A[i].val = -1; } if( rt <= A[i<<1].rt ){ update(i<<1,lt,rt,val); }else if( lt >= A[i<<1|1].lt ){ update(i<<1|1,lt,rt,val); }else{ update(i<<1,lt,A[i<<1].rt,val); update(i<<1|1,A[i<<1|1].lt,rt,val); } } int find(int i){ if( A[i].val != -1 ){ return ( (A[i].rt-A[i].lt+1)*A[i].val); }else{ return ( find(i<<1) + find(i<<1|1) ); } } int main(){ int T,N,a,b,c; cin >> T; while(T--){ scanf("%d",&N); Build(1,1,N); int n; scanf("%d",&n); while(n--){ scanf("%d%d%d",&a,&b,&c); update(1,a,b,c); } printf("Case %d: The total value of the hook is %d.\n",j++,find(1)); } }
hdu1698(线段树的区间替换)的更多相关文章
- hdu1698线段树的区间更新区间查询
Just a Hook Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Tota ...
- HDU1698 线段树(区间更新区间查询)
Just a Hook Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total S ...
- 1698-Just a Hook 线段树(区间替换)
Just a Hook Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total ...
- hdu1698 线段树(区间更新~将区间[x,y]的值替换为z)
Just a Hook Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total ...
- hdu1698 线段树区间更新
Just a Hook Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Tota ...
- Codeforces Round #222 (Div. 1) D. Developing Game 线段树有效区间合并
D. Developing Game Pavel is going to make a game of his dream. However, he knows that he can't mak ...
- hiho一下20周 线段树的区间修改
线段树的区间修改 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 对于小Ho表现出的对线段树的理解,小Hi表示挺满意的,但是满意就够了么?于是小Hi将问题改了改,又出给了 ...
- 2016年湖南省第十二届大学生计算机程序设计竞赛---Parenthesis(线段树求区间最值)
原题链接 http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1809 Description Bobo has a balanced parenthes ...
- poj 3468:A Simple Problem with Integers(线段树,区间修改求和)
A Simple Problem with Integers Time Limit: 5000MS Memory Limit: 131072K Total Submissions: 58269 ...
随机推荐
- Vcl.FileCtrl.SelectDirectory
描述:显示一个目录的对话框(属于Delphi) function SelectDirectory(var Directory: string; Options: TSelectDirOpts; Hel ...
- crontab没有正确重定向导致磁盘inode节点空间满
通常是发现磁盘没有满但是无法写入文件.提示“no space left on device” 用df -i 查看,应该会发现相应的分区是100% 一般都是crontab的job有问题,造成 ...
- .net source code
.NET 类库的强大让我们很轻松的解决常见问题,作为一个好专研的程序员,为了更上一层楼,研究CLR的基础类库实现是快速稳定的捷径. 一般场景下,采用 Reflector可以反射出.NET 的部分实现出 ...
- FFMPEG视音频编解码零基础学习方法-b
感谢大神分享,虽然现在还看不懂,留着大家一起看啦 PS:有不少人不清楚“FFmpeg”应该怎么读.它读作“ef ef em peg” 0. 背景知识 本章主要介绍一下FFMPEG都用在了哪里(在这里仅 ...
- Java Annotation手册
Java Annotation手册 作者:cleverpig(作者的Blog:http://blog.matrix.org.cn/page/cleverpig) 原文:http://www.matri ...
- CSAPP(深入理解计算机系统)读后感
9月到10月8号,包括国庆七天,大概每天5小时以上的时间,把Computer System: A Programmer Perspective 2rd version(深入理解计算机系统)的英文版啃完 ...
- 10款无限滚动自动翻页jquery插件
2012年3月29日 无限滚动自动翻页可以说是web2.0时代的一项堪称伟大的技术,它让我们在浏览页面的时候只需要把滚动条拉到网页底部就能自动显示下一页的 结果,改变了一直以来只能通过点击下一页来翻页 ...
- 导入旧版本Android项目时的“Unable to resolve target ‘android
在Ecplise + ATD + Android SDK的开发中,导入旧版本的Android项目时,往往会出现类似的如下错误 Error:Unable to resolve target 'andro ...
- centos网络安装中的注意点
转自centos网络安装中的注意点 centos网络安装的教程网上很多,这里仅仅记录一下安装过程中网上别处提及很少的注意点. 1.centos默认会安装selinux,并且默认阻止ftp服务,所以要禁 ...
- 设计模式之单例(singleton)设计模式代码详解
单例有两种:懒汉式和饿汉式 /** * 懒汉式的单例模式 * 这种单例模式如果采用到多线程调用该方法,有可能会产生多个实例,原因是: * 当线程一进入了①处,此时轮到线程二的时间片,线程二也来到①处, ...