4A. Just a Hook

Time Limit: 2000ms
Case Time Limit: 2000ms
Memory Limit: 32768KB
 
64-bit integer IO format: %I64d      Java class name: Main
 
 
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.

思路:线段树模板题,对于我这种英语渣来说,题目有点长,不过操作很简单!跟count color那题差不多吧!
 #include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <vector>
#include <climits>
#include <algorithm>
#include <cmath>
#define LL long long
using namespace std;
const int maxn = ;
struct node{
int val,lt,rt;
}tree[maxn<<];
void build(int lt,int rt,int layer){
tree[layer].lt = lt;
tree[layer].rt = rt;
tree[layer].val = ;
if(lt == rt) return;
int mid = (lt+rt)>>;
build(lt,mid,layer<<);
build(mid+,rt,layer<<|);
}
void update(int lt,int rt,int val,int layer){
if(tree[layer].val == val) return;
int mid = (tree[layer].lt + tree[layer].rt)>>;
if(tree[layer].lt == lt && tree[layer].rt == rt){
tree[layer].val = val;return;
}
if(tree[layer].val){
tree[layer<<].val = tree[layer<<|].val = tree[layer].val;
tree[layer].val = ;
}
if(rt <= mid) update(lt,rt,val,layer<<);
else if(lt > mid) update(lt,rt,val,layer<<|);
else{
update(lt,mid,val,layer<<);
update(mid+,rt,val,layer<<|);
}
}
int sum(int layer){
if(tree[layer].val){
return (tree[layer].rt-tree[layer].lt+)*tree[layer].val;
}
return sum(layer<<)+sum(layer<<|);
}
int main(){
int kase,i,x,y,z,m,n,k = ;
scanf("%d",&kase);
while(kase--){
scanf("%d %d",&n,&m);
build(,n,);
for(i = ; i < m; i++){
scanf("%d %d %d",&x,&y,&z);
update(x,y,z,);
}
printf("Case %d: The total value of the hook is %d.\n",k++,sum());
}
return ;
}

4A. Just a Hook的更多相关文章

  1. svnserver hook python

    在使用中可能会遇到的错误排除 :1.Error: svn: 解析"D:\www\test"出错,或svn: E020024: Error resolving case of 'D: ...

  2. Android Hook技术

    原文:http://blog.csdn.net/u011068702/article/details/53208825 附:Android Hook 全面入侵监听器 第一步.先爆项目demo照片,代码 ...

  3. Frida HOOK微信实现骰子作弊

    由于微信摇骰子的功能在本地进行随机后在发送,所以存在可以hook掉判断骰子数的方法进行修改作弊. 1.frida实现hook java层函数1)写个用来测试的demo,当我们点击按钮的时候会弹出窗口显 ...

  4. java的关闭钩子(Shutdown Hook)

    Runtime.getRuntime().addShutdownHook(shutdownHook);    这个方法的含义说明:        这个方法的意思就是在jvm中增加一个关闭的钩子,当jv ...

  5. IDT HOOK思路整理

    IDT(中断描述符表)分为IRQ(真正的硬件中断)和软件中断(又叫异常). HOOK的思路为,替换键盘中断处理的函数地址为自己的函数地址.这样在键盘驱动和过滤驱动之前就可以截获键盘输入. 思路确定之后 ...

  6. Android Hook 借助Xposed

    主要就是使用到了Xposed中的两个比较重要的方法,handleLoadPackage获取包加载时候的回调并拿到其对应的classLoader:findAndHookMethod对指定类的方法进行Ho ...

  7. iOS App 无代码入侵的方法hook

    继续Objective-C runtime的研究 最近公司项目在做用户行为分析 于是App端在某些页面切换,交互操作的时候需要给统计系统发送一条消息 在几十个Controller 的项目里,一个一个地 ...

  8. Hook机制里登场的角色

    稍有接触过 WordPress 主题或插件制作修改的朋友,对 WordPress 的Hook机制应该不陌生,但通常刚接触WordPress Hook 的新手,对其运作原理可能会有点混乱或模糊.本文针对 ...

  9. java hook

    linux下 hook的触发,需要 发送信号为15. 后续补充具体内容.

随机推荐

  1. Struts 2中访问Servlet API的几种方法小结

    1.使用ActionContext Action运行期间所用到的数据都保存在ActionContext中,例如session.客户端提交的参数等,ActionContext是Action的一个上下文对 ...

  2. Mvc 多级控制器 路由重写 及 多级Views目录 的寻找视图的规则

    1.那么我们再来看我们需要的访问方式,如下图 如果我们要访问Admin下的TestController里面的Index页面,那么我们输入Test/Index,这个肯定不行的.因为TestControl ...

  3. Java中的数据类型——通过示例学习Java编程(5)

    作者:CHAITANYA SINGH 来源:https://www.koofun.com//pro/kfpostsdetail?kfpostsid=15 数据类型用来定义变量可以采用的值,例如,如果变 ...

  4. NOIP数学相关模板整理

    $O(n)$递推求逆元 #include<cstdio> #include<cstring> #include<algorithm> using namespace ...

  5. 降低PNG图片存储大小方法、图片压缩方法

    降低PNG图片存储大小方法,图片压缩方法,如何降低PNG图片存储大小?前提是分辨率和尺寸大小不变,图形的透明部分不变.请看如下办法,亲测可用. 1. 将PNG图片用PS打开. 2. 图像-模式-8位/ ...

  6. JBOSS连接池默认连接数是多少?在哪个配置文件有这个默认的连接数?

    如果你用的是是4.x的Jboss的话,请参考:docs/dtd/jboss-ds_1_0.dtd,相信你很容易就能找到控制最大/最小连接数的选项,应该是诸如:max-pool-size/min-poo ...

  7. Linux OpenGL 实践篇-14-多实例渲染

    多实例渲染 OpenGL的多实例渲染是一种连续执行多条相同的渲染命令的方法,并且每条命令产生的结果都有轻微的差异,通常用于渲染大量的几何物体. 设想一个场景,比如太空,我们需要渲染数以万记的星球,如果 ...

  8. 前端性能优化:细说JavaScript的加载与执行

    本文主要是从性能优化的角度来探讨JavaScript在加载与执行过程中的优化思路与实践方法,既是细说,文中在涉及原理性的地方,不免会多说几句,还望各位读者保持耐心,仔细理解,请相信,您的耐心付出一定会 ...

  9. Python 字典dict 集合set

    字典dict Python内置字典,通过key-value进行存储,字典是无序的,拓展hash names = ['Michael', 'Bob', 'Tracy'] scores = [95, 75 ...

  10. 在Terminal中,如何打开Finder,并显示当前的目录

    这是一个非常方便实用的小技巧,在Terminal中输入如下命令: $ open . 有图有真相: 参考: Open Finder in Current Folder from Terminal