LOJ #6280. Introduction to series partitioning 4,
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 addition and interval summation.
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, it indicates that the query is located in [l, r] [l, r] [l, r] And mod (c + 1) mod (c + 1) mod (c + 1) mod (c + 1) of all numbers ).
Output Format
For each query, a row of numbers is output to indicate the answer.
Sample Input
41 2 2 30 1 3 11 1 4 40 1 2 21 1 2 4
Sample output
14
Data range and prompt
For data of 100% 100 \ % 100%, 1 ≤ n ≤ 50000, − 231 ≤ others 1 \ leq n \ leq 50000, -2 ^ {31} \ leq \ mathrm {others} 1 ≤ n ≤ 50000, − 231 ≤ others, ans ≤ 231 − 1 \ mathrm {ans} \ leq 2 ^ {31}-1ans ≤ 231 − 1.
Multipart
Maintain the Block Value
The rest follow the routine
#include<cstdio>#include<cstring>#include<algorithm>#include<cmath>#include<vector>#define int long long using namespace std;const int MAXN=2*1e6+10;const int INF=1e8+10;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],sum[MAXN],tag[MAXN],block;void IntervalAdd(int l,int r,int val){ for(int i=l;i<=min(R[l],r);i++) a[i]+=val,sum[belong[i]]+=val; if(belong[l]!=belong[r]) for(int i=L[r];i<=r;i++) a[i]+=val,sum[belong[i]]+=val; for(int i=belong[l]+1;i<=belong[r]-1;i++) tag[i]+=val;}int Query(int l,int r,int mod){ int ans=0; for(int i=l;i<=min(R[l],r);i++) ans+=a[i]+tag[belong[i]],ans=ans%mod; if(belong[l]!=belong[r]) for(int i=L[r];i<=r;i++) ans+=a[i]+tag[belong[i]]; for(int i=belong[l]+1;i<=belong[r]-1;i++) ans+=sum[i]+tag[i]*block,ans=ans%mod; return ans%mod;}main(){ #ifdef WIN32 freopen("a.in","r",stdin); // freopen("b.out","w",stdout); #else #endif int N=read();block=sqrt(N); for(int i=1;i<=N;i++) belong[i]=(i-1)/block+1,L[i]=(belong[i]-1)*block+1,R[i]=belong[i]*block; for(int i=1;i<=N;i++) a[i]=read(); for(int i=1;i<=N;i++) sum[belong[i]]+=a[i]; for(int i=1;i<=N;i++) { int opt=read(),l=read(),r=read(),c=read(); if(opt==0) IntervalAdd(l,r,c); else printf("%lld\n",Query(l,r,c+1)); } return 0;}