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. Angular——tab切换案例

    基本介绍 angular框架下的tab切换,相比较于之前的纯js写的代码,有一个很大的特点就是以数据为驱动,基本上不用搜索dom元素就可以实现效果 基本使用 (1)导航部分使用的是的状态使用的是ng- ...

  2. JS——行内式注册事件

    html中行内调用function的时候,是通过window调用的function,所以打印this等于打印window,所以在使用行内注册事件时务必传入参数this <!DOCTYPE htm ...

  3. [Windows Server 2008] IIS自带FTP配置方法

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

  4. dnn 添加图片

    public string fileUpload()         {             if (fuPhoto.PostedFile != null && fuPhoto.P ...

  5. vs Could Not Connect

    解决,   在win7上卸载IIS 10.0 Express ,安装 IIS7.5 Express

  6. cocos creator destroy方法

    node.destroy(),Node.destroyAllChildren并不会立即销毁,实际销毁操作会延迟到当前帧渲染前执行. 这段话可能不明白,但是在Node.destroyAllChildre ...

  7. 哈夫曼树(Huffman Tree)

    Date:2019-06-21 14:42:04 做题时更多的是用到哈夫曼树的构造思想,即按照问题规模从小到大,依次解决问题,可以得到最优解 Description: 在一个果园里,多多已经将所有的果 ...

  8. [JS]window.location获取url各项参数详解

    window.location方法后还还可以带href,search等参数,下面我们来看看获取url各项参数的办法. URL即:统一资源定位符 (Uniform Resource Locator, U ...

  9. CentOS7下安装ELK三件套

    ELK用于分布式收集,然后elasticsearch用于分析数据,在Kibana中可以查看数据.报表. 目前公司日志数据量暂时不使用elasticsearch集群,只是用的elasticsearch单 ...

  10. PAT 1101 Quick Sort

    There is a classical process named partition in the famous quick sort algorithm. In this process we ...