hdu 1698(线段树区间更新)
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
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 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.
each case, print a number in a line representing the total value of the
hook after the operations. Use the format in the example.
#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(线段树区间更新)的更多相关文章
- HDU 1698 线段树 区间更新求和
一开始这条链子全都是1 #include<stdio.h> #include<string.h> #include<algorithm> #include<m ...
- hdu 1698 线段树 区间更新 区间求和
Just a Hook Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total ...
- HDU(1698),线段树区间更新
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1698 区间更新重点在于懒惰标记. 当你更新的区间就是整个区间的时候,直接sum[rt] = c*(r- ...
- HDU 1698 (线段树 区间更新) Just a Hook
有m个操作,每个操作 X Y Z是将区间[X, Y]中的所有的数全部变为Z,最后询问整个区间所有数之和是多少. 区间更新有一个懒惰标记,set[o] = v,表示这个区间所有的数都是v,只有这个区间被 ...
- E - Just a Hook HDU - 1698 线段树区间修改区间和模版题
题意 给出一段初始化全为1的区间 后面可以一段一段更改成 1 或 2 或3 问最后整段区间的和是多少 思路:标准线段树区间和模版题 #include<cstdio> #include& ...
- HDU - 1698 线段树区间修改,区间查询
这就是很简单的基本的线段树的基本操作,区间修改,区间查询,对区间内部信息打上laze标记,然后维护即可. 我自己做的时候太傻逼了...把区间修改写错了,对给定区间进行修改的时候,mid取的是节点的左右 ...
- Hdu 1698(线段树 区间修改 区间查询)
In the game of DotA, Pudge's meat hook is actually the most horrible thing for most of the heroes. T ...
- HDU 3016 线段树区间更新+spfa
Man Down Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Su ...
- hdu 1698 线段树 区间修改
#include <cstdio> #include <cstdlib> #include <cmath> #include <map> #includ ...
- Just a Hook HDU - 1698Just a Hook HDU - 1698 线段树区间替换
#include<cstdio> #include<cstring> #include<iostream> #include<algorithm> us ...
随机推荐
- Java jre7及以上版本中的switch支持String的实现细节
Java7中的switch支持String的实现细节 作者: zsxwing 更新: 2013-03-04 21:08:02 发布: 2012-04-26 13:58:19 在Java7之前,swit ...
- Core 项目下使用SQl语句
public static DataTable ExeQuery(string connectionString, CommandType cmdType, string cmdText) { usi ...
- 使用Hexo搭建个人博客配置全过程
大致过程分为: 1.搭建Node.js 环境 2. 搭建Git 环境 3.安装配置Hexo 4.GitHub 注册和配置 5. 关联Hexo 与 GitHub Pages 7.Hexo的常用操作 下面 ...
- 扩增子分析QIIME2-4分析实战Moving Pictures
本示例的的数据来自文章<Moving pictures of the human microbiome>,Genome Biology 2011,取样来自两个人身体四个部位五个时间点 ...
- AcGePoint3d ads_point 转换
AcGePoint3d (AcGePoint2d )转换 ads_point 用:asDblArray函数. ads_point 转换AcGePoint2d 用asPnt2d(const doubl ...
- Array.prototype.slice.call()的理解
最近在看廖雪峰的JS课程,浏览器中的操作DOM的那一章,有这样一道题. JavaScript Swift HTML ANSI C CSS DirectX <!-- HTML结构 --> & ...
- Sort HDU5884(二分+多叉哈夫曼树)
HDU5884 Sort 题意:有n个序列要进行归并,每次归并的代价是两个序列的长度的和,要求最终的代价不能超过规定的T,求在此前提下一次能同时进行归并的序列的个数k. 思路:还是太单纯,看完题目一直 ...
- protel99se 问题汇总(不定期更新)
1.在PROTEL99SE中,怎样改变敷铜的线宽? 规则---manufacturing----polygon connect style 里面设置:或Power polygon connect st ...
- 用Twebbrowser做可控编辑器与MSHTML
首先要明白mshtml的属性方法: {IHTMLDocument2 方法:} write //写入 writeln //写入并换行 open //打开一个流,以收集 document.write 或 ...
- 更简单高效的HTML数据提取-Xpath
XPath 是一门在 XML 文档中查找信息的语言.XPath 用于在 XML 文档中通过元素和属性进行导航. 相比于BeautifulSoup,Xpath在提取数据时会更加的方便. 安装 在Pyth ...