Just a Hook
题目大意:原来有N个铜棍, 一个人有种能力可以把一个区间的棍变成铜,银或者金的,价值分别是1,2,3, 最后求出总价值,没啥好说的,赤裸裸的线段树;
Time Limit : 4000/2000ms (Java/Other)   Memory Limit : 32768/32768K  (Java/Other)
Total Submission(s) : 8   Accepted Submission(s) : 3
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.  [center][img]../../../data/images/C116-1010-1.JPG[/img][/center] 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
 
Sample Output
Case 1: The total value of the hook is 24. 
 
 
#include<iostream>
#include<cstdio>
using namespace std;
#define maxn 100000
struct node
{
    int L, R, nature;
    int mid()
    {
        return (L+R) / 2;
    }
};
node a[maxn*4+10];
int value;
void BuildTree(int r, int L, int R);
void Insert(int r ,int L, int R, int nature);
void Query(int r);
int main()
{
    int ncase, k=1;
    scanf("%d", &ncase);
    while(ncase--)
    {
        int N, Q;
        scanf("%d%d", &N, &Q);
        BuildTree(1, 1, N);
        for(int i=0; i<Q; i++)
        {
            int X, Y, Z;
            scanf("%d%d%d", &X, &Y, &Z);
            Insert(1, X, Y, Z);
        }
        value = 0;
        Query(1);
        printf("Case %d: The total value of the hook is %d.\n", k++, value);
    }
    return 0;
}
void BuildTree(int r, int L, int R)
{
    a[r].L = L, a[r].R = R, a[r].nature = 1;
    if(L == R)return ;
    BuildTree(r*2, L, a[r].mid());
    BuildTree(r*2+1, a[r].mid()+1, R);
}
void Insert(int r ,int L, int R, int nature)
{
    if(a[r].nature == nature)return ;
    if(a[r].L == L && a[r].R == R)
    {
        a[r].nature = nature;
        return;
    }
    if(a[r].nature)
        a[r*2].nature = a[r*2+1].nature = a[r].nature;
    a[r].nature = 0;
    if(R <= a[r].mid())
        Insert(r*2, L, R, nature);
    else if(L > a[r].mid())
        Insert(r*2+1, L, R, nature);
    else
    {
        Insert(r*2, L, a[r].mid(), nature);
        Insert(r*2+1, a[r].mid()+1, R, nature);
    }
}
void Query(int r)
{
    if(a[r].nature)
    {
        value += (a[r].R - a[r].L + 1) * a[r].nature;
        return ;
    }
    Query(r*2);
    Query(r*2+1);
}
												
												
						- svnserver hook python
		
在使用中可能会遇到的错误排除 :1.Error: svn: 解析"D:\www\test"出错,或svn: E020024: Error resolving case of 'D: ...
		 
						- Android Hook技术
		
原文:http://blog.csdn.net/u011068702/article/details/53208825 附:Android Hook 全面入侵监听器 第一步.先爆项目demo照片,代码 ...
		 
						- Frida HOOK微信实现骰子作弊
		
由于微信摇骰子的功能在本地进行随机后在发送,所以存在可以hook掉判断骰子数的方法进行修改作弊. 1.frida实现hook java层函数1)写个用来测试的demo,当我们点击按钮的时候会弹出窗口显 ...
		 
						- java的关闭钩子(Shutdown Hook)
		
Runtime.getRuntime().addShutdownHook(shutdownHook);    这个方法的含义说明:        这个方法的意思就是在jvm中增加一个关闭的钩子,当jv ...
		 
						- IDT HOOK思路整理
		
IDT(中断描述符表)分为IRQ(真正的硬件中断)和软件中断(又叫异常). HOOK的思路为,替换键盘中断处理的函数地址为自己的函数地址.这样在键盘驱动和过滤驱动之前就可以截获键盘输入. 思路确定之后 ...
		 
						- Android Hook 借助Xposed
		
