Problem Description
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.

 
Input
The 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.
 
Output
For 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

11021 5 25 9 3
 
 Sample Output

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

思路:

区间覆盖,还是用lazy标签,没看到最后一个句点疯狂WA

代码:

#include<queue>
#include<cstring>
#include<set>
#include<map>
#include<vector>
#include<iostream>
#include<algorithm>
#define ll long long
const int N=100005;
const int MOD=20071027;
using namespace std;
int node[N<<2],lazy[N<<2];
void push_down(int rt,int l,int r){
int m=(l+r)/2;
if(lazy[rt]!=-1){
node[rt<<1]=lazy[rt]*(m-l+1);
node[rt<<1|1]=lazy[rt]*(r-(m+1)+1);
lazy[rt<<1]=lazy[rt<<1|1]=lazy[rt];
lazy[rt]=-1;
}
}
void update(int rt,int l,int r,int L,int R,int v){ //l r搜索区间
if(L<=l && R>=r){
node[rt]=v*(r-l+1);
lazy[rt]=v;
return;
}
push_down(rt,l,r);
int m=(l+r)/2;
node[rt]=0;
if(L<=m){
update(rt<<1,l,m,L,R,v);
}
if(R>m){
update(rt<<1|1,m+1,r,L,R,v);
}
node[rt]+=node[rt<<1]+node[rt<<1|1];
} int main(){
int n,q,a,b,c,T,num=1;
scanf("%d",&T);
while(T--){
scanf("%d",&n);
memset(node,-1,sizeof(node));
int len=n<<2;
for(int i=0;i<len;i++){
lazy[i]=1;
}
scanf("%d",&q);
node[1]=n;
while(q--){
scanf("%d%d%d",&a,&b,&c);
update(1,1,n,a,b,c);
}
printf("Case %d: The total value of the hook is %d.\n",num++,node[1]); }
return 0;
}

HDU1698 Just a Hook(线段树&区间覆盖)题解的更多相关文章

  1. 【原创】hdu1698 Just a Hook(线段树→区间更新,区间查询)

    学习线段树第二天,这道题属于第二简单的线段树,第一简单是单点更新,这个属于区间更新. 区间更新就是lazy思想,我来按照自己浅薄的理解谈谈lazy思想: 就是在数据结构中,树形结构可以线性存储(线性表 ...

  2. hdu1698 Just a hook 线段树区间更新

    题解: 和hdu1166敌兵布阵不同的是 这道题需要区间更新(成段更新). 单点更新不用说了比较简单,区间更新的话,如果每次都更新到底的话,有点费时间. 这里就体现了线段树的另一个重要思想:延迟标记. ...

  3. HDU1698 Just a Hook —— 线段树 区间染色

    题目链接:https://vjudge.net/problem/HDU-1698 In the game of DotA, Pudge’s meat hook is actually the most ...

  4. hdu1698 Just a Hook (线段树区间更新 懒惰标记)

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

  5. hdu-------(1698)Just a Hook(线段树区间更新)

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

  6. HDU 4509 湫湫系列故事——减肥记II(线段树-区间覆盖 或者 暴力技巧)

    http://acm.hdu.edu.cn/showproblem.php?pid=4509 题目大意: 中文意义,应该能懂. 解题思路: 因为题目给的时间是一天24小时,而且还有分钟.为了解题方便, ...

  7. HDU 1698 Just a Hook(线段树 区间替换)

    Just a Hook [题目链接]Just a Hook [题目类型]线段树 区间替换 &题解: 线段树 区间替换 和区间求和 模板题 只不过不需要查询 题里只问了全部区间的和,所以seg[ ...

  8. HDU.1689 Just a Hook (线段树 区间替换 区间总和)

    HDU.1689 Just a Hook (线段树 区间替换 区间总和) 题意分析 一开始叶子节点均为1,操作为将[L,R]区间全部替换成C,求总区间[1,N]和 线段树维护区间和 . 建树的时候初始 ...

  9. [NOI2015] 软件包管理器【树链剖分+线段树区间覆盖】

    Online Judge:Luogu-P2146 Label:树链剖分,线段树区间覆盖 题目大意 \(n\)个软件包(编号0~n-1),他们之间的依赖关系用一棵含\(n-1\)条边的树来描述.一共两种 ...

  10. Mayor's posters POJ - 2528 线段树区间覆盖

    //线段树区间覆盖 #include<cstdio> #include<cstring> #include<iostream> #include<algori ...

随机推荐

  1. 【编码备份】1.9从Excel中导入用户名进行测试,用户一次进入系统进行答题测试。

    # coding=utf-8 """ Created on 2017年7月31日 @author: candy """ from selen ...

  2. Laravel和thinkphp的区别/优缺点

    Laravel的设计思想是很先进的,非常适合应用各种开发模式TDD, DDD和BDD,作为使用者最多的php框架,它为你准备好了一切,composer是个php的未来.laravel最大的特点和处优秀 ...

  3. sql批量修改wordpress网站的文章发布状态

    wordpress批量导入文章的时候,有些文章的状态可能会缺失,例如“mis scheduled”.draft.future等几种状态,如何用sql批量修改wordpress网站的文章发布状态呢? 点 ...

  4. java计算器 图形用户界面 升级版 v1.02

    package com.rgy.entity; import java.awt.BorderLayout; import java.awt.Font; import java.awt.GridLayo ...

  5. 十天精通CSS3(11)

    Media Queries——媒体类型(一) 随着科学技术不断的向前发展,网页的浏览终端越来越多样化,用户可以通过:宽屏电视.台式电脑.笔记本电脑.平板电脑和智能手机来访问你的网站.尽管你无法保证一个 ...

  6. [py]python自省工具

    参考 在日常生活中,自省(introspection)是一种自我检查行为.自省是指对某人自身思想.情绪.动机和行为的检查.伟大的哲学家苏格拉底将生命中的大部分时间用于自我检查,并鼓励他的雅典朋友们也这 ...

  7. PHP中header('content-type:text/html;charset="utf-8')和error_reporting()的作用

    1.header PHP文件插入header("Content-type: text/html; charset=utf-8");相当于页面里面的<meta http-equ ...

  8. django的分页器

    Django中分页器的使用 django分页器模块 #分页器 from django.core.paginator import Paginator,EmptyPage,PageNotAnIntege ...

  9. Object之clone

    一.Object类中clone的实现. 二.clone详解. 看,clone()方法又是一个被声明为native的方法,因此,我们知道了clone()方法并不是Java的原生方法,具体的实现是有C/C ...

  10. fontawesome与amazeUI

    fontawesome是很不错的东西呢~~~~ amazeUI也是很不错的东西呢~~~~~ 最近一年里,比较偏爱这两个家伙? 什么?为什么bootstrap?有什么区别? 这个我还真说不太清楚. 用一 ...