Just a Hook

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

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 <iostream>
#include <algorithm>
#include <stdio.h>
#include <string.h>
#include <math.h>
using namespace std;
#define ll long long int
ll a[];
ll d[];
void build(int b,int c,int x)
{
if(b==c)
{
a[x]=;
return ;
}
int m=(b+c)>>;
build(b,m,x<<);
build(m+,c,x<<|);
a[x]=a[x<<]+a[x<<|];
}
void fun(int x,int m)
{
if(d[x])
{
d[x<<]=d[x<<|]=d[x];
a[x<<]=(m-(m>>))*d[x];
a[x<<|]=(m>>)*d[x];
d[x]=;
}
}
void update(int x,int y,int b,int c,int t,int z)
{
if(x<=b&&y>=c)
{
d[t]=z;
a[t]=(c-b+)*z;
return;
}
fun(t,c-b+);
int m=(b+c)>>;
if(x<=m) update(x,y,b,m,t<<,z);
if(y>m) update(x,y,m+,c,t<<|,z);
a[t]=a[t<<]+a[t<<|];
}
int main()
{
//freopen("int.txt","r",stdin);
int m;
int i,j,x,y,z;
cin>>m;
for(i=;i<=m;i++)
{
int n,k;
memset(a,,sizeof(a));
memset(d,,sizeof(d));
cin>>n>>k;
build(,n,);
for(j=;j<k;j++)
{
scanf("%d%d%d",&x,&y,&z);
update(x,y,,n,,z);
}
cout<<"Case "<<i<<": The total value of the hook is "<<a[]<<"."<<endl;
}
}

hdu1698线段树的区间更新区间查询的更多相关文章

  1. HDU1698 线段树(区间更新区间查询)

    Just a Hook Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total S ...

  2. hdu1698 线段树(区间更新~将区间[x,y]的值替换为z)

    Just a Hook Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total ...

  3. hdu 1556:Color the ball(线段树,区间更新,经典题)

    Color the ball Time Limit: 9000/3000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)To ...

  4. hdu 1698:Just a Hook(线段树,区间更新)

    Just a Hook Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total ...

  5. UVA 12436-Rip Van Winkle's Code(线段树的区间更新)

    题意: long long data[250001]; void A( int st, int nd ) { for( int i = st; i \le nd; i++ ) data[i] = da ...

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

    http://acm.hdu.edu.cn/showproblem.php?pid=1556 题意: N个气球,每次[a,b]之间的气球涂一次色,统计每个气球涂色的次数. 思路: 这道题目用树状数组和 ...

  7. zoj3686(线段树的区间更新)

    对线段树的区间更新有了初步的了解... A Simple Tree Problem Time Limit: 3 Seconds      Memory Limit: 65536 KB Given a ...

  8. Color the ball (线段树的区间更新问题)

    N个气球排成一排,从左到右依次编号为1,2,3....N.每次给定2个整数a b(a <= b),lele便为骑上他的“小飞鸽"牌电动车从气球a开始到气球b依次给每个气球涂一次颜色.但 ...

  9. ZOJ 2301 Color the Ball 线段树(区间更新+离散化)

    Color the Ball Time Limit: 2 Seconds      Memory Limit: 65536 KB There are infinite balls in a line ...

随机推荐

  1. java中接口实现多态举例

    public class Test4 { public static void main(String[] args){ Instrument ss[]={new Wind(),new Piano() ...

  2. js学习--变量作用域和作用域链

    作为一名菜鸟的我,每天学点的感觉还是不错的.今天学习闭包的过程中看到作用域与作用域链这两个概念,我觉得作为一名有追求的小白,有必要详细了解下. 变量的作用域 就js变量而言,有全局变量和局部变量.这里 ...

  3. Project 7:自然数的拆分

    自然数的拆分:任何一个大于1的自然数N,总可以拆分成若干个自然数之和,并且有多种拆分方法.例如自然数5,可以有如下一些拆分方法: 5=1+1+1+1+1 5=1+1+1+2 5=1+2+2 5=1+4 ...

  4. python re group()

    python group() 正则表达式中,group()用来提出分组截获的字符串,()用来分组 import re a = "123abc456" print re.search ...

  5. GUI(国际象棋棋盘)

    package com.niit.javagui; import java.awt.BorderLayout; import java.awt.Color; import java.awt.GridB ...

  6. 201521123028 《Java程序设计》第8周学习总结

    1. 本周学习总结 2. 书面作业 Q1.List中指定元素的删除(题目4-1) 1.1 实验总结 Ans: 在这一题中我们需要写两个函数,分别是remove()和convertStringToLis ...

  7. 201521123009 《Java程序设计》第7周学习总结

    1. 本周学习总结 2. 书面作业 Q1:ArrayList代码分析 1.1 解释ArrayList的contains源代码 //contains()方法 public boolean contain ...

  8. 201521123054《java程序设计》第12周学习总结

    1. 本周学习总结 2. 书面作业 1. 字符流与文本文件:使用 PrintWriter(写),BufferedReader(读) 1.1 生成的三个学生对象,使用PrintWriter的printl ...

  9. thinkphp介绍及访问方式

    ThinkPHP框架 1.解压到www目录下,里面有一个index文件是入口文件,通过修改里面的APP_PATH进入不同的应用 2.ThinkPHP文件夹是核心文件夹,里面东西不要修改,可以查看,比如 ...

  10. Modeling -> Mixamo auto rigging -> UE4 retargeting

    In general, there are 3 ways we can work with the Blender-UE4 pipeline:   1 Model character Export m ...