cogs 2633. [HZOI 2016] Sequence operation e

2633. [HZOI 2016] Sequence operation e

★★★ ☆ Input file: rneaty.in   Output file: rneaty.out   a simple comparison of
the time limit: 1 s memory limit: 128 MB

Description [title]

 

A sequence of length n, a weight value of the start sequence are 0, m has operations

It supports two modes of operation,

1 LR x, to the interval [L, R], plus a first number x, the second number plus 2 2 X , plus the third number . 3 2 X ... R-L + 1 of the number of plus ( R & lt - L + . 1 ) 2 X

In weight and 2 LR query interval [L, R]

Each time the answer to the inquiry 2 64 modulo

 

[Input Format]

 

The first line of the two numbers n, m, represents the sequence length and the number of operations

Subsequently m rows, each row describes an operation, the following two situations:

 

1 LR x, to the interval [L, R], plus a first number x, the second number plus 2 2 X , plus the third number . 3 2 X ... R-L + 1 of the number of plus ( R & lt - L + . 1 ) 2 X

In weight and 2 LR query interval [L, R]

 

[Output format]

In order to reduce the output, you only need to output all the answers to 2 64 after the film is taken and XOR.

[Sample input]

5 5

1 3 4 1

2 1 5

2 2 2

1 3 3 1

1 2 4 1

[Sample output]

5

【prompt】

 

For 10% of the data n, m <= 2000

For 30% of the data n, m <= 10000

To 100% of the data, n-, m <= 100000,1 <= L <= R & lt <= n-, 0 <= X <= 10 . 9

 

【source】

A name is very long konjac

 

 

Permanent marker segment tree QAQ

This method is the first subject of questions in the open formula

This may eventually split into: i ^ 2 * x + i * 2 (1-L) * x + (L-1) ^ 2 * x

Then we fight for every mark a lz

At the same time some stuff first pretreatment

The first example may be pretreated an i ^ 2

The second term may be pretreated i * 2 * (1-L)

A third can be pretreated (L-1) ^ 2 // fact, no pretreatment 

 

We then split open after a simple formula more

 

There are several complementary knowledge

1.unsigned long long is automatically modulo 2 ^ 64

2. Be sure to pay attention to prevent the type of explosive intQAQ such that i ^ 2 will i * 1ull * i the job (otherwise 30 points)

code show as below

♪(^∇^*)

 

#include<bits/stdc++.h>
#define maxn 100005
#define LL unsigned long long
#define mid (l+r>>1)
using namespace std;
int n,m;
int RT;
int cnt;//标记 下标 
int ls[maxn<<1],rs[maxn<<1];
LL lz0[maxn<<1],lz1[maxn<<1],lz2[maxn<<1];
LL sum[maxn<<1];
LL s1[maxn],s2[maxn];
void Build(int &rt,int l,int r)
{
    if(!rt) 
        rt=++cnt;
    if(l==r)
        return;
    Build(ls[rt],l,mid);
    Build(rs[rt],mid+1,r);
}
LL ans;
void Add(int rt,int l,int r,int s,int t,LL x2,LL x1,LL x0)
{
    if(s>r||t<l)
        return;
    if(s<=l&&r<=t)
    {
        lz2[rt]+=x2;
        lz1[rt]+=x1;
        lz0[rt]+=x0;
        sum[rt]=sum[ls[rt]]+sum[rs[rt]]+lz2[rt]*(s2[r]-s2[l-1])+lz1[rt]*(s1[r]-s1[l-1])+lz0[rt]*(r-l+1);
        return;
    }
    Add(ls[rt],l,mid,s,t,x2,x1,x0);
    Add(rs[rt],mid+1,r,s,t,x2,x1,x0);
    sum[rt]=sum[ls[rt]]+sum[rs[rt]]+lz2[rt]*(s2[r]-s2[l-1])+lz1[rt]*(s1[r]-s1[l-1])+lz0[rt]*(r-l+1);
    return;
}
LL Sum(int rt,int l,int r,int s,int t)
{
    if(s>r||t<l)
        return 0;
    if(s<=l&&r<=t)    return sum[rt];
    int ll=max(l,s);
    int rr=min(r,t);
    return Sum(ls[rt],l,mid,s,t)+Sum(rs[rt],mid+1,r,s,t)+lz2[rt]*(s2[rr]-s2[ll-1])+lz1[rt]*(s1[rr]-s1[ll-1])+lz0[rt]*(rr-ll+1);
}
int main()
{
    freopen("rneaty.in","r",stdin);
    freopen("rneaty.out","w",stdout);
    scanf("%d%d",&n,&m);
    Build(RT,1,n);
    for(int i=1;i<=n;i++)
    {
        s1[i]=s1[i-1]+i;
        s2[i]=s2[i-1]+i*1ull*i;
    }
    while(m--)
    {
        int opt,L,R;
        scanf("%d%d%d",&opt,&L,&R);
        if(opt==1)
        {
            LL x;
            scanf("%llu",&x);
            //i^2*x + i*2(1-L)*x +(L-1)^2*x 
            //1^2 + 2^2 +3^2 +..+n^2   =n*(n+1)*(2n+1)/6
            Add(1,1,n,L,R,x,x*2*(1ull-L),(L-1)*x*(L-1)) ;
        }
        else
            ans^=Sum(1,1,n,L,R);
    }
    printf("%llu\n",ans);
    return 0;
}
Hurry up and Chou Chou ♪ (^ ∇ ^ *)

 

 

 

Guess you like

Origin www.cnblogs.com/Tidoblogs/p/11344147.html