魔兽世界---屠夫(Just a Hook)

        Just a Hook

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

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.

题解:本来屠夫的钩子是铜的价值是1,然后每次使x到y间的钩子变为银2,或金3;线段树;

错了很多次,原来想着把z设为全局变量,最后答案一直不对,经历了各种曲折。。。

代码:

 1 #include<stdio.h>
 2 const int MAXN=100010;
 3 struct Node{
 4     int l,r;
 5     int sum,lazy,val;//val不能全局变量。。。
 6 };
 7 Node tree[MAXN<<2];
 8 #define NOW tree[root].sum=tree[root<<1].sum+tree[root<<1|1].sum
 9 #define lson root<<1,tree[root].l,mid
10 #define rson root<<1|1,mid+1,tree[root].r
11 void build(int root,int l,int r){
12     tree[root].l=l;
13     tree[root].r=r;
14     tree[root].lazy=0;
15     tree[root].val=0;
16     if(l==r)tree[root].sum=1;
17     else{
18             int mid=(l+r)>>1;
19         build(lson);
20         build(rson);
21         NOW;
22     }
23 }
24 void update(int root,int l,int r,int v){
25     if(l==tree[root].l&&r==tree[root].r){
26             tree[root].lazy=1;
27             tree[root].val=v;
28             tree[root].sum=(r-l+1)*v;
29     }
30     else{
31         int mid=(tree[root].l+tree[root].r)>>1;
32         if(tree[root].lazy==1){
33             tree[root].lazy=0;
34             update(lson,tree[root].val);
35             update(rson,tree[root].val);
36             tree[root].val=0;
37         }
38         if(r<=mid)update(root<<1,l,r,v);
39         else if(l>mid)update(root<<1|1,l,r,v);
40         else{//这个不能少了,代表l,r在tree的两个孩子节点内,也就是找到了l,r的区间;
41             update(root<<1,l,mid,v);
42             update(root<<1|1,mid+1,r,v);
43         }
44         NOW;
45     }
46 }
47 int main(){
48     int T,N,Q,flot=0;
49     scanf("%d",&T);
50     while(T--){
51             scanf("%d",&N);
52         scanf("%d",&Q);
53         build(1,1,N);
54         while(Q--){
55             int x,y,z;
56             scanf("%d%d%d",&x,&y,&z);
57             update(1,x,y,z);
58         }
59         printf("Case %d: The total value of the hook is %d.\n",++flot,tree[1].sum);
60     }
61     return 0;
62 }
时间: 2024-07-30 13:49:28

魔兽世界---屠夫(Just a Hook)的相关文章

HDU 1689 Just a Hook 线段树区间更新求和

点击打开链接 Just a Hook Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 18894    Accepted Submission(s): 9483 Problem Description In the game of DotA, Pudge's meat hook is actually the most horrible

hdu 1698 Just a Hook(线段树区间修改)

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 numb

HDU1689(Just a Hook)

题目地址:Just a Hook 题目大意: 在data中 一位英雄“屠夫”有个钩子,是由几段金属棒构成的,其中金属棒可以分为铜棒其val为1,银棒其val为2,金棒其val为3,其中屠夫的钩子其金属棒的初始值为1,屠夫想要进行一些操作,来改变一些区间的金属棒的val值.其改变的性质是从x->y区间的所有金属棒值改变为z.最后求出钩子的价值总和. 解题思路: 线段数,成段的更新求出总和,需要用到lazy 标记. 代码: 1 #include <algorithm> 2 #include

HDU - 1698 Just a Hook(线段树区间整体修改值,查询区间和)

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 numb

HOOK钩子技术5 SSDT Inline Hook

原理 内联钩子的原理在R3和R0下是相同的,就是不改变SSDT表项,而是改变函数内部前几条指令. 内联钩子的典型伪函数为: 恢复原指令 执行目标操作,或改写参数 执行原函数 返回时重新挂钩 demo #include "stdafx.h" #ifdef __cplusplus extern "C" NTSTATUS DriverEntry(IN PDRIVER_OBJECT DriverObject, IN PUNICODE_STRING RegistryPath)

hdu 1698 Just a Hook(线段树,成段更新,懒惰标记)

Just a Hook Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 18384    Accepted Submission(s): 9217 Problem Description In the game of DotA, Pudge's meat hook is actually the most horrible thing

svn集成ReviewBoard,让post-commit hook后台运行

代码评审(Code Review)不但可以提高质量,而且还是一个知识共享和指导的极好的手段. 代码评审(CodeReview)一般有两种形式:pre-commit-review,post-commit-review. pre-commit-review是指代码提交到代码库前进行代码评审: post-commit-review是指代码提交到代码库后进行代码评审. ReviewBoard是一个开源的基于web的代码评审工具,支持Subversion,CVS,Git和Mercurial版本控制系统.

gitlab+jenkins+hook代码自动构建发布上线

Gitlab+Jenkins+Hook 1.gitlab和jenkins的安装见: http://www.cnblogs.com/cuishuai/p/7544663.html http://www.cnblogs.com/cuishuai/p/7544775.html 2.gitlab配置 1)创建一个project,并创建一个monkey的分支. 2)对分支进行设置: 点击project->settings->integrations: 1. 2. 3 Webhook,点击test,返回如

android hook 框架 libinject2 简介、编译、运行

简介: libinject 最开始是2011年看雪android安全版版主之一‘古河’大神发布的一份android平台的注入库:  发个Android平台上的注入代码  ,网上很多随后发布的注入代码都是其变种,不过我这几天尝试运行那份代码,发现有些问题,本博运行和分析的代码是另外一位大神的改进版本,在我的环境里运行注入和挂钩都成功了 : Android中的so注入(inject)和挂钩(hook) - For both x86 and arm ,为了表示区别,我把这个项目称为  libinjec