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. 前端开发之旅- 移动端HTML5实现文件上传

    一. 在一个客户的webapp项目中需要用到 html5调用手机摄像头,找了很多资料,大都是 js调用api  然后怎样怎样,做了几个demo测试发现根本不行, 后来恍然大悟,用html5自带的 in ...

  2. Cannot resolve symbol R

    最近遇到一个奇怪的问题,在Android build 完版本后,将app 删除后,直接出现 Cannot resolve symbol R , Clean. ReBuild 等试过都没效果. 最终解决 ...

  3. JS——样式获取的兼容写法

    样式获取 普通获取属性方式div.style.width或者div.style["width"]无法获取内嵌和外链式,只能获取行内式 window.getComputedStyle ...

  4. JS——arguments

    1.只在函数中使用 2.返回的是实参的数组 <script> getNum(1, 2);//(2) [1, 2, callee: ƒ, Symbol(Symbol.iterator): ƒ ...

  5. win10系统安装postgresql后无法连接

    win10系统安装postgresql后在系统服务列表中找不到,连接不上数据库. 可以尝试关闭系统防火墙后重启电脑或者重装程序.

  6. 2.1 Java开发工具包

        Java专业术语                   术语名   缩写                                                             ...

  7. 9.3.4 BeaufitulSoup4

    BeautifulSoup 是一个非常优秀的Python扩展库,可以用来从HTML或XML文件中提取我们感兴趣的数据,并且允许指定使用不同的解析器. 使用 pip install BeaufifulS ...

  8. hdu 4971 多校10最大权闭合图

    /* 很明显的最大权闭合图题 */ #include<stdio.h> #include<string.h> #include<queue> using names ...

  9. 对SHH的公钥和私钥的简单理解

    SSH是在应用层和传输层基础上的安全协议 SSH提供了两种级别的安全验证: 第一基于密码的安全验证:账号.密码,但可能有别的服务器冒充真正的服务器,无法避免被“中间人”攻击(man-in-the-mi ...

  10. FORTIFY_SOURCE

    In recent years Linux distributions started treating security more seriously. Out of many security f ...