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 ...
随机推荐
- h5添加音乐
http://changziming.com/post-209.html 加入HTML代码,因为是绑定在每一页的右上方(或者其他位置),定位用了fixed,所以在页面底部/body之前加上html代码 ...
- PHP对URL设置
一.URL规则 1.默认是区分大小写的 2.如果我们不想区分大小写可以改配置文件 'URL_CASE_INSENSITIVE'=>true, //url不区分 ...
- 基于 Redis 数据累计的实现
需求:对上传文件进行统一编号,以 xxx-YYYYmmdd-000001为编码格式,其中YYYYmmdd为当天传的日期. 技术方案:redis,get,set,incr,expireAt即可实现. p ...
- yii2 安装
php版本必须是php5.4以上.记得配置php环境变量 1.下载https://github.com/yiisoft/yii2-app-advanced 2.php -r "readfil ...
- TDirectory.GetAttributes、TDirectory.SetAttributes获取和设置文件夹属性
使用函数: System.IOUtils.TDirectory.GetAttributes//获取属性 System.IOUtils.TDirectory.SetAttributes//设置属性 注: ...
- (转载)delphi 常用函数(数学)
delphi 常用函数(数学) Delphi中怎么将实数取整? floor 和 ceil 是 math unit 里的函数,使用前要先 Uses Math.trunc 和 round 是 system ...
- [转]iOS之浅谈纯代码控制UIViewController视图控制器跳转界面的几种方法
参考:http://www.mamicode.com/info-detail-469709.html 一.最普通的视图控制器UIViewContoller 一个普通的视图控制器一般只有模态跳转的功能( ...
- GPUImage 滤镜头文件
#import "GLProgram.h" // Base classes #import "GPUImageOpenGLESContext.h" #impor ...
- POJ 3267 The Cow Lexicon 简单DP
题目链接: http://poj.org/problem?id=3267 从后往前遍历,dp[i]表示第i个字符到最后一个字符删除的字符个数. 状态转移方程为: dp[i] = dp[i+1] + 1 ...
- [BZOJ 3530] [Sdoi2014] 数数 【AC自动机+DP】
题目链接:BZOJ - 3530 题目分析 明显是 AC自动机+DP,外加数位统计. WZY 神犇出的良心省选题,然而去年我太弱..比现在还要弱得多.. 其实现在做这道题,我自己也没想出完整解法.. ...