Just a Hook
来源:互联网 发布:nginx 流量统计 编辑:程序博客网 时间:2024/06/05 02:11
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.
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.
11021 5 25 9 3
Case 1: The total value of the hook is 24.
题意:给一段长度为n的棒,初始表面为铜,单价为1,在这段棒上涂上银或者金,单价分别为2,3;问最后这段棒的价值;区间更新,lazy思想;
#include<cstdio>#include<cstring>#include<iostream>#include<algorithm>#include<queue>using namespace std;const int MAXN=100000+10;const int inf=0x3f3f3f;int n,m;struct node{ int left,right; int value,sum;}z[4*MAXN];void build(int i,int left,int right){ z[i].left=left; z[i].right=right; if(left==right) { z[i].value=1; z[i].sum=1; return ; } int mid=(z[i].left+z[i].right)/2; build(i<<1,left,mid); build((i<<1)+1,mid+1,right); z[i].value=z[i<<1].value+z[(i<<1)+1].value; z[i].sum=1;}void update(int i,int left,int right,int num){ if(z[i].sum==num) return ; if(z[i].left==left&&z[i].right==right) { z[i].value=num*(right-left+1); z[i].sum=num; return ; } if(z[i].sum) { int l1=z[i<<1].right-z[i<<1].left+1; int l2=z[(i<<1)+1].right-z[(i<<1)+1].left+1; z[i<<1].value=l1*z[i].sum; z[(i<<1)+1].value=l2*z[i].sum; z[i<<1].sum=z[i].sum; z[(i<<1)+1].sum=z[i].sum; z[i].sum=0; } int mid=(z[i].left+z[i].right)/2; if(right<=mid) update(i<<1,left,right,num); else if(left>mid) update((i<<1)+1,left,right,num); else if(left<=mid&&right>mid) { update(i<<1,left,mid,num); update((i<<1)+1,mid+1,right,num); } else return ; z[i].value=z[i<<1].value+z[(i<<1)+1].value;}int main(){ int T,t=0; scanf("%d",&T); while(T--) { scanf("%d%d",&n,&m); int a,b,c; build(1,1,n); while(m--) { scanf("%d%d%d",&a,&b,&c); update(1,a,b,c); } printf("Case %d: The total value of the hook is %d.\n",++t,z[1].value); }}
阅读全文
0 0
- hdu1698 Just a Hook
- HDU1689 Just a Hook
- Just a Hook
- hdu Just a Hook
- hdu1698 Just a Hook
- [HDU1698]Just a Hook
- hdu_1698 Just a Hook
- hdu1698 Just a Hook
- Just a Hook
- Just a Hook
- Just a Hook
- hdu1698 Just a Hook
- HDU1698 Just a Hook
- HDU Just a Hook
- hdu1698 Just a Hook
- HDU1698 Just a Hook
- Just a Hook
- Just a Hook
- MySQL的MVCC
- 更换MyEclipse10项目中的JRE Syetem Library
- 函数需要声明的情况
- js中apply和call的用法和区别
- 运维监控之路
- Just a Hook
- 在云服务器CentOS上使用Cloudera Manager安装CDH5.9.0
- .net HtmlAgilityPack解析返回的html字符串
- QPaintEvent的性能
- libfacedetection最简单粗暴的配置方法
- sed命令【转】
- python的/与//
- hdu problem1166 (树状数组)
- python学习(3)scrapy