某个英雄有这样一个金属长棍,这个金属棍有很多相同长度的短棍组成,大概最多有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 = ; struct Hook{int l, r, z;}hook[maxn];
struct Tree{
    int L, R;
    int isCover;//等于1的时候被覆盖,等于2的时候区间下面有被覆盖的
    int Mid(){return (L+R)/;}
    int Len(){return (R-L+);}
}tree[maxn*]; 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<<].isCover ==  && tree[root<<|].isCover == )
        tree[root].isCover = ;
}
int  Insert(int root, int L, int R)
{
    if(tree[root].isCover == )return ;     if(tree[root].L == L && tree[root].R == R && !tree[root].isCover)
    {
        tree[root].isCover = ;
        return tree[root].Len();
    }
    tree[root].isCover = ;     int ans = ;     if(R <= tree[root].Mid())
        ans = Insert(root<<, L, R);
    else if(L > tree[root].Mid())
        ans = Insert(root<<|, L, R);
    else
        ans = Insert(Lson)+Insert(Rson);     Up(root);     return ans;
} int main()
{
    int i, T, t=;     scanf("%d", &T);     while(T--)
    {
        int N, M;         scanf("%d%d", &N, &M);
        Build(, , N);         for(i=; i<=M; i++)
            scanf("%d%d%d", &hook[i].l, &hook[i].r, &hook[i].z);         int ans = N;         for(i=M; i>; i--)
        {
            int len = Insert(, 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 ; } 

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

  1. Just a Hook (HDU 1698) 懒惰标记

    Just a Hook (HDU 1698) 题链 每一次都将一个区间整体进行修改,需要用到懒惰标记,懒惰标记的核心在于在查询前才更新,比如将当前点rt标记为col[rt],那么此点的左孩子和右孩子标 ...

  2. HDU 3397 区间覆盖,颠倒,合并(好题)

    http://acm.hust.edu.cn/vjudge/problem/14689 三个操作 [a,b]覆盖为0 [a,b]覆盖为1 [a,b]颠倒每项 两个查询 [a,b]间1数量 [a,b]间 ...

  3. E - Just a Hook HDU - 1698 线段树区间修改区间和模版题

    题意  给出一段初始化全为1的区间  后面可以一段一段更改成 1 或 2 或3 问最后整段区间的和是多少 思路:标准线段树区间和模版题 #include<cstdio> #include& ...

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

    #include<cstdio> #include<cstring> #include<iostream> #include<algorithm> us ...

  5. HDU 1698 区间更新

    Just a Hook Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total ...

  6. hdu 1698区间延迟更新

    #include<stdio.h> #define N 100100 struct node { int x,y,yanchi; }a[N*4];//注意数组范围 void build(i ...

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

    题目地址:pid=1698">HDU 1698 区间替换裸题.相同利用lazy延迟标记数组,这里仅仅是当lazy下放的时候把以下的lazy也所有改成lazy就好了. 代码例如以下: # ...

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

    题目链接 题意 : 一个有n段长的金属棍,开始都涂上铜,分段涂成别的,金的值是3,银的值是2,铜的值是1,然后问你最后这n段总共的值是多少. 思路 : 线段树的区间更新.可以理解为线段树成段更新的模板 ...

  9. HDU 1698——Just a Hook——————【线段树区间替换、区间求和】

    Just a Hook Time Limit:2000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Submit  ...

随机推荐

  1. Python开发【第一篇】:目录

    本系列博文包含 Python基础.前端开发.Web框架.缓存以及队列等,希望可以给正在学习编程的童鞋提供一点帮助!!! Python开发[第一篇]:目录 Python开发[第二篇]:初识Python ...

  2. ADO.NET基础

    using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.W ...

  3. 简单图片banner轮播

    /**************[css]****************/   <style type="text/css">        *{margin:0px; ...

  4. JAVA 读取pdf文件

    第一个路口action /* * wuhan syspro author zhangrui 2010/08/23 */ package jp.co.syspro.poo.action; import ...

  5. JavaScript—window对象使用

    window对象是JavaScript浏览器对象模型中的顶层对象,包含多个常用方法和属性: 1. 打开新窗口 window.open(pageURL,name,parameters) 其中:pageU ...

  6. C# Word常用操作(转)格式设置

    一.word文档表格操作.分页及换行 //合并单元格table.Cell(2, 2).Merge(table.Cell(2, 3)); //单元格分离 object Rownum = 2;object ...

  7. linux command cp.

    Examples cp file1.txt newdir Copies the file1.txt in the current directory to the newdir subdirector ...

  8. 【USACO 1.3.2】修理牛棚

    [描述] 在一个夜黑风高,下着暴风雨的夜晚,farmer John的牛棚的屋顶.门被吹飞了. 好在许多牛正在度假,所以牛棚没有住满. 牛棚一个紧挨着另一个被排成一行,牛就住在里面过夜. 有些牛棚里有牛 ...

  9. 妙用git rebase --onto指令

    有时候,在分支提交更改的时候,会忘记rebase,就直接提交上去,或者忘记和本地远程分支做merge,就直接rebase了别的分支.有时候真希望有一种切片的方式,让自己的分支只需要接上某一段.这个时候 ...

  10. sublime常用插件及配置,自留自用

    1.Angularjs 写angularjs经常操作template文件,没有一个ng-xx的提示真的很蛋疼是不是,有些服务的名字记不住是不是,那就用这个插件吧 2.AutoFileName 如果你的 ...