HDU1698(线段树入门题)
Time Limit:2000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u
Description
Let us number the consecutive metallic sticks of the hook from 1 to N. For each operation, Pudge can change the consecutive metallic sticks, numbered from X to Y, into cupreous sticks, silver sticks or golden sticks. 
The total value of the hook is calculated as the sum of values of N metallic sticks. More precisely, the value for each kind of stick is calculated as follows:
For each cupreous stick, the value is 1. 
For each silver stick, the value is 2. 
For each golden stick, the value is 3.
Pudge wants to know the total value of the hook after performing the operations. 
You may consider the original hook is made up of cupreous sticks. 
Input
For each case, the first line contains an integer N, 1<=N<=100,000, which is the number of the sticks of Pudge’s meat hook and the second line contains an integer Q, 0<=Q<=100,000, which is the number of the operations.
Next Q lines, each line contains three integers X, Y, 1<=X<=Y<=N, Z, 1<=Z<=3, which defines an operation: change the sticks numbered from X to Y into the metal kind Z, where Z=1 represents the cupreous kind, Z=2 represents the silver kind and Z=3 represents the golden kind.
Output
Sample Input
Sample Output
#include"cstdio"
#include"cstring"
using namespace std;
const int MAXN=;
struct Node{
int l,r;
int lazy,sum;
}a[MAXN*]; void build(int rt,int l,int r)
{
a[rt].l=l;
a[rt].r=r;
a[rt].lazy=;
if(l==r){
a[rt].sum=;
return ;
}
int mid=(l+r)>>;
build(rt<<,l,mid);
build((rt<<)|,mid+,r);
a[rt].sum=a[rt<<].sum+a[(rt<<)|].sum;
} void PushDown(int rt)
{
int mid=(a[rt].l+a[rt].r)>>;
a[rt<<].lazy=a[(rt<<)|].lazy=a[rt].lazy;
a[rt<<].sum=a[rt].lazy*(mid-a[rt].l+);
a[(rt<<)|].sum=a[rt].lazy*(a[rt].r-mid);
a[rt].lazy=;
} void update(int rt,int l,int r,int val)
{
if(a[rt].l==l&&a[rt].r==r)
{
a[rt].lazy=val;
a[rt].sum=val*(r-l+);
return ;
} if(a[rt].lazy) PushDown(rt); int mid=(a[rt].l+a[rt].r)>>;
if(r<=mid) update(rt<<,l,r,val);
else if(mid<l) update((rt<<)|,l,r,val);
else{
update(rt<<,l,mid,val);
update((rt<<)|,mid+,r,val);
}
a[rt].sum=a[rt<<].sum+a[(rt<<)|].sum;
} int main()
{
int T;
scanf("%d",&T);
for(int cas=;cas<=T;cas++)
{
int n;
scanf("%d",&n);
build(,,n);
int m;
scanf("%d",&m);
while(m--)
{
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 %d.\n",cas,a[].sum);
}
return ;
}
HDU1698(线段树入门题)的更多相关文章
- hdu 1166敌兵布阵(线段树入门题)
		
>>点击进入原题测试<< 思路:这两天在学线段树,这个题直接手敲一下线段树就行了,都没有用上懒人标记.入门题 cin,cout会超时,记得加std::ios::sync_wit ...
 - [poj2104]可持久化线段树入门题(主席树)
		
解题关键:离线求区间第k小,主席树的经典裸题: 对主席树的理解:主席树维护的是一段序列中某个数字出现的次数,所以需要预先离散化,最好使用vector的erase和unique函数,很方便:如果求整段序 ...
 - 几道简单的线段树入门题 POJ3264&&POJ3468&&POJ2777
		
Balanced Lineup Time Limit: 5000MS Memory Limit: 65536K Total Submissions: 40687 Accepted: 19137 ...
 - HDU1698 线段树入门之区间修改/查询(lazy标记法)
		
Just a Hook Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total ...
 - hiho1079 - 数据结构 线段树(入门题,离散化)
		
题目链接 描述 小Hi和小Ho在回国之后,重新过起了朝7晚5的学生生活,当然了,他们还是在一直学习着各种算法~ 这天小Hi和小Ho所在的学校举办社团文化节,各大社团都在宣传栏上贴起了海报,但是贴来贴去 ...
 - Mosaic  HDU 4819 二维线段树入门题
		
Mosaic Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 102400/102400 K (Java/Others)Total S ...
 - A Simple Problem with Integers(线段树入门题)
		
Description You have N integers, A1, A2, ... , AN. You need to deal with two kinds of operations. On ...
 - POJ3264(线段树入门题)
		
Balanced LineupCrawling in process... Crawling failed Time Limit:5000MS Memory Limit:65536KB ...
 - hiho1080 - 数据结构 线段树(入门题,两个lazy tag)
		
题目链接 维护区间和,两个操作:一个是将某个区间设置成一个值,一个是将某个区间增加一个固定值 /**************************************************** ...
 
随机推荐
- Unable to determine IP address from host name
 - 【python】-- MySQL简介、安装、操作
			
MySQL简介.安装.操作 数据库(Database)是按照数据结构来组织.存储和管理数据的仓库,每个数据库都有一个或多个不同的API用于创建,访问,管理,搜索和复制所保存的数据.我们也可以将数据存储 ...
 - js面对对象编程
			
说到js,非常大一部分人会说我非常熟悉,在日常的web开发中经经常使用,那么你的js代码是符合面对对象思路的吗?那你会问我面向过程的js代码有什么不好吗?我的感受是面对对象的js编码更加简洁,降低了混 ...
 - test_bdc
			
[转]REPORT zbdc_test_by_shir. * 定义个BDC格式的内表**************************************************DATA : B ...
 - Spring之AOP由浅入深(转发:https://www.cnblogs.com/zhaozihan/p/5953063.html)
			
1.AOP的作用 在OOP中,正是这种分散在各处且与对象核心功能无关的代码(横切代码)的存在,使得模块复用难度增加.AOP则将封装好的对象剖开,找出其中对多个对象产生影响的公共行为,并将其封装为一个可 ...
 - Linux shell join命令详解
			
Linux join命令 2012-02-09 17:49:00| 分类: SHELL | 标签:linux join 文件连接 |字号 订阅join命令 功能:“将两个文件里指定栏位同样的行连接起来 ...
 - STM32 ~ 串口DMA通道查找
			
STM32F4XX: /**************************************************************************************** ...
 - height()、innerHeight()、outerHeight()函数的区别详解
			
具体参考博客:http://www.365mini.com/page/jquery-height-vs-innerheight-vs-outerheight.htm
 - 使用JavaScript定义一个微信小程序插件样例
			
var wxTimer = new wxTimer({ beginTime: "00:00:20", complete: function () { wx.redirectTo({ ...
 - 关于scrollLeft的获取在不同浏览器或相同浏览器的不同版本下的获取
			
chrome61向w3c规则靠拢,document.body.scrollLeft获取的值一直为0,需要使用document.documentElement.scrollLeft(或document. ...