HDU1698 Just a Hook (区间更新)
Just a Hook
Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 23644 Accepted Submission(s): 11839
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.
10
2
1 5 2
5 9 3
#include <cstdio>
#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <ctime>
#include <cmath>
#include <string>
#include <cstring>
#include <stack>
#include <queue>
#include <list>
#include <vector>
#include <map>
#include <set>
using namespace std; const int INF=0x3f3f3f3f;
const double eps=1e-;
const double PI=acos(-1.0);
#define maxn 110000
int tre[maxn*];
int lazy[maxn*];
void build(int num, int le, int ri)
{
if(le == ri)
{
tre[num] = ;
return;
}
int mid = (le+ri)/;
build(num*, le, mid);
build(num*+, mid+, ri);
tre[num] = tre[num*] + tre[num*+];
}
void pushdown(int num, int le, int mid, int ri)
{
if(lazy[num]!=)
{
lazy[num*] = lazy[num];
lazy[num*+] = lazy[num];
tre[num*] = (mid-le+)*lazy[num*];
tre[num*+] = (ri-mid)*lazy[num*+];
lazy[num] = ;
}
} void update(int num, int le, int ri, int x, int y, int val)
{
if(x<=le && y>=ri)
{
tre[num] = (ri-le+)*val;
lazy[num] = val;
return;
}
int mid = (le+ri)/;
pushdown(num,le,mid,ri);
if(x<=mid)
update(num*,le,mid,x,y,val);
if(y>mid)
update(num*+,mid+,ri,x,y,val);
tre[num] = tre[num*] + tre[num*+];
}
int main()
{
int t;
scanf("%d", &t);
int cas = ;
while(t--)
{
int n;
scanf("%d", &n);
build(,,n);
memset(lazy, , sizeof lazy);
int m;
scanf("%d", &m);
for(int i = ; i < m; i++)
{
int a,b,c;
scanf("%d%d%d", &a, &b, &c);
update(,,n,a,b,c);
}
printf("Case %d: The total value of the hook is %d.\n", ++cas, tre[]);
}
return ;
}
HDU1698 Just a Hook (区间更新)的更多相关文章
- hdu1698线段树的区间更新区间查询
Just a Hook Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Tota ...
- hdu1698 线段树(区间更新~将区间[x,y]的值替换为z)
Just a Hook Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total ...
- HDU 1698 Just a Hook 区间更新 lazy标记
lazy标记 #include <iostream> #include <cstdio> #include <cstring> #include <sstre ...
- HDU1698 线段树(区间更新区间查询)
Just a Hook Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total S ...
- 【原创】hdu1698 Just a Hook(线段树→区间更新,区间查询)
学习线段树第二天,这道题属于第二简单的线段树,第一简单是单点更新,这个属于区间更新. 区间更新就是lazy思想,我来按照自己浅薄的理解谈谈lazy思想: 就是在数据结构中,树形结构可以线性存储(线性表 ...
- HDU1698:Just a Hook(线段树区间更新)
Problem Description In the game of DotA, Pudge’s meat hook is actually the most horrible thing for m ...
- hdu1698 Just a hook 线段树区间更新
题解: 和hdu1166敌兵布阵不同的是 这道题需要区间更新(成段更新). 单点更新不用说了比较简单,区间更新的话,如果每次都更新到底的话,有点费时间. 这里就体现了线段树的另一个重要思想:延迟标记. ...
- hdu1698 线段树区间更新
Just a Hook Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Tota ...
- 线段树---成段更新hdu1698 Just a Hook
hdu1698 Just a Hook 题意:O(-1) 思路:O(-1) 线段树功能:update:成段替换 (由于只query一次总区间,所以可以直接输出1结点的信息) 题意:给一组棍子染色,不同 ...
随机推荐
- xcode插件——新建cocos2dx工程
个人制作的一个创建cocos2dx工程的xcode小插件 按照readme安装一下即可. 创建工程后,将自动弹出finder到工程目录. 弹出窗口:
- 设计模式之(二)Adapter模式
今天学习Adapter模式,An adapter helps two incompatible interfaces to work together. This is the real world ...
- pyqt node节点1
#!/usr/bin/env python # coding: utf-8 from PyQt4.QtGui import * from PyQt4.QtCore import * rad = 5 c ...
- [原创作品]手把手教你怎么写jQuery插件
这次随笔,向大家介绍如何编写jQuery插件.啰嗦一下,很希望各位IT界的‘攻城狮’们能和大家一起分享,一起成长.点击左边我头像下边的“加入qq群”,一起分享,一起交流,当然,可以一起吹水.哈,不废话 ...
- UIImagePickerController从拍照、图库、相册获取图片
iOS 获取图片有三种方法: 1. 直接调用摄像头拍照 2. 从相册中选择 3. 从图库中选择 UIImagePickerController 是系统提供的用来获取图片和视频的接口: 用UIImage ...
- sql server 2008 中的架构(schame)理解
机构是属于数据库里面的.在一个数据库中,每一张表都属于一个架构,架构就像是命名空间,把数据库中的表分成不同的组,一个组就是一个命名空间,方便管理
- 操作系统下查看HBA卡信息wwn的方法
一.Windows 系统在Windows系统中,可以使用FC HBA卡厂家提供的管理软件查看光纤适配器的WWN号码,具体如下:Qlogic:SANsurferEmulex:HBAnyware http ...
- 新建的硬盘-mount
一.查看已经格式化或已挂接硬盘 df -aT 等命令(自己度娘) 二.查看未挂硬盘和未格式化硬盘 1.fdisk -l 比如/dev/sdb 如果已经分区,会有sdb1. 2.格式化 #mkfs - ...
- 监控工具nagios
Nagios 简介是一个开源软件,可以监控网络设备网络流量.Linux/windows主机状态,甚至可以监控打印机它可以运行在Linux上或windows上基于浏览器的web界面方便运维人员查看监控项 ...
- Linux目录和权限
1. rmdir -p 用来删除一串目录,是否可以成功删除? rmdir -p 删除一个不存在的目录时是否报错呢?rmdir -p 不能成功删除非空目录,rmdir -p 删除一个不存在的目录 ...