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. pig报错

    pig failed to read data from....... 错误可能1:load data的目录不在,或者引用出错,load data '/in/train'这里的红色/应该去掉,因为默认 ...

  2. 翻译 | 玩转 React 表单 —— 受控组件详解

    原文地址:React.js Forms: Controlled Components 原文作者:Loren Stewart 译者:小 B0Y 校对者:珂珂君 本文涵盖以下受控组件: 文本输入框 数字输 ...

  3. 初次就这么给了你(Django-rest-framework)

    Django-Rest-Framework Django-Rest框架是构建Web API强大而灵活的工具包. 简单粗暴,直奔主题. pip install django pip install dj ...

  4. 实例讲解js正则表达式的使用

    前言:正则表达式(regular expression)反反复复学了多次,学了又忘,忘了又学,这次打算把基本的东西都整理出来,加强记忆,也方便下次查询. 学习正则表达式之前首先需要掌握记忆这些基本概念 ...

  5. 【转】Mapreduce部署与第三方依赖包管理

    Mapreduce部署是总会涉及到第三方包依赖问题,这些第三方包配置的方式不同,会对mapreduce的部署便捷性有一些影响,有时候还会导致脚本出错.本文介绍几种常用的配置方式: 1. HADOOP_ ...

  6. poj2891非互质同余方程

    Strange Way to Express Integers Time Limit: 1000MS   Memory Limit: 131072K Total Submissions: 8176   ...

  7. 最长上升子序列 LIS(Longest Increasing Subsequence)

    引出: 问题描述:给出一个序列a1,a2,a3,a4,a5,a6,a7….an,求它的一个子序列(设为s1,s2,…sn),使得这个子序列满足这样的性质,s1<s2<s3<…< ...

  8. Jquery实现弹出选择框选择后返回,支持多级分类

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/ ...

  9. Sql语句构造类,多字段新增或修改时,拼装sql语句比较方便

    using System; using System.Collections.Generic; using System.Text; namespace MSCL { #region 使用示例 /* ...

  10. Hadoop通过HCatalog编写Mapreduce任务访问hive库中schema数据

    1.dirver package com.kangaroo.hadoop.drive; import java.util.Map; import java.util.Properties; impor ...