HDU 1698 Just a Hook
来源:互联网 发布:投资软件 编辑:程序博客网 时间:2024/06/06 11:42
http://acm.hdu.edu.cn/showproblem.php?pid=1698
Total Submission(s): 18946 Accepted Submission(s): 9512
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
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.
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.
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
11021 5 25 9 3
Sample Output
Case 1: The total value of the hook is 24.
Source
2008 “Sunline Cup” National Invitational Contest
Recommend
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;
}
0 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
- 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
- POJ 2828 Buy Tickets
- POJ 3468 A Simple Problem with Integers(区间更新)
- Can you find it?(二分)
- POJ 3264 Balanced Lineup(RMQ)
- POJ 3368 Frequent values (RMQ)
- HDU 1698 Just a Hook
- HDU 3974 Assign the task
- POJ 3321 Apple Tree
- POJ 2155 Matrix(二维线段树)
- 加载顺序,一个类的
- HDU 2492 Ping pong
- POJ 2299 Ultra-QuickSort
- POJ 1394 Minimum Inversion Number
- javascript、JavaWeb、URL的区别联系