cogs 2632. [HZOI 2016] d series operation

2632. [HZOI 2016] d series operation

★★★ Input file: segment.in   Output file: segment.out   a simple comparison of
the time limit: 3 s memory limit: 512 MB

Description [title]

A length n of the sequence, a sequence beginning weights are number 0 , there are m operations

It supports two modes of operation:

1 LR x, to the interval [L, R] position plus the number of pos (pos-L) * x

In weight and 0 LR, inquiry interval [L, R]

The final answer to 10 . 9 + 7 mod.

[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] position plus the number of pos ( P O S - L ) × X

In weight and 0 LR, inquiry interval [L, R]

[Output format]

Each an integer 0 output operation mode 10 . 9 + 7

[Sample input]

5 5
0 2 3
1 4 5 1
1 1 5 5
0 1 4
0 2 3

[Sample output]

0
30
15 

【prompt】

Data for 30%  n- , m <= 2000

To 100% of the data, n- , m <= 300000

Are read to ensure non-negative integer, all X <= 10000

【source】

Thank God for Ben
Thank God Ben

Ben very, very grateful to God

 

 
   

 

 

 

#include <bits / STDC ++ H.>
 #define LL Long Long
 #define INF 1000000007
 #define MAXN 300005
 the using  namespace STD; 
LL S [MAXN]; 
LL LZ1 [MAXN << 2 ], LZ2 [MAXN << 2 ]; / / LZ1 is the recording of lz2 -L * x is the pos * x recording   
LL DAT [MAXN << 2 ];
 void the Add ( int RT, int L, int R & lt, int SS, int TT, QX LL, LL POSX) { 
     iF (SS> || R & lt TT <L) return ; // determines whether bounds 
    iF (SS <= R & lt && L <= TT) {// all included 
        LZ1 [RT] = (LZ1 [RT] + QX) INF%; // permanent marker 
        LZ2 [RT] = (LZ2 [RT] + POSX)% INF; 
        DAT [RT] = (DAT [RT ] + QX * (L-R & lt + . 1 ) + INF POSX% * ((S [R & lt] -S [L- . 1 ]) INF%)% INF) INF%; // (S [R & lt] -S [L- 1]) that is the period of pre-processing arithmetic sequence of number and make a difference out of the direct line of   
        return ; 
    } 
    int MID = (L + R & lt) >> 1 ; 
    the Add (RT * 2 , L, MID, SS, TT, QX, POSX); the Add (RT * 2 + . 1 , MID + . 1 , R & lt, SS, TT, QX, POSX); 
    DAT [RT] = (DAT [RT * 2 ] + DAT [RT * 2 + . 1]+lz1[rt]*(r-l+1)%INF+lz2[rt]*((S[r]-S[l-1])%INF)%INF)%INF;
}
ll Get(int rt,int l,int r,int ss,int tt){
    if(ss>r||tt<l) return 0;
    if(ss<=l&&r<=tt) return dat[rt];
      int lll=max(l,ss);
    int rr=min(r,tt);
    int mid=(l+r)>>1;
    return (lz1[rt]*(rr-lll+1)%INF+lz2[rt]*((S[rr]-S[lll-1])%INF)%INF+Get(rt*2,l,mid,ss,tt)+Get(rt*2+1,mid+1,r,ss,tt))%INF;
}
int main(){
    freopen("segment.in","r",stdin);freopen("segment.out","w",stdout);
    int n,m;scanf("%d%d",&n,&m);//输入 不说了 哈哈 
    for(int i=1;i<=n;i++) S[i]=S[i-1]+i;//This is pretreated a prefix and 
    for ( int I = . 1 ; I <= m; I ++ ) {
         int the Type; Scanf ( " % D " , & the Type);
         IF (the Type) {
             int L, R & lt; LL X, POSX ; Scanf ( " % D% D% LLD " , & L, R & lt &, & X); 
            POSX = (INF-L) * X% INF; // POSX -L here is that a plus INF is because --L negative numbers fried! ! 
            The Add ( . 1 , . 1 , n-, L, R & lt, POSX, X); 
        } 
        the else {
             int L, R & lt; Scanf ( " % D% D " , L &, &r);
            printf("%lld\n",Get(1,1,n,l,r)%INF);
        }
    }
    return 0;
}

 

Guess you like

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