Just a Hook
Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 1714 Accepted Submission(s): 700
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.
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.
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
#include<stdio.h> struct Tree { int zuo; int you; int date; }hook[100000*3]; //int p[100000+10]; void build(int a,int b,int n=1) { hook[n].zuo=a; hook[n].you=b; hook[n].date=1; if(a==b)return; int zhong=(a+b)>>1; build(a,zhong,2*n); build(zhong+1,b,2*n+1); } void change(int a,int b,int c,int n=1) { if(c==hook[n].date)return; if(a==hook[n].zuo&&b==hook[n].you) { hook[n].date=c; return; } if(hook[n].date!=0) { hook[2*n].date=hook[2*n+1].date=hook[n].date; hook[n].date=0; } int zhong=(hook[n].zuo+hook[n].you)>>1; if(b<=zhong)change(a,b,c,2*n); else if(zhong<a)change(a,b,c,2*n+1); else { change(a,zhong,c,2*n); change(zhong+1,b,c,2*n+1); } } int totle(int n=1) { if(hook[n].date!=0)return((hook[n].you-hook[n].zuo+1)*hook[n].date); return(totle(2*n)+totle(2*n+1)); } int main() { // freopen("in.txt","r",stdin); int T; int n,m; int a,b,c; int i=1; scanf("%d",&T); while(T--) { scanf("%d%d",&n,&m); build(1,n); while(m--) { scanf("%d%d%d",&a,&b,&c); change(a,b,c); } printf("Case %d: The total value of the hook is %d.\n",i++,totle()); } return(0); }
相关推荐
从简单入门到偏中等的几个题,线段树很灵活,主要懂了lazy操作,其他的自己yy吧。
hook git仓库自动更新脚本,服务器自动更新部署
hook 教程hook 教程hook 教程hook 教程hook 教程hook 教程hook 教程hook 教程hook 教程hook 教程hook 教程hook 教程hook 教程hook 教程hook 教程hook 教程hook 教程hook 教程hook 教程hook 教程hook 教程hook 教程...
hook api,hook CreateFile,hook CloseHandle,hook ReadFile,hook WriteFile,hook LoadLibrary
HookAPI HookAPI HookAPI HookAPI
远程hook 远程hook 远程hook 远程hook 远程hook 远程hook
ssdthook
HOOK 系统注册表 HOOK API SYSTEM REGISTRY 文件清单: PHookRegistry.exe HOOK管理主程序 PNtHOOK.dll HOOK API DLL 功能描述: 1. 只针对用户级别的程序API陷井式HOOK, 这里只对以下API进行HOOK: ...
这是一个Hook WinSocket的例子,只在原理性述如何Hook API。 直接注入就可以使用了 sdddddddddddddddd
API hook API hook API hook
Windows miniHook hookapi demo
hook,apihook,inlinehook
含内核HOOK 的 easyhook,可用于C#等语言支持
Hook经典分析 关于QQ Hook的应用 钩子
ApiHook 技术大全 ApiHook 技术大全 ApiHook 技术大全
原文地址http://blog.csdn.net/xugangjava/article/details/14001685, 使用Detour3.0在Hook其他进程的MessageBox。
Easyhook demo 供大家学习和参考
包含3个教程,易语言Hook教程,Hook教学实战等,包含PC2.6 Hook全功能版
hook c++ hook c++ hook c++ hook c++ hook c++
这是学习Hook编程的好实例。有很多的Hook实例,Net方面的,文件系统方面的,注册表方面的,等等,可以算是一个HOOKAPI大全了!