HDU1698

#include <bits/stdc++.h>
using namespace std;
#define Maxn 1001000*4
struct Node{
    int lt,rt,val;
}A[Maxn];
int j = 1;
void Build(int i,int lt,int rt){
    A[i].lt = lt;
    A[i].rt = rt;
    A[i].val = 1;
    if( lt == rt ){
        return ;
    }
    int mid = (lt+rt) >> 1;
    Build(i<<1,lt,mid);
    Build(i<<1|1,mid+1,rt);
}

void update(int i,int lt,int rt,int val){
    if( A[i].val == val ){
        return ;
    }
    if( A[i].lt == lt && A[i].rt == rt ){
        A[i].val = val;
        return ;
    }
    if( A[i].val != -1 ){
        A[i<<1].val = A[i<<1|1].val = A[i].val;
        A[i].val = -1;
    }
    if( rt <= A[i<<1].rt ){
        update(i<<1,lt,rt,val);
    }else if( lt >= A[i<<1|1].lt ){
        update(i<<1|1,lt,rt,val);
    }else{
        update(i<<1,lt,A[i<<1].rt,val);
        update(i<<1|1,A[i<<1|1].lt,rt,val);
    }
}

int find(int i){
    if( A[i].val != -1 ){
        return ( (A[i].rt-A[i].lt+1)*A[i].val);
    }else{
        return ( find(i<<1) + find(i<<1|1) );
    }
}

int main(){
    int T,N,a,b,c;
    cin >> T;
    while(T--){
        scanf("%d",&N);
        Build(1,1,N);
        int n;
        scanf("%d",&n);
        while(n--){
            scanf("%d%d%d",&a,&b,&c);
            update(1,a,b,c);
        }
        printf("Case %d: The total value of the hook is %d.\n",j++,find(1));
    }
}

  

hdu1698(线段树的区间替换)的更多相关文章

  1. hdu1698线段树的区间更新区间查询

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

  2. HDU1698 线段树(区间更新区间查询)

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

  3. 1698-Just a Hook 线段树(区间替换)

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

  4. hdu1698 线段树(区间更新~将区间[x,y]的值替换为z)

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

  5. hdu1698 线段树区间更新

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

  6. Codeforces Round #222 (Div. 1) D. Developing Game 线段树有效区间合并

    D. Developing Game   Pavel is going to make a game of his dream. However, he knows that he can't mak ...

  7. hiho一下20周 线段树的区间修改

    线段树的区间修改 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 对于小Ho表现出的对线段树的理解,小Hi表示挺满意的,但是满意就够了么?于是小Hi将问题改了改,又出给了 ...

  8. 2016年湖南省第十二届大学生计算机程序设计竞赛---Parenthesis(线段树求区间最值)

    原题链接 http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1809 Description Bobo has a balanced parenthes ...

  9. poj 3468:A Simple Problem with Integers(线段树,区间修改求和)

    A Simple Problem with Integers Time Limit: 5000MS   Memory Limit: 131072K Total Submissions: 58269   ...

随机推荐

  1. js json和对象互相转换

    http://www.jb51.net/article/44562.htm obj = JSON.parse(string) | obj = jQuery.parseJSON(str) 将JSON字符 ...

  2. const和define的使用区别

    在PHP中(PHP 4及以后),我们可以使用函数define()来定义常量,例如: <?php define('PI',3.14159);  //定义一个名为PI的常量 echo PI;     ...

  3. 压缩代码加速ecshop程序页面加载速度

    由于页面有很多图片,页面加载速度有点慢,本来打算减小图片的体积,后来想想这个后期还得测试下,所以暂时不打算使用google的图片优化工具,先把ecshop生成的html代码压缩下吧 压缩前:首页体积为 ...

  4. PYTHON 获取机器硬件信息及状态

    #!/usr/bin/env python # encoding: utf-8 from optparse import OptionParser import os import re import ...

  5. 简单的介绍下WPF中的MVVM框架

    最近在研究学习Swift,苹果希望它迅速取代复杂的Objective-C开发,引发了一大堆热潮去学它,放眼望去各个培训机构都已打着Swift开发0基础快速上手的招牌了.不过我觉得,等同于无C++基础上 ...

  6. Linux系统调优

    Linux核心参数都是放置在/proc下面:系统的参数都是放置在/proc/sys swap最好放置在运行最快的硬盘上面,但是swap并能取代ram,因为并有I/O上面的损耗,所以优先考虑检验内存没有 ...

  7. dustjs

    http://akdubya.github.io/dustjs/ https://github.com/linkedin/dustjs

  8. Longest common prefix | leetcode

    Write a function to find the longest common prefix string amongst an array of strings. 思路:要去是寻找字符串ve ...

  9. C语言中.h和.c文件解析(很精彩)

    C语言中.h和.c文件解析(很精彩)   简单的说其实要理解C文件与头文件(即.h)有什么不同之处,首先需要弄明白编译器的工作过程,一般说来编译器会做以下几个过程: 1.预处理阶段 2.词法与语法分析 ...

  10. bzoj 1815: [Shoi2006]color 有色图 置换群

    1815: [Shoi2006]color 有色图 Time Limit: 4 Sec  Memory Limit: 64 MBSubmit: 136  Solved: 50[Submit][Stat ...