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. Hash二次探测

    Hash的二次探测,当hash的长度为n:插入val,当Hash[val]不为0时,选择新地址newval = val +(-) 1*1,val+(-)2*2,val+(-)(n-1)*(n-1); ...

  2. mounted钩子问题

    recommend.vue <script type="text/ecmascript-6"> import Slider from 'base/slider/slid ...

  3. html table内容不随标题滚动

    <html><head></head><body> <div> <div id="demo" style=&quo ...

  4. PAT_A1003#Emergency

    Source: PAT A1003 Emergency (25 分) Description: As an emergency rescue team leader of a city, you ar ...

  5. openstack——nova计算服务

    一.nova介绍               Nova 是 OpenStack 最核心的服务,负责维护和管理云环境的计算资源.OpenStack 作为 IaaS 的云操作系统,虚拟机生命周期管理也就是 ...

  6. MVCHelper 请求检验

    public class MVCHelper { //有 两 个ModelStateDictionary类,别弄混乱了要使用 System.Web.Mvc 下的 //如果添加引用中找不到System. ...

  7. chrony配置介绍

    rhel7 文档https://access.redhat.com/documentation/en-US/Red_Hat_Enterprise_Linux/7/html/System_Adminis ...

  8. awk 新手入门笔记

    转自:http://www.habadog.com/2011/05/22/awk-freshman-handbook/ awk新手入门笔记 @作者 : habadog@邮箱 : habadog1203 ...

  9. 洛谷——P2574 XOR的艺术

    P2574 XOR的艺术 很久之前就想挑战一下这道题了,线段树下传标记的入门题,跟区间加法下传标记类似. #include<bits/stdc++.h> #define N 1000005 ...

  10. Secret of Chocolate Poles (Aizu1378——dp)

    Select Of Chocolate Poles 题意:有一个竖直放置的高度为l cm的盒子,现在有三种方块分别为1cm的白块,1cm的黑块,k cm的黑块,要求第一块放进去的必须是黑色的,盒子最上 ...