# LOJ #6283. Getting started with series partitioning 7,

Source: Internet
Author: User
Tags mul

LOJ #6283. Getting started with series partitioning 7,
Memory limit: 256 MiB time limit: 500 ms standard input/output question type: traditional evaluation method: text comparison uploaded by: hzwer submit Record Statistics Discussion test data question description

A series with a length of nnn and nnn operations are provided. The operations involve interval multiplication, interval addition, and single point inquiry.

Input Format

Enter a number nnn in the first line.

Enter nnn numbers in the second row. the I-th digit is aia_iai, separated by spaces.

Next, enter the nnn line and enter four numbers in each line: opt \ mathrm {opt} opt, lll, rrr, and ccc, separated by spaces.

If opt = 0 \ mathrm {opt} = 0opt = 0, the numbers between [l, r] [l, r] [l, r] are added with ccc.

If opt = 1 \ mathrm {opt} = 1opt = 1, The number between [l, r] [l, r] [l, r] is multiplied by ccc.

If opt = 2 \ mathrm {opt} = 2opt = 2, The ara_rar value mod 10007mod \ 10007mod 10007 is queried (lll and ccc are ignored ).

Output Format

For each query, a row of numbers is output to indicate the answer.

Sample Input
``71 2 2 3 9 3 20 1 3 12 1 3 11 1 4 40 1 7 21 2 6 41 1 6 52 2 6 4``
Sample output
``3100``
Data range and prompt

For data of 100% 100 \ % 100%, 1 ≤ n ≤ 100000, − 231 ≤ others 1 \ leq n \ leq 100000, -2 ^ {31} \ leq \ mathrm {others} 1 ≤ n ≤ 100000, − 231 ≤ others, ans ≤ 231 − 1 \ mathrm {ans} \ leq 2 ^ {31}-1ans ≤ 231 − 1.

Show category labels

Maintain the two tags separately.

According to the calculation Law (this can be used as a substatement), we should first consider multiplication, and then consider addition.

For addition operations, the addition tag of each block is directly added.

For multiplication operations, we need to multiply the multiplication mark and the addition mark by the corresponding value.

Fragmented blocks are hard to record and are directly modified by brute force.

`#include<cstdio>#include<cstring>#include<cmath>#include<algorithm>using namespace std;const int MAXN=1e5+10,mod=10007;inline char nc(){    static char buf[MAXN],*p1=buf,*p2=buf;    return p1==p2&&(p2=(p1=buf)+fread(buf,1,MAXN,stdin)),p1==p2?EOF:*p1++;}inline int read(){    char c=nc();int x=0,f=1;    while(c<'0'||c>'9'){if(c=='-')f=-1;c=nc();}    while(c>='0'&&c<='9'){x=x*10+c-'0';c=nc();}    return x*f;}int a[MAXN],belong[MAXN],L[MAXN],R[MAXN],block,N;int mul[MAXN],add[MAXN];void reset(int x){    for(int i=L[x*block];i<=min(N,R[x*block]);i++)        a[i]=(a[i]*mul[x]+add[x])%mod;    mul[x]=1;add[x]=0;}void Add(int l,int r,int val){    reset(belong[l]);    for(int i=l;i<=min(r,R[l]);i++) a[i]+=val,a[i]%=mod;    if(belong[l]!=belong[r])    {        reset(belong[r]);        for(int i=L[r];i<=r;i++)             a[i]+=val,a[i]%=mod;    }    for(int i=belong[l]+1;i<=belong[r]-1;i++)        add[i]+=val,add[i]%=mod;}void Mul(int l,int r,int val){    reset(belong[l]);    for(int i=l;i<=min(r,R[l]);i++) a[i]*=val,a[i]%=mod;    if(belong[l]!=belong[r])    {        reset(belong[r]);        for(int i=L[r];i<=r;i++)            a[i]*=val,a[i]%=mod;    }            for(int i=belong[l]+1;i<=belong[r]-1;i++)        mul[i]*=val,add[i]*=val,mul[i]%=mod,add[i]%=mod;}int main(){    #ifdef WIN32    freopen("a.in","r",stdin);    #else    #endif    N=read();block=sqrt(N);    fill(mul,mul+N+1,1);    for(int i=1;i<=N;i++) a[i]=read()%mod,belong[i]=(i-1)/block+1;    for(int i=1;i<=N;i++) L[i]=(belong[i]-1)*block+1,R[i]=belong[i]*block;    for(int i=1;i<=N;i++)    {        int opt=read(),l=read(),r=read(),c=read()%mod;        if(opt==0)             Add(l,r,c);        else if(opt==1)             Mul(l,r,c);        else if(opt==2)             printf("%d\n",(a[r]*mul[belong[r]]+add[belong[r]])%mod);    }    return 0;}`

Related Keywords:

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

## A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

• #### Sales Support

1 on 1 presale consultation

• #### After-Sales Support

24/7 Technical Support 6 Free Tickets per Quarter Faster Response

• Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.