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. [2013-01-15]The Little Schemer 学习笔记

    <The Little Schemer> FP编程.lisp入门必备 这书貌似没中文版: 有英文pdf版:完整版下载链接 英文不好的,被前几页噎住的,可以先到这里看翻译好的前言部分 看完人 ...

  2. Webpack+Vue+ES6 前端组件化开发mobile-multi-page应用实战总结

    本文版权归博客园和作者吴双本人共同所有 转载和爬虫请注明原文地址 www.cnblogs.com/tdws 一.写在前面 项目上线有一段时间了,一个基于webpack+vue+ES6的手机端多页面应用 ...

  3. java TreeSet应用

    这篇是紧接着上一篇而写的,具体的实现TreeSet中有序的第二中方法 首先新建一个类,此类就是用于集合中存放的对象 然后定义一个类,实现Comparator中的CompareTo()方法 最后一个测试 ...

  4. jmeter系列------参数关联

    接口请求中的一个变量需要用上一个接口道服务器返回响应的动态值(上个请求). 遇到这样的情况,我们就需要用到关联 例如用户A发表了一个一条微信朋友圈,用户B想对这条朋友圈进行评论,就需要先获取到这个朋友 ...

  5. 【小白成长撸】--链栈(C语言版)

    // 链栈.cpp : 定义控制台应用程序的入口点. // #include "stdafx.h" #include <stdio.h> #include <st ...

  6. 利用百度地图API和群蚁算法,对TSP问题进行模拟与求解

    前言 最近由于换了工作,期间也有反思和总结上家公司的得失,总觉得有什么事情当初可以完成或者完成得更好,其中TSP问题就是其中之一.当初在开发一个仓配系统的时候,有一个线路排程的需求,当时自己简单在纸上 ...

  7. web切图的几个快捷键及总结

      自由的控制视图系列 自由的浏览图片:按住空格后,鼠标拖动 自由的缩放图片:按住alt+滚轮 切换到实际像素(100%):Ctrl + 1 工作区类型切换:Tab 控制内容系列 通过画面上点选一个图 ...

  8. SNS团队第一次站立会议(2017.04.22)

    一.当天站立式会议照片 本次会议主要内容:进一步明确了团队中各个成员的定位,说明了下一步团队工作的方向 二.每个人的工作 成员 昨天已完成的工作 今天计划完成的工作 罗于婕 系统架构设计及项目数据库设 ...

  9. 201521123013 《Java程序设计》第8周学习总结

    1. 本章学习总结 2. 书面作业 Q1.List中指定元素的删除(题目4-1) 1.1 实验总结 while(list.contains(str)) list.remove(str); Q2.统计文 ...

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

    1. 本周学习总结 以你喜欢的方式(思维导图或其他)归纳总结集合相关内容. 2. 书面作业 ArrayList代码分析 1.1 解释ArrayList的contains源代码 答:从ArrayList ...