Just a Hook

Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 26203    Accepted Submission(s): 13101

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.
 
第二道区间更新的题。
回顾了一下区间更新的要领,还不错总体算是自己完成的。
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include<iostream>
using namespace std;
#define N 200005
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1 struct Node1
{
int kind;
int sum;
int l,r;
} tree[N<<]; void pushup(int rt)
{
tree[rt].sum=tree[rt<<].sum+tree[rt<<|].sum;
} void build(int l,int r,int rt)
{
tree[rt].l=l;
tree[rt].r=r;
tree[rt].kind=;
if(l==r)
{
tree[rt].sum=;
return;
}
int mid=(l+r)>>;
build(lson);
build(rson);
pushup(rt);
} void pushdown(int rt)
{
if(tree[rt].kind!=)
{
tree[rt<<].kind=tree[rt].kind;
tree[rt<<|].kind=tree[rt].kind;
tree[rt<<].sum=(tree[rt<<].r-tree[rt<<].l+)*tree[rt<<].kind;
tree[rt<<|].sum=(tree[rt<<|].r-tree[rt<<|].l+)*tree[rt<<|].kind;
tree[rt].kind=;
}
} void update(int x,int L,int R,int l,int r,int rt)
{
if(L==l&&r==R)
{
tree[rt].kind=x;
tree[rt].sum=(tree[rt].r-tree[rt].l+)*x;
return;
}
//cout<<"*"<<endl;
pushdown(rt);
int mid=(l+r)>>;
if(R<=mid)
update(x,L,R,lson);
else if(L>mid)
update(x,L,R,rson);
else
{
update(x,L,mid,lson);
update(x,mid+,R,rson);
}
pushup(rt);
} int main()
{
int t,n,q,cnt=;
scanf("%d",&t);
while(t--)
{
scanf("%d",&n);
build(,n,);
scanf("%d",&q);
while(q--)
{
int a,b,k;
scanf("%d%d%d",&a,&b,&k);
update(k,a,b,,n,);
}
printf("Case %d: The total value of the hook is %d.\n",cnt++,tree[].sum);
}
return ;
}

HDU_1698_Just a Hook_线段树区间更新的更多相关文章

  1. HDU 1556 Color the ball(线段树区间更新)

    Color the ball 我真的该认真的复习一下以前没懂的知识了,今天看了一下线段树,以前只会用模板,现在看懂了之后,发现还有这么多巧妙的地方,好厉害啊 所以就应该尽量搞懂 弄明白每个知识点 [题 ...

  2. hihoCoder 1080 : 更为复杂的买卖房屋姿势 线段树区间更新

    #1080 : 更为复杂的买卖房屋姿势 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 小Hi和小Ho都是游戏迷,“模拟都市”是他们非常喜欢的一个游戏,在这个游戏里面他们 ...

  3. HDU 5023 A Corrupt Mayor's Performance Art(线段树区间更新)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5023 解题报告:一面墙长度为n,有N个单元,每个单元编号从1到n,墙的初始的颜色是2,一共有30种颜色 ...

  4. HDU 4902 Nice boat 2014杭电多校训练赛第四场F题(线段树区间更新)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4902 解题报告:输入一个序列,然后有q次操作,操作有两种,第一种是把区间 (l,r) 变成x,第二种是 ...

  5. HDU 1698 线段树 区间更新求和

    一开始这条链子全都是1 #include<stdio.h> #include<string.h> #include<algorithm> #include<m ...

  6. POJ-2528 Mayor's posters (线段树区间更新+离散化)

    题目分析:线段树区间更新+离散化 代码如下: # include<iostream> # include<cstdio> # include<queue> # in ...

  7. ZOJ 1610 Count the Colors (线段树区间更新)

    题目链接 题意 : 一根木棍,长8000,然后分别在不同的区间涂上不同的颜色,问你最后能够看到多少颜色,然后每个颜色有多少段,颜色大小从头到尾输出. 思路 :线段树区间更新一下,然后标记一下,最后从头 ...

  8. POJ 2528 Mayor's posters (线段树区间更新+离散化)

    题目链接:http://poj.org/problem?id=2528 给你n块木板,每块木板有起始和终点,按顺序放置,问最终能看到几块木板. 很明显的线段树区间更新问题,每次放置木板就更新区间里的值 ...

  9. HDU5039--Hilarity DFS序+线段树区间更新 14年北京网络赛

    题意:n个点的树,每个条边权值为0或者1, q次操作 Q 路径边权抑或和为1的点对数, (u, v)(v, u)算2个. M i修改第i条边的权值 如果是0则变成1, 否则变成0 作法: 我们可以求出 ...

随机推荐

  1. js的jsonp

    window.ajaxJsonp=function(params) { params = params || {}; params.data = params.data || {}; var json ...

  2. 函数操作(this操作)

    1.apply/call函数:会改变this关键字,并且第一个参数作为this关键字. /*apply与call区别*/ console.log(Array.prototype.join.call([ ...

  3. TDSTCPServerTransport 的Filters

    TDSTCPServerTransport 的Filters TDSTCPServerTransport 的 Filter 属性,可以对传递的数据进行加密,压缩,再修改等,有 点注入的概念.默认情况下 ...

  4. OSX: node中安装zeromq

    1. brew install pkg-config2. brew install zmq3. export PKG_CONFIG_PATH="/usr/local/lib/pkgconfi ...

  5. 1. MaxCounters 计数器 Calculate the values of counters after applying all alternating operations: increase counter by 1; set value of all counters to current maximum.

    package com.code; import java.util.Arrays; public class Test04_4 { public static int[] solution(int ...

  6. [C]if (CONDITION)语句中CONDITION的情况

    编译环境: Ubuntu 12.04: gcc Windows XP : VS-2005 深入一下if (CONDITION)语句中CONDITION的情况.即CONDITION何时为真,何时是假. ...

  7. P4700 算

    P4700 算 时间: 1000ms / 空间: 125829120KiB / Java类名: Main 背景 zhx和他的妹子出去玩. 描述

  8. windowActionModeOverlay

    windowActionModeOverlay: android:windowActionModeOverlay=“true|false”  : actionmode 弹出时覆盖部分布局      若 ...

  9. 使用git命令 (git reset --hard HEAD) 回退版本信息

    Git必须知道当前版本是哪个版本,在Git中,用HEAD表示当前版本,上一个版本就是HEAD^,上上一个版本就是HEAD^^,当然往上100个版本写100个^比较容易数不过来,所以写成HEAD~100 ...

  10. [LibreOJ NOIP Round #1] 旅游路线

    [题目链接] https://loj.ac/problem/539 [算法] 首先 , 我们用f[u][k]表示现在在景点u ,还有k元钱 , 最多能够走多少路 不难发现f[u][k] = max{ ...