主要就是使用到了Xposed中的两个比较重要的方法,handleLoadPackage获取包加载时候的回调并拿到其对应的classLoader:findAndHookMethod对指定类的方法进行Ho ...
		 
						- iOS App 无代码入侵的方法hook
		
继续Objective-C runtime的研究 最近公司项目在做用户行为分析 于是App端在某些页面切换,交互操作的时候需要给统计系统发送一条消息 在几十个Controller 的项目里,一个一个地 ...
		 
						- Hook机制里登场的角色
		
稍有接触过 WordPress 主题或插件制作修改的朋友,对 WordPress 的Hook机制应该不陌生,但通常刚接触WordPress Hook 的新手,对其运作原理可能会有点混乱或模糊.本文针对 ...
		 
						- java hook
		
linux下 hook的触发,需要 发送信号为15. 后续补充具体内容.
		 
						- HDU 1698 Just a Hook(线段树 区间替换)
		
Just a Hook [题目链接]Just a Hook [题目类型]线段树 区间替换 &题解: 线段树 区间替换 和区间求和 模板题 只不过不需要查询 题里只问了全部区间的和,所以seg[ ...
		 
		
	
随机推荐
	
									- JavaScript的push(),pop(),concat()方法
			
push 方法 将新元素添加到一个数组中,并返回数组的新长度值. arrayObj.push([item1 [item2 [. . . [itemN ]]]]) 参数 arrayObj 必选项.一个  ...
			 
						- CSS3弹性盒模型flex box快速入门 2016.03.16
			
@import url(http://i.cnblogs.com/Load.ashx?type=style&file=SyntaxHighlighter.css);@import url(/c ...
			 
						- java web工程的错误页面的简单配置
			
jsp页面,本身服务器也会将该页面翻译成一个servlet页面,所以请求该页面就会有可能出现错误的情况,就会出现下面类似的页面 这样给客户看到并不友好. 1.jsp页面<%@ page %> ...
			 
						- angularjs应用骨架(2)
			
时隔一个星期,接着上一篇的angularjs应用骨架继续聊聊angularjs其他的其他的内容. 区分UI和控制器的职责 在应用控制器中有三种职责: 1.为应用中模型设置初始状态 2.通过$scope ...
			 
						- gpfdist工具的初级使用
			
gpfdist工具的使用主要两步: 第一步:打开gpfdist服务: gpfdist -d /home/admin -p -l /tmp/gpfdist.log & 参数解释: -d 数据文件 ...
			 
						- 转载C#泛型集合—Dictionary<K,V>使用技巧
			
1.要使用Dictionary集合,需要导入C#泛型命名空间 System.Collections.Generic(程序集:mscorlib) 2.描述 1).从一组键(Key)到一组值(Value) ...
			 
						- MAYA 多线程
			
''' Usage: def timerTest(): print 'Hello World!' #create and start a timer timer = Timer(30, timerTe ...
			 
						- 我学C的那些年[ch02]:宏,结构体,typedef
			
c语言的编译过程: 预处理 编译 汇编 链接 而预处理中有三种情况: 文件包含( #include ) 条件编译(#if,#ifndef,#endif) 宏定义( #define ) 宏就是预处理中的 ...
			 
						- uboot移植之环境变量在NandFlash
			
一.概述 u-boot环境变量可以设置在Norflash上,也可以在NandFlash上. 倘若环境变量在NorFlash上,再假设S3C2440从NorFlash启动,是能正确从NorFlash上读 ...
			 
						- 将小度WiFi改造为无线网卡(小度WiFi能够接收WiFi信号)
			
安装官方的小度WiFi的驱动器,只能让它当做无线信号的发射装置,但是我想通过小度WiFi让我的台式电脑能都接收无线信号,于是经过一番折腾终于成功了.我的是win7. 小度WiFi无法接受无线信号,不能 ...