分块练习 D
来源:互联网 发布:闲鱼申请淘宝介入几天 编辑:程序博客网 时间:2024/05/21 11:27
#include<cctype>#include<iostream>#include<cstring>#include<cmath>#include<algorithm>#include<cstdio>using namespace std;#define maxn 50010int n,a[maxn];bool flag;char _c;inline void read(int& x){flag = false;_c = getchar();x = 0;while(!isdigit(_c)){if(_c=='-')flag=true;_c=getchar();}while(isdigit(_c)){x = x*10+_c-'0';_c=getchar();}if(flag)x = -x;}typedef long long LL;int belong[maxn],L[maxn],R[maxn],block,num;LL add[maxn],sum[maxn];void build(){block = sqrt(n);num = n/block;if(n%block)num++;for(int i=1;i<=num;i++)L[i]=(i-1)*block+1,R[i]=i*block;R[num] = n;for(int i=1;i<=n;i++)belong[i] = (i-1)/block+1,sum[belong[i]]+=a[i];}void update(int x,int y,int w){if(belong[x]==belong[y]){for(int i=x;i<=y;i++)a[i]+=w;sum[belong[x]]+=(LL)w*(y-x+1);return;}for(int i=x;i<=R[belong[x]];i++)a[i]+=w;sum[belong[x]]+=(LL)(R[belong[x]]-x+1)*w;for(int i=belong[x]+1;i<belong[y];i++)add[i]+=w;for(int i=L[belong[y]];i<=y;i++)a[i]+=w;sum[belong[y]]+=(LL)(y-L[belong[y]]+1)*w;}LL query(int x,int y){LL ret = 0;if(belong[x]==belong[y]){for(int i=x;i<=y;i++)ret+=a[i];ret+=(LL)add[belong[x]]*(y-x+1);return ret;}for(int i=x;i<=R[belong[x]];i++)ret+=a[i];ret+=(LL)add[belong[x]]*(R[belong[x]]-x+1);for(int i=belong[x]+1;i<belong[y];i++)ret+=(LL)add[i]*(R[i]-L[i]+1)+sum[i];for(int i=L[belong[y]];i<=y;i++)ret+=a[i];ret+=(LL)add[belong[y]]*(y-L[belong[y]]+1);return ret;}int main(){read(n);for(int i=1;i<=n;i++)read(a[i]);build();int f,l,r,x;for(int i=1;i<=n;i++){read(f),read(l),read(r),read(x);if(f)printf("%lld\n",query(l,r)%(x+1));else update(l,r,x);}return 0;}
1 0
- 分块练习 D
- 分块练习
- 分块练习 A
- 分块练习 B
- 分块练习 C
- Scala练习-分块查找
- codeforces 455D 分块
- HDU1166敌兵布阵 分块解法,分块练习
- Codevs2038 线段树练习3(分块)
- Codevs 4927 线段树练习5(分块)
- 分块练习- BZOJ2002-Bounce 弹飞绵羊
- 机房练习赛nan(分块压缩)
- 【分块】 codeforces 455D - Serega and Fun
- Codeforces 86D Powerful array 分块
- Codeforces 487D. Conveyor Belts 分块+DP
- codeforces 86D. Powerful array(分块)
- 练习三 Problem D
- 分块。。
- C++原子操作实现互斥
- RSACryptoServiceProvider加密解密签名验签和DESCryptoServiceProvider加解密
- C语言打洞访问基本原理
- PL/SQL性能优化技巧
- Android 中如何获取本app的版本号?
- 分块练习 D
- 剑指Offer 35题 第一个只出现一次的字符 Java版
- 水叮当的舞步(迭代搜索+A*搜索)
- 第三十四讲 项目 用循环累加
- 如何設計乘加電路? (SOC) (Verilog) (MegaCore)
- spring组件注解和注入注解
- java:客户端与java后台交互不常用。
- 嵌入式linux之Uboot和系统移植--基础
- JAVA的基本数据类型和类型转换