Just a Hook

Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 30080    Accepted Submission(s): 14859

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
1
10
2
1 5 2
5 9 3
Sample Output
Case 1: The total value of the hook is 24.
Source
区间更新
 #include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<queue>
#include<map>
#include<set>
#include<vector>
#include<cstdlib>
#include<string>
#define eps 0.000000001
typedef long long ll;
typedef unsigned long long LL;
using namespace std;
const int N=+;
struct node{
int l,r;
int val;
}tree[N*];
int flag[N*];
void pushup(int pos){
tree[pos].val=tree[pos<<].val+tree[pos<<|].val;
}
void build(int l,int r,int pos){
tree[pos].l=l;
tree[pos].r=r;
tree[pos].val=;
flag[pos]=;
if(tree[pos].l==tree[pos].r)return;
int mid=(tree[pos].l+tree[pos].r)>>;
build(l,mid,pos<<);
build(mid+,r,pos<<|);
//pushup(pos);
}
void update(int l,int r,int x,int pos){
if(tree[pos].l==l&&tree[pos].r==r){
tree[pos].val=x;
return;
}
if(tree[pos].val!=){
tree[pos<<].val=tree[pos].val;
tree[pos<<|].val=tree[pos].val;
tree[pos].val=;
}
int mid=(tree[pos].l+tree[pos].r)>>;
if(mid>=r)update(l,r,x,pos<<);
else if(mid<l)update(l,r,x,pos<<|);
else{
update(l,mid,x,pos<<);
update(mid+,r,x,pos<<|);
}
}
int query(int l,int r,int pos){
int mid=(tree[pos].l+tree[pos].r)>>;
if(tree[pos].l==l&&tree[pos].r==r){
if(tree[pos].val){
return tree[pos].val*(tree[pos].r-tree[pos].l+);
}
else{
return query(l,mid,pos<<)+query(mid+,r,pos<<|);
}
}
}
int main(){
int Case;
scanf("%d",&Case);
for(int k=;k<=Case;k++){
int m,n;
scanf("%d",&n);
build(,n,);
scanf("%d",&m);
int x,y,z;
while(m--){
scanf("%d%d%d",&x,&y,&z);
update(x,y,z,);
}
int ans=query(,n,);
printf("Case %d: The total value of the hook is %d.\n",k,ans); }
}

hdu 1698(线段树区间更新)的更多相关文章

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

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

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

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

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

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

  4. HDU 1698 (线段树 区间更新) Just a Hook

    有m个操作,每个操作 X Y Z是将区间[X, Y]中的所有的数全部变为Z,最后询问整个区间所有数之和是多少. 区间更新有一个懒惰标记,set[o] = v,表示这个区间所有的数都是v,只有这个区间被 ...

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

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

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

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

  7. Hdu 1698(线段树 区间修改 区间查询)

    In the game of DotA, Pudge's meat hook is actually the most horrible thing for most of the heroes. T ...

  8. HDU 3016 线段树区间更新+spfa

    Man Down Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Su ...

  9. hdu 1698 线段树 区间修改

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

  10. Just a Hook HDU - 1698Just a Hook HDU - 1698 线段树区间替换

    #include<cstdio> #include<cstring> #include<iostream> #include<algorithm> us ...

随机推荐

  1. Sql Server 优化 SQL 查询:如何写出高性能SQL语句

    1. 首先要搞明白什么叫执行计划? 执行计划是数据库根据SQL语句和相关表的统计信息作出的一个查询方案,这个方案是由查询优化器自动分析产生的,比如一条SQL语句如果用来从一个 10万条记录的表中查1条 ...

  2. [Windows Server 2008] 查看ASP详细错误信息方法

    ★ 欢迎来到[护卫神·V课堂],网站地址:http://v.huweishen.com ★ 护卫神·V课堂是护卫神旗下专业提供服务器教学视频的网站,每周更新视频. ★ 本节我们将带领大家:查看IIS下 ...

  3. HDU_3549_网络流(最大流)

    Flow Problem Time Limit: 5000/5000 MS (Java/Others)    Memory Limit: 65535/32768 K (Java/Others)Tota ...

  4. 删除Git服务器文件但是保留本地文件

    参考: https://blog.csdn.net/u012804886/article/details/83059315 https://www.cnblogs.com/wfsovereign/p/ ...

  5. linux最常用的快捷键

    1.ctrl+alt+T 调出命令行界面 2.alt+f4 关闭当前窗口

  6. SpringMVC与MyBatis整合方法

    一.springmvc+mybaits的系统架构: 第一步:整合dao层 mybatis和spring整合,通过spring管理mapper接口. 使用mapper的扫描器自动扫描mapper接口在s ...

  7. JS练习:显示和隐藏

    <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...

  8. linux安装openjdk

    使用yum查找jdk: yum search java | grep jdk 执行安装命令:yum install java-1.8.0-openjdk

  9. centos中安装tomcat

    1.先保证centos中安装了jre的环境. 2.上传tomcat的压缩包到root根目录. 3.切换到根目录 输入命令cd ~ , 然后 ll , 查看上传情况: 4.选中复制压缩文件,输入解压命令 ...

  10. PAT 1119 Pre- and Post-order Traversals

    Suppose that all the keys in a binary tree are distinct positive integers. A unique binary tree can ...