In the game of DotA, Pudge’s meat hook is actually the most horrible thing for most of the heroes. The hook is made up of several consecutive metallic sticks which are of the same length.

(图片走丢了,真不好意思,要不我补一张?) (对就是这张图)

Now Pudge wants to do some operations on the hook.

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. 

InputThe input consists of several test cases. The first line of the input is the number of the cases. There are no more than 10 cases. 
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. 
OutputFor each case, print a number in a line representing the total value of the hook after the operations. Use the format in the example. 
Sample Input

1
10
2
1 5 2
5 9 3

Sample Output

Case 1: The total value of the hook is 24.

题意:有一个长度为n的钩子,钩子由金银铜三种棒子组成,所以问题来了:骚年,这是你的金棒子,还是你的银棒子,咳咳,扯远了,现在有个浪到飞起的男人,他能将一段的不管曾经是怎样的棒子全部改成自己想要的棒子.好的,现在已知金棒子价值为3,银为2,铜为1.
求修改完以后整个钩子的价值. 再多练几道线段树吧...不过这道题没强制在线,似乎可以搞些别的东东?当我没说....反正就打线段树吧...
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#define N 100000
#define lson root<<1
#define rson root<<1|1
using namespace std; int node[N<<],lazy[N<<]; void pushup(int root)
{
node[root]=node[lson]+node[rson];
} void pushdown(int root,int val)
{
if(lazy[root]!=-)
{
lazy[lson]=lazy[root];
lazy[rson]=lazy[root];
node[lson]=(val-(val>>))*lazy[root];
node[rson]=(val>>)*lazy[root];
lazy[root]=-;
}
} void build(int l,int r,int root)
{
lazy[root]=-;
node[root]=;
if(l==r)
{
return;
}
int mid=(l+r)>>;
build(l,mid,lson);
build(mid+,r,rson);
pushup(root);
} void update(int left,int right,int val,int l,int r,int root)
{
if(left<=l&&right>=r)
{
lazy[root]=val;
node[root]=val*(r-l+);
return;
}
pushdown(root,r-l+);
int mid=(l+r)>>;
if(left<=mid)
{
update(left,right,val,l,mid,lson);
}
if(mid<right)
{
update(left,right,val,mid+,r,rson);
}
pushup(root);
} int main()
{
int ttt=,t;
scanf("%d",&t);
while(t--)
{
int n,m;
scanf("%d%d",&n,&m);
build(,n,); for(int i=;i<=m;i++)
{
int ll,rr,ww;
scanf("%d%d%d",&ll,&rr,&ww);
update(ll,rr,ww,,n,);
}
printf("Case %d: The total value of the hook is %d.\n",++ttt,node[]);
}
}

每天刷题,身体棒棒!

Hdu 1698(线段树 区间修改 区间查询)的更多相关文章

  1. E - Just a Hook HDU - 1698 线段树区间修改区间和模版题

    题意  给出一段初始化全为1的区间  后面可以一段一段更改成 1 或 2 或3 问最后整段区间的和是多少 思路:标准线段树区间和模版题 #include<cstdio> #include& ...

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

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

  3. hdu 1698 线段树 区间修改

    #include <cstdio> #include <cstdlib> #include <cmath> #include <map> #includ ...

  4. [线段树]区间修改&区间查询问题

    区间修改&区间查询问题 [引言]信息学奥赛中常见有区间操作问题,这种类型的题目一般数据规模极大,无法用简单的模拟通过,因此本篇论文将讨论关于可以实现区间修改和区间查询的一部分算法的优越与否. ...

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

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

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

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

  7. SPOJ GSS2 - Can you answer these queries II(线段树 区间修改+区间查询)(后缀和)

    GSS2 - Can you answer these queries II #tree Being a completist and a simplist, kid Yang Zhe cannot ...

  8. SPOJ BGSHOOT - Shoot and kill (线段树 区间修改 区间查询)

    BGSHOOT - Shoot and kill no tags  The problem is about Mr.BG who is a great hunter. Today he has gon ...

  9. HDU(1698),线段树区间更新

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1698 区间更新重点在于懒惰标记. 当你更新的区间就是整个区间的时候,直接sum[rt] = c*(r- ...

随机推荐

  1. Unitty 3D 贪吃蛇 今日小记 -- 碰撞

    当蛇头碰撞到蛋的时候  应该让蛋消失并且重新创建蛋. void OnTriggerEnter    可以使用这个方法 下面附有这个方法的介绍 其次需要对挂载在之上的Object  check IsTr ...

  2. Linux的硬盘使用情况、挂载、SSD挂载(查看df -h不能看到的卷)

    linux上的盘和window的有区别,磁盘空间必须挂载在目录上,要不然没用 对与新增的硬盘.SSD固态硬盘.挂载到linux上的操作如下: df -h      #显示目前在Linux系统上的文件系 ...

  3. javaWeb正则表达式

    对于web来说,字符串的处理特别重要,而正则表达式是对字符串处理的利器,在字符过滤,验证方面都能看到她的身影. 今天需要处理一段json字符串,在用String.replaceAll的过程中,遇到了正 ...

  4. servlet文件上传2——复合表单提交(数据获取和文件上传)

    上传文件时表单enctype属性必须要更改为<enctype='multipart/form-data'>:采用post提交表单,元素需要有name属性: 利用第三方jar包(common ...

  5. C语言编程练习(一)

    问题一: 问题描述:输入n个数,n<=100,找到其中最小的数和最大的数 输入样例: 4                      1 2 3 4 输出样例:14 #include " ...

  6. Linux 独立安装subversion-1.8.18

    一.所需软件包 1.apr-1.4.6.tar.gz 下载地址:http://apr.apache.org/   2.apr-util-1.4.1.tar.gz 下载地址:http://apr.apa ...

  7. 学习如何看懂SQL Server执行计划(三)——连接查询篇

    三.连接查询部分 --------------------嵌套循环-------------------- /* UserInfo表数据少.Coupon表数据多嵌套循环可以理解为就是两层For循环,外 ...

  8. Python实战之网络编程socket学习笔记及简单练习

    sk = socket.socket(socket.AF_INET,socket.SOCK_STREAM,0) 参数一:地址簇 socket.AF_INET IPv4(默认) socket.AF_IN ...

  9. zoj3954 详细讲解 排序比较单词法

    Seven-Segment Display Time Limit: 1 Second      Memory Limit:65536 KB A seven segment display, or se ...

  10. kazoo python zookeeper 选主

    本文讲述基于zookeeper选主与故障切换的方法.我们的例子使用的是python. 使用的库是kazoo,安装方式 pip install kazoo  应用场景: 多个实例部署,但不是" ...