E - Just a Hook - hdu 1698(区间覆盖)

某个英雄有这样一个金属长棍,这个金属棍有很多相同长度的短棍组成,大概最多有10w节,现在这个人有一种魔法,他可以把一段区间的金属棍改变成别的物质,例如金银或者铜, 现在他会有一些操作在这个金属棍上,他想知道这些操作结束后金属棍的质量是多少呢?(PS,一节铜重量1, 银 2 ,金3)。

分析:如果做了那到海报覆盖的题目会发现这两题是差不多的,都可以从后面往前去覆盖,只不过返回这次能覆盖多少节就行了。

*************************************************************************

#include<stdio.h>
#include<math.h>
#include<string.h>
#include<algorithm>
using namespace std;
#define Lson root<<1,L,tree[root].Mid()
#define Rson root<<1|1,tree[root].Mid()+1,R

const int maxn = 100005;

struct Hook{int l, r, z;}hook[maxn];
struct Tree{
    int L, R;
    int isCover;//等于1的时候被覆盖,等于2的时候区间下面有被覆盖的
    int Mid(){return (L+R)/2;}
    int Len(){return (R-L+1);}
}tree[maxn*4];

void Build(int root, int L, int R)
{
    tree[root].L = L, tree[root].R = R;
    tree[root].isCover = false;

if(L == R)return ;

Build(Lson);
    Build(Rson);
}
void Up(int root)
{
    if(tree[root].L != tree[root].R)
    if(tree[root<<1].isCover == 1 && tree[root<<1|1].isCover == 1)
        tree[root].isCover = 1;
}
int  Insert(int root, int L, int R)
{
    if(tree[root].isCover == 1)return 0;

if(tree[root].L == L && tree[root].R == R && !tree[root].isCover)
    {
        tree[root].isCover = 1;
        return tree[root].Len();
    }
    tree[root].isCover = 2;

int ans = 0;

if(R <= tree[root].Mid())
        ans = Insert(root<<1, L, R);
    else if(L > tree[root].Mid())
        ans = Insert(root<<1|1, L, R);
    else
        ans = Insert(Lson)+Insert(Rson);

Up(root);

return ans;
}

int main()
{
    int i, T, t=1;

scanf("%d", &T);

while(T--)
    {
        int N, M;

scanf("%d%d", &N, &M);
        Build(1, 1, N);

for(i=1; i<=M; i++)
            scanf("%d%d%d", &hook[i].l, &hook[i].r, &hook[i].z);

int ans = N;

for(i=M; i>0; i--)
        {
            int len = Insert(1, hook[i].l, hook[i].r);
            ans = ans - len + len * hook[i].z;
        }

printf("Case %d: The total value of the hook is %d.\n", t++, ans);
    }

return 0;

}

时间: 2024-11-05 19:41:30

E - Just a Hook - hdu 1698(区间覆盖)的相关文章

Just a Hook HDU - 1698Just a Hook HDU - 1698 线段树区间替换

#include<cstdio> #include<cstring> #include<iostream> #include<algorithm> using namespace std; typedef long long ll; const int N=1e5+10; struct node{ int l,r; int sum; int add; }tr[N*4]; void pushdown(int root) { if (tr[root].add)

E - Just a Hook HDU - 1698

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1698 通过这个题练习了基本的Pushdown的操作 参考着蓝书的模板敲了一下,需要修改的地方就是:这里的区间修改是直接改变值而不是增加值 把+=改成=即可. 1 #include <cmath> 2 #include <queue> 3 #include <string> 4 #include <cstdio> 5 #include <cstring>

HDU 1698 区间更新

Just a Hook Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 20532    Accepted Submission(s): 10284 Problem Description In the game of DotA, Pudge’s meat hook is actually the most horrible thing

E - Just a Hook HDU 1698 (线段树+类似延迟标记)

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

Just a Hook HDU - 1698

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 th

HDU 1698 Just a Hook(线段树区间替换)

题目地址:HDU 1698 区间替换裸题.同样利用lazy延迟标记数组,这里只是当lazy下放的时候把下面的lazy也全部改成lazy就好了. 代码如下: #include <iostream> #include <cstdio> #include <string> #include <cstring> #include <stdlib.h> #include <math.h> #include <ctype.h> #in

HDU 1698 Just a Hook (线段树,区间更新)

Just a Hook Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 17214    Accepted Submission(s): 8600 Problem Description In the game of DotA, Pudge’s meat hook is actually the most horrible thing f

HDU - 1698 Just a Hook (线段树区间修改)

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.

hdu 1698:Just a Hook(线段树,区间更新)

Just a Hook Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 15129    Accepted Submission(s): 7506 Problem Description In the game of DotA, Pudge's meat hook is actually the most horrible thing f