zoukankan      html  css  js  c++  java
  • Hdu1698Just a Hook线段树区间更新

      区间更新基础。。不说了,也是照着notonlysuccess的博客撸的。

    #include <cstdio>
    #include <cstring>
    #include <algorithm>
    #include <climits>
    #include <string>
    #include <iostream>
    #include <map>
    #include <cstdlib>
    #include <list>
    #include <set>
    #include <queue>
    #include <stack>
    
    using namespace std;
    #define lson l,mid,rt<<1
    #define rson mid+1,r,rt<<1|1
    int sum[444444];
    int color[444444];
    void up(int rt)
    {
        sum[rt] = sum[rt << 1] + sum[rt << 1 | 1];
    }
    
    void down(int rt, int len)
    {
        if (color[rt]){
            color[rt << 1] = color[rt << 1 | 1] = color[rt];
            int mid = len / 2;
            sum[rt << 1] = (len - mid) * color[rt];
            sum[rt << 1 | 1] = (mid)*color[rt];
            color[rt] = 0;
        }
    }
    void build(int l, int r, int rt)
    {
        color[rt] = 0;
        if (l == r){
            sum[rt] = 1; return;
        }
        int mid = (l + r) >> 1;
        build(lson);
        build(rson);
        up(rt);
    }
    
    void update(int L, int R, int add, int l, int r, int rt)
    {
        if (L <= l&&r <= R){
            sum[rt] = (r - l + 1) * add; color[rt] = add;
            return;
        }
        int mid = (l + r) >> 1;
        down(rt, r - l + 1);
        if (L <= mid) update(L, R, add, lson);
        if (R>mid) update(L, R, add, rson);
        up(rt);
    }
    
    int main()
    {
        int Icase; int tt = 0;
        cin >> Icase;
        int n, m; int a, b, c;
        while (Icase--){
            scanf("%d", &n); build(1, n, 1);
            scanf("%d", &m);
            for (int i = 0; i<m; i++){
                scanf("%d%d%d", &a, &b, &c);
                update(a, b, c, 1, n, 1);
            }
            printf("Case %d: The total value of the hook is ", ++tt);
            printf("%d.
    ", sum[1]);
        }
        return 0;
    }
  • 相关阅读:
    性能测试
    怎样开始用selenium进行自动化测试
    手机自动化测试的原理
    黑盒测试与白盒测试的区别
    白盒测试方法
    黑盒测试概念及设计方法
    接口测试的概念及常用方法
    运用c语言和Java写九九乘法表
    appium键值对的应用
    压力测试和负载测试的区别
  • 原文地址:https://www.cnblogs.com/yigexigua/p/3928256.html
Copyright © 2011-2022 走看看