(hdu 1698) Just a Hook(区间更新)
来源:互联网 发布:东风153抢险救援车数据 编辑:程序博客网 时间:2024/05/21 11:05
Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 34260 Accepted Submission(s): 16716
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.
Source
2008 “Sunline Cup” National Invitational Contest
题意:一个钩有铜,银,金三种棍子,重分别为1,2,3
给定n,q,开始[1,n]内都是铜棍,经过q次[x,y]内的更新后,问钩多重?
分析:区间更新,直接把[x,y]内的数值 置为 z
注意输出的标点符号!!! 找这种bug 可以让自己怀疑题目错了。。。 噗
1341MS 5972K 1675 B C++
#include<cstdio>#include<cstring>#include<algorithm>using namespace std;#define lson l,m,rt<<1#define rson m+1,r,rt<<1|1typedef long long LL;const LL N=1e5+5;LL sum[N<<2],a[N],MAX[N<<2],ad[N<<2];void pushup(LL rt){ sum[rt]=sum[rt<<1]+sum[rt<<1|1]; // MAX[rt]=max(MAX[rt<<1],MAX[rt<<1|1]);}void pushdown(int rt,int m){ if(ad[rt]) { ad[rt<<1]=ad[rt]; ad[rt<<1|1]=ad[rt]; sum[rt<<1]=ad[rt]*(m-(m>>1)); sum[rt<<1|1]=ad[rt]*(m>>1); ad[rt]=0; }}void build(LL l,LL r,LL rt){ ad[rt]=0; if(l==r) { sum[rt]=1; return ; } LL m=(l+r)>>1; build(lson); build(rson); pushup(rt);}void update(LL L,LL R,LL c,LL l,LL r,LL rt){ if(L<=l&&R>=r) { ad[rt]=c; sum[rt]=c*(r-l+1); return ; } pushdown(rt,r-l+1); LL m=(l+r)>>1; if(L<=m) update(L,R,c,lson); if(R>m) update(L,R,c,rson); pushup(rt);}LL query(LL L,LL R,LL l,LL r,LL rt){ if(L<=l&&R>=r) { return sum[rt]; } pushdown(rt,r-l+1); LL m=(l+r)>>1; LL ret=0; if(L<=m) ret+=query(L,R,lson); if(R>m) ret+=query(L,R,rson); return ret;}int main(){ int t,cas=1; scanf("%d",&t); while(t--) { int n,q; scanf("%d%d",&n,&q); build(1,n,1); for(int i=0;i<q;i++) { LL x,y,z; scanf("%lld%lld%lld",&x,&y,&z); update(x,y,z,1,n,1); } printf("Case %d: The total value of the hook is %lld.\n",cas++,query(1,n,1,n,1)); } return 0;}
- (hdu 1698) Just a Hook(区间更新)
- 线段树(区间更新) hdu-1698-Just a Hook
- hdu 1698 Just a Hook(线段树-区间更新)
- HDU 1698 Just a Hook (线段树区间更新)
- HDU 1698 Just a Hook (线段树区间更新)
- HDU 1698 Just a Hook(区间更新)
- HDU 1698 Just a Hook(线段树区间更新)
- HDU-1698 Just a Hook(区间更新)
- HDU 1698 Just a Hook (线段树,区间更新)
- RE:HDU 1698 Just a Hook(区间更新)
- HDU 1698 Just a Hook (线段树区间更新)
- hdu 1698 Just a Hook(区间更新)
- HDU 1698 Just a Hook(线段树---区间更新)
- Just a Hook (hdu 1698 线段树区间更新)
- HDU-1698 Just a Hook(线段树区间更新)
- HDU 1698 Just a Hook (线段树区间更新)
- HDU-1698-Just a Hook-区间更新
- hdu 1698 Just a Hook (区间更新)
- 火狐浏览器下 返回顶部功能bug
- 线性模型
- NIO入门
- sqlserver数据库中如果对数值型的字段进行小数点保留两位,如果是小于1的数,前面的0消失解决方案
- [Leetcode-53]Maximum Subarray 最大子数组和
- (hdu 1698) Just a Hook(区间更新)
- js如何判断QQ号码是否输入正确?
- 切片上传视频
- php 断点视频上传
- scala中的io使用
- HDU 1686 Oulipo【KMP模板题】
- HDU 1505 City Game——递推
- JAVA设计模式之二:工厂模式(简单工厂模式+工厂方法模式)
- no modules name gevent