Just a Hook

Time Limit:2000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u


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"cstdio"
#include"cstring"
using namespace std;
const int MAXN=;
struct Node{
int l,r;
int lazy,sum;
}a[MAXN*]; void build(int rt,int l,int r)
{
a[rt].l=l;
a[rt].r=r;
a[rt].lazy=;
if(l==r){
a[rt].sum=;
return ;
}
int mid=(l+r)>>;
build(rt<<,l,mid);
build((rt<<)|,mid+,r);
a[rt].sum=a[rt<<].sum+a[(rt<<)|].sum;
} void PushDown(int rt)
{
int mid=(a[rt].l+a[rt].r)>>;
a[rt<<].lazy=a[(rt<<)|].lazy=a[rt].lazy;
a[rt<<].sum=a[rt].lazy*(mid-a[rt].l+);
a[(rt<<)|].sum=a[rt].lazy*(a[rt].r-mid);
a[rt].lazy=;
} void update(int rt,int l,int r,int val)
{
if(a[rt].l==l&&a[rt].r==r)
{
a[rt].lazy=val;
a[rt].sum=val*(r-l+);
return ;
} if(a[rt].lazy) PushDown(rt); int mid=(a[rt].l+a[rt].r)>>;
if(r<=mid) update(rt<<,l,r,val);
else if(mid<l) update((rt<<)|,l,r,val);
else{
update(rt<<,l,mid,val);
update((rt<<)|,mid+,r,val);
}
a[rt].sum=a[rt<<].sum+a[(rt<<)|].sum;
} int main()
{
int T;
scanf("%d",&T);
for(int cas=;cas<=T;cas++)
{
int n;
scanf("%d",&n);
build(,,n);
int m;
scanf("%d",&m);
while(m--)
{
int x,y,z;
scanf("%d%d%d",&x,&y,&z);
update(,x,y,z);
}
printf("Case %d: The total value of the hook is %d.\n",cas,a[].sum);
}
return ;
}

最新文章

  1. linux 文件系统sysvinit 流程分析
  2. nullcon HackIM2016 -- Programming Question 3
  3. Java之内存分析和String对象
  4. DOS下无法调出中文输入法-Solved
  5. java基础笔记
  6. Kobject结构体分析
  7. 【转】lua Date和Time
  8. 游戏对象的变换-Transform
  9. Ubuntu 12.04搭建MTK 6577 安卓开发环境
  10. JQuery日记_5.13 Sizzle选择器(六)选择器的效率
  11. 用tp框架来对数据库进行增删改
  12. yum升级mysql
  13. kibana使用
  14. redis list命令操作
  15. 启动bind失败
  16. hdu1576-A/B-(同余定理+乘法逆元+费马小定理+快速幂)
  17. Hadoop 5 Hbase 遇到的问题
  18. 配置Tomcat apr运行模式
  19. MySQL5.7.10配置和使用
  20. Spring界的HelloWorld

热门文章

  1. 7 Javascript:表单与验证-非空验证
  2. Java进阶学习:JSON解析利器JackSon
  3. 2018年长沙理工大学第十三届程序设计竞赛 C 取手机 【概率】
  4. HackerRank - camelcase 【字符串】
  5. Hadoop2.x + eclipse 插件配置
  6. Oracle数据库体系结构(6)数据库归档重做日志文件管理
  7. Sql Server2008——存储过程编程简单例子
  8. python 3 封装
  9. alpine安装更新
  10. android电池(五):电池 充电IC(PM2301)驱动分析篇【转】