HDU 1698 Just a Hook
2016-04-21 18:58
441 查看
http://acm.hdu.edu.cn/showproblem.php?pid=1698
Total Submission(s): 18946 Accepted Submission(s): 9512
[align=left]Problem Description[/align]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.
![](http://acm.hdu.edu.cn/data/images/C116-1010-1.JPG)
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.
[align=left]Input[/align]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.
[align=left]Output[/align]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.
[align=left]Sample Input[/align]1
10
2
1 5 2
5 9 3
[align=left]Sample Output[/align]Case 1: The total value of the hook is 24.
[align=left]Source[/align]2008 “Sunline Cup” National Invitational Contest
[align=left]Recommend[/align]wangye 延迟标记
Just a Hook
Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 18946 Accepted Submission(s): 9512
[align=left]Problem Description[/align]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.
[align=left]Input[/align]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.
[align=left]Output[/align]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.
[align=left]Sample Input[/align]1
10
2
1 5 2
5 9 3
[align=left]Sample Output[/align]Case 1: The total value of the hook is 24.
[align=left]Source[/align]2008 “Sunline Cup” National Invitational Contest
[align=left]Recommend[/align]wangye 延迟标记
#include<iostream> #include<cstring> #include<algorithm> #include<cstdlib> #include<vector> #include<cmath> #include<stdlib.h> #include<iomanip> #include<list> #include<deque> #include<map> #include <stdio.h> #include <queue> #include <stack> #define maxn 100000+5 #define ull unsigned long long #define ll long long #define reP(i,n) for(i=1;i<=n;i++) #define rep(i,n) for(i=0;i<n;i++) #define cle(a) memset(a,0,sizeof(a)) #define mod 90001 #define PI 3.141592657 #define INF 1<<30 const ull inf = 1LL << 61; const double eps=1e-5; using namespace std; struct node { int l,r; int c; }nod[3*maxn]; void build(int i,int l,int r) { nod[i].l=l; nod[i].r=r; nod[i].c=1; if(l==r) { return ; } int mid=(l+r)/2; build(i<<1,l,mid); build(i<<1|1,mid+1,r); } void add(int i,int a,int b,int c)//改变结点i的区间ab 的值为c { if(nod[i].c==c)return ; if(nod[i].l==a&&nod[i].r==b) { nod[i].c=c; return ; } if(nod[i].c!=-1) { nod[i<<1].c=nod[i].c; nod[i<<1|1].c=nod[i].c; nod[i].c=-1; } int mid=(nod[i].l+nod[i].r)/2; if(b<=mid)add(i<<1,a,b,c); else if(a>mid)add(i<<1|1,a,b,c); else { add(i<<1,a,mid,c); add(i<<1|1,mid+1,b,c); } } int query(int i) { if(nod[i].c!=-1) return (nod[i].r-nod[i].l+1)*nod[i].c; else return query(i<<1)+query(i<<1|1); } int main() { #ifndef ONLINE_JUDGE freopen("in.txt","r",stdin); #endif //freopen("out.txt","w",stdout); int n,t,m; scanf("%d",&t); for(int j=1;j<=t;j++) { scanf("%d",&n); scanf("%d",&m); build(1,1,n); int x,y,z; for(int i=1;i<=m;i++) { scanf("%d%d%d",&x,&y,&z); add(1,x,y,z); } printf("Case %d: The total value of the hook is %d.\n",j,query(1)); } return 0; }
相关文章推荐
- POJ 3368 Frequent values (RMQ)
- POJ 3264 Balanced Lineup(RMQ)
- Can you find it?(二分)
- POJ 3468 A Simple Problem with Integers(区间更新)
- POJ 2828 Buy Tickets
- POJ 2528 Mayor\'s posters
- HDU 5166 Missing number
- 分解质因数
- HDU 5162Jump and Jump...
- Activity之数据恢复
- 括号配对问题
- HDU 5163 Taking Bus
- 面试题目
- 计算机中的负数
- 位运算
- 控制台下画图
- 升级chrome后字体模糊的解决办法
- 学生成绩管理系统(c++)控制台应用程序
- C语言问卷调查
- 跟我学REDIS-REDIS(五)----常用数据类型之SortedSet