E - Just a Hook HDU 1698 (线段树+类似延迟标记)
来源:互联网 发布:方可进销存软件 编辑:程序博客网 时间:2024/05/29 14:28
E - Just a Hook
Time Limit:2000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u
Submit Status Practice
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<bits/stdc++.h>#include<cstdio>#include<algorithm>using namespace std;const int maxn=100011;const int inf=999999999;#define lson (rt<<1),L,M#define rson (rt<<1|1),M+1,R#define M ((L+R)>>1)#define For(i,n) for(int i=0;i<(n);i++)template<class T>inline T read(T&x){ char c; while((c=getchar())<=32); bool ok=false; if(c=='-')ok=true,c=getchar(); for(x=0; c>32; c=getchar()) x=x*10+c-'0'; if(ok)x=-x; return x;}template<class T> inline void read_(T&x,T&y){ read(x); read(y);}template<class T> inline void write(T x){ if(x<0)putchar('-'),x=-x; if(x<10)putchar(x+'0'); else write(x/10),putchar(x%10+'0');}template<class T>inline void writeln(T x){ write(x); putchar('\n');}//-------IO template------typedef long long LL;struct node{ int sum; int val;} p[maxn<<3];void build(int rt,int L,int R){ p[rt].val=0; if(L==R) { p[rt].sum=1; p[rt].val=1; return; } build(lson); build(rson); p[rt].sum=p[rt<<1].sum+p[rt<<1|1].sum;}void update(int rt,int L,int R,int x,int y,int z){ // printf("%d %d %d %d %d %d\n",rt,L,R,x,y,z); if(x==L&&y==R) { p[rt].sum=(R-L+1)*z; p[rt].val=z; return ; } if(p[rt].val>0)//向下更新时,判断条件写好, { p[rt<<1].sum=(M-L+1)*p[rt].val; p[rt<<1|1].sum=(R-M)*p[rt].val;//右儿子 区间是R-M即R-(M+1)+1 p[rt<<1].val=p[rt<<1|1].val=p[rt].val; p[rt].val=0; } if(y<=M) update(lson,x,y,z); else if(x>M) update(rson,x,y,z); else { update(lson,x,M,z); update(rson,M+1,y,z); } p[rt].sum=p[rt<<1].sum+p[rt<<1|1].sum;}int main(){//#ifndef ONLINE_JUDGE // freopen("in.txt","r",stdin);//#endif // ONLINE_JUDGE int T; int n,m,i,j,k,t; read(T); int cas=1; while(T--) { read_(n,m); build(1,1,n); int x,y,z; while(m--) { read_(x,y); read(z); update(1,1,n,x,y,z); } printf("Case %d: The total value of the hook is %d.\n",cas++,p[1].sum); } return 0;}
0 0
- E - Just a Hook HDU 1698 (线段树+类似延迟标记)
- HDU 1698 Just a Hook (线段树延迟标记(lazy))
- 杭电 HDU ACM 1698 Just a Hook(线段树 区间更新 延迟标记)
- HDU 1689 Just a HooK(线段树+延迟标记)
- HDU 1698 JUST a hook (线段树 成段替换 区间求和 延迟标记)
- hdu 1698 Just a Hook(线段树成段更新+延迟标记).
- 【hdu】 Just a Hook (线段树 -成段更新,延迟标记)
- HDU 1698 Just a Hook(线段树延迟更新)
- [线段树]hdu1698 Just a Hook(区间更新、延迟标记
- hdu1698 Just a Hook 线段树更新延迟标记
- HDU 1698Just a Hook(线段树 + Lazy Tag(延迟更新))
- HDU 1698 Just a Hook(线段树+简单lazy标记)
- [ACM] hdu 1698 Just a Hook (线段树,成段更新,懒惰标记)
- HDU 1698 Just a Hook(线段树的区间更新《标记》)
- hdu1689-Just a Hook-线段树-整段区间的替换(延迟标记)
- hdu1698 Just a hook (线段树 延迟标记 区间更新)
- hdu1698-Just a Hook (线段树区间更新)(延迟标记)
- 线段树(类似延迟标记) HDU
- vim plugin NERDTree
- OC-字符串-NSComparisonResult
- c++ 字符串流 sstream(常用于格式转换)
- nefu 84 五指山(扩展欧几里德)
- Android多线程(一)线程池
- E - Just a Hook HDU 1698 (线段树+类似延迟标记)
- ArcGIS教程:如何在ArcMap中将点图层的属性赋给面图层
- C语言 在终端输入多行信息,找出包含“ould”的行,并打印改行
- PRML第六章核方法(核函数)读书笔记(上)
- 使用Application Verifier (AppVerifier)检查资源泄漏
- 安装Xamarin时特有的名词说明
- HTML Meta中添加X-UA-Compatible和IE=Edge,chrome=1有什么作用?
- Ubuntu 14.04 LTS 洗NTFS分区无法访问解决
- javaHL JNI not available