HDU 1698 Just a Hook(线段树
Just a Hook
Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 42724 Accepted Submission(s): 20543
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.
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.
10
2
1 5 2
5 9 3
#include<bits/stdc++.h>
using namespace std;
const int maxn = 1e5+;
int n,sum;
struct node{
int l,r,s;
}t[maxn<<];
void build(int l,int r,int num){
t[num].l=l;
t[num].r=r;
t[num].s=;
if(l==r) return;
int mid=(l+r)>>;
build(l,mid,num<<);
build(mid+,r,num<<|);
} void update(int l,int r,int m ,int num){
if(t[num].s==m) return;
if(t[num].l==l&&t[num].r==r){
t[num].s=m;
return ;
}
if(t[num].s!=-){
t[num<<].s=t[num<<|].s=t[num].s;
t[num].s=-;
}
int mid=(t[num].l+t[num].r)>>;
if(l>mid) update(l,r,m,num<<|);
else if(r<=mid) update(l,r,m,num<<);
else {
update(l,mid,m,num<<);
update(mid+,r,m,num<<|);
}
} int query(int num){
if(t[num].s!=-){
return (t[num].r-t[num].l+)*t[num].s;
}else{
return query(num<<)+query(num<<|);
}
} int main(){
int x,y,z,T,k;
scanf("%d",&T);
int cas=;
while(T--){
scanf("%d%d",&n,&k);
build(,n,);
while(k--){
scanf("%d%d%d",&x,&y,&z);
update(x,y,z,);
}
printf("Case %d: The total value of the hook is %d.\n",cas++,query());
}
return ;
}
HDU 1698 Just a Hook(线段树的更多相关文章
- HDU 1698 just a hook 线段树,区间定值,求和
Just a Hook Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=1 ...
- HDU 1698 Just a Hook(线段树 区间替换)
Just a Hook [题目链接]Just a Hook [题目类型]线段树 区间替换 &题解: 线段树 区间替换 和区间求和 模板题 只不过不需要查询 题里只问了全部区间的和,所以seg[ ...
- HDU 1698 Just a Hook(线段树成段更新)
Just a Hook Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Tota ...
- HDU 1698 Just a Hook (线段树 成段更新 lazy-tag思想)
题目链接 题意: n个挂钩,q次询问,每个挂钩可能的值为1 2 3, 初始值为1,每次询问 把从x到Y区间内的值改变为z.求最后的总的值. 分析:用val记录这一个区间的值,val == -1表示这 ...
- [HDU] 1698 Just a Hook [线段树区间替换]
Just a Hook Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total ...
- (简单) HDU 1698 Just a Hook , 线段树+区间更新。
Description: In the game of DotA, Pudge’s meat hook is actually the most horrible thing for most of ...
- HDU 1698 Just a Hook 线段树+lazy-target 区间刷新
Just a Hook Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Tota ...
- HDU 1698 Just a Hook(线段树区间更新查询)
描述 In the game of DotA, Pudge’s meat hook is actually the most horrible thing for most of the heroes ...
- HDU 1698 Just a Hook(线段树区间替换)
题目地址:pid=1698">HDU 1698 区间替换裸题.相同利用lazy延迟标记数组,这里仅仅是当lazy下放的时候把以下的lazy也所有改成lazy就好了. 代码例如以下: # ...
- HDU 1698 Just a Hook 线段树区间更新、
来谈谈自己对延迟标记(lazy标记)的理解吧. lazy标记的主要作用是尽可能的降低时间复杂度. 这样说吧. 如果你不用lazy标记,那么你对于一个区间更新的话是要对其所有的子区间都更新一次,但如果用 ...
随机推荐
- 6-C++远征之封装篇[上]-学习笔记
C++远征之封装篇(上) 课程简介 类(抽象概念),对象(真实具体) 配角: 数据成员和成员函数(构成了精彩而完整的类) 构造函数 & 析构函数(描述了对象的生生死死) 对象复制和对象赋值 ( ...
- 深入了解jQuery Mobile-1
介绍 jQuery Mobile是一种触控优化的HTML5 UI框架,旨在制作可在所有智能手机,平板电脑和台式机设备上访问的响应式网站和应用程序 移动页面结构 jQuery Mobile站点必须以HT ...
- Linux系统下安装rz/sz命令
执行命令 yum install -y lrzsz rz -be本地上传文件到服务器
- DATAGUARD实施文档
DATAGUARD实施文档 一.前期准备及备机安装: 通过获取到的主机信息规划备机数据库安装基础信息:(注:在安装备机时需要尽量保障与主机库信息一致,以下表格中的备机信息为根据主机信息规划的安装信息. ...
- 20145202马超 2016-2017-2 《Java程序设计》第四周学习总结
20145202马超 2016-2017-2 <Java程序设计>第四周学习总结 教材学习内容总结 继承:打破了封装性 extends 1.提高了代码的复用性. 2.让类与类之间产生了关系 ...
- pxe无人值守安装linux机器笔记----摘抄
1. 基建工作 1.关闭防火墙 a)service iptables stop b)service ip6tables stop c)chkconfig iptables off d)chkconfi ...
- 用起来超爽的Maven——进阶篇
以后随着使用的maven的频率增加,此文件会越来越大,也是为什么需要把默认C:\Users\Administrator\.m2 \repository目录改变为D:/OpenSources/repos ...
- 菜鸟级appium 必看
之所以写这个,因为太多新人,appium环境半天都搭建不好,版本问题,兼容问题等等. 自己的解决方案:1 官网下载nodejs,建议安装长期支持版 2 进入appium官网,点击下载,跳转到githu ...
- The Erdös-Straus Conjecture 题解
题面 Description The Brocard Erdös-Straus conjecture is that for any integern > 2 , there are posit ...
- deeplearning.ai课程学习(4)
第四周:深层神经网络(Deep Neural Networks) 1.深层神经网络(Deep L-layer neural network) 在打算使用深层神经网络之前,先去尝试逻辑回归,尝试一层然后 ...