• bzoj1251


    1251: 序列终结者

    Time Limit: 20 Sec  Memory Limit: 162 MB
    Submit: 3776  Solved: 1581
    [Submit][Status][Discuss]

    Description

    网上有许多题,就是给定一个序列,要你支持几种操作:A、B、C、D。一看另一道题,又是一个序列 要支持几种操作:D、C、B、A。尤其是我们这里的某人,出模拟试题,居然还出了一道这样的,真是没技术含量……这样 我也出一道题,我出这一道的目的是为了让大家以后做这种题目有一个“库”可以依靠,没有什么其他的意思。这道题目 就叫序列终结者吧。 【问题描述】 给定一个长度为N的序列,每个序列的元素是一个整数(废话)。要支持以下三种操作: 1. 将[L,R]这个区间内的所有数加上V。 2. 将[L,R]这个区间翻转,比如1 2 3 4变成4 3 2 1。 3. 求[L,R]这个区间中的最大值。 最开始所有元素都是0。

    Input

    第一行两个整数N,M。M为操作个数。 以下M行,每行最多四个整数,依次为K,L,R,V。K表示是第几种操作,如果不是第1种操作则K后面只有两个数。

    Output

    对于每个第3种操作,给出正确的回答。

    Sample Input

    4 4
    1 1 3 2
    1 2 4 -1
    2 1 3
    3 2 4

    Sample Output

    2
    【数据范围】
    N<=50000,M<=100000。

    HINT

    Source

    平衡树 懒标记

    #include<cstdio>
    #include<cstring>
    using namespace std;
    #define lowbit(x) x&-x
    #define N 200010
    typedef long long ll;
    int n,q;
    ll sum[N],t1[N],t2[N];
    void add1(int pos,int delta)
    {
        for(int i=pos;i<=n;i+=lowbit(i))
            t1[i]+=delta;
    }
    void add2(int pos,int delta)
    {
        for(int i=pos;i<=n;i+=lowbit(i))
            t2[i]+=delta;
    }
    ll sum1(int pos)
    {
        ll ret=0;
        for(int i=pos;i>0;i-=lowbit(i))
            ret+=t1[i];
        return ret;
    }
    ll sum2(int pos)
    {
        ll ret=0;
        for(int i=pos;i>0;i-=lowbit(i))
            ret+=t2[i];
        return ret;
    }
    int main()
    {
        scanf("%d",&n);
        for(int i=1;i<=n;i++)
        {
            scanf("%d",&sum[i]);
            sum[i]+=sum[i-1];
        }
        scanf("%d",&q);
        while(q--)
        {
            int opt,a,b; scanf("%d%d%d",&opt,&a,&b);
            if(opt==1)
            {
                int x; scanf("%d",&x);
                add1(a,-(a-1)*x);
                add1(b+1,b*x);
                add2(a,x);
                add2(b+1,-x);
            }
            else 
            {
                printf("%lld
    ",sum[b]-sum[a-1]+sum1(b)-sum1(a-1)+sum2(b)*b-sum2(a-1)*(a-1));
            }
        }
        return 0;
    }
  • 相关阅读:
    python练习册 每天一个小程序 第0006题
    python练习册 每天一个小程序 第0005题
    [happyctf]部分writeup
    python练习册 每天一个小程序 第0004题
    [实验吧](web)因缺思厅的绕过 源码审计绕过
    python练习册 每天一个小程序 第0002题
    poj2185 Milking Grid
    hdu1711 Number Sequence
    poj1961 Period
    lightOJ 1017 Brush (III) DP
  • 原文地址:https://www.cnblogs.com/19992147orz/p/6209535.html
Copyright © 2020-2023  润新知