题目:

Problem Description
Let A1, A2, ... , AN be N elements. You need to deal with two kinds of operations. One type of operation is to add a given number to a few numbers in a given interval. The other is to query the value of some element.
 
Input
There are a lot of test cases. The first line contains an integer N. (1 <= N <= 50000) The second line contains N numbers which are the initial values of A1, A2, ... , AN. (-10,000,000 <= the initial value of Ai <= 10,000,000) The third line contains an integer Q. (1 <= Q <= 50000) Each of the following Q lines represents an operation. "1 a b k c" means adding c to each of Ai which satisfies a <= i <= b and (i - a) % k == 0. (1 <= a <= b <= N, 1 <= k <= 10, -1,000 <= c <= 1,000) "2 a" means querying the value of Aa. (1 <= a <= N)
 
Output
For each test case, output several lines to answer all query operations.
 
Sample Input
4
1 1 1 1
14
2 1
2 2
2 3
2 4
1 2 3 1 2
2 1
2 2
2 3
2 4
1 1 4 2 1
2 1
2 2
2 3
2 4
 
Sample Output
1
1
1
1
1
3
3
1
2
3
4
1

思路:
区间修改 单点查询
第一个操作是 对在a-b区间内的位置i 如果满足(i-a)%k==0 就把这个位置上的值加上c
式子可以等同于i%k==a%k 所以问题就转化为了右边的部分
从数据范围中可以看到k的范围很小 对k进行枚举 
k=1时 可以取的余数为0,1 
k=2时 可以取的余数为0,1 ,2
以此类推 所有可以取的结果共55种 根据取余的情况 对这一个区间内该更新哪些线段树进行纪录 然后对这一棵线段树这个区间内的所有值进行更新

代码:
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <string>
#include <cstring>
#include <algorithm> using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int inf=0x3f3f3f3f;
const int maxn=5e4+;
int n,m,y,a,b,k,c,op,ans;
int x[maxn]; struct node{
int l,r,w;
int add[];
}tree[maxn<<]; void build(int l,int r,int rt){
tree[rt].l=l;
tree[rt].r=r;
memset(tree[rt].add,,sizeof(tree[rt].add));
if(l==r){
tree[rt].w=x[l];
return;
}
int mid=(l+r)/;
build(l,mid,rt*);
build(mid+,r,rt*+);
tree[rt].w=tree[rt*].w+tree[rt*+].w;
} void pushdown(int rt){
tree[rt*].w+=tree[rt].w;
tree[rt*+].w+=tree[rt].w;
tree[rt].w=;
for(int i=;i<;i++){
tree[rt*].add[i]+=tree[rt].add[i];
tree[rt*+].add[i]+=tree[rt].add[i];
tree[rt].add[i]=;
}
} void update(int tmp,int rt){
if(tree[rt].l>=a && tree[rt].r<=b){
int index=k*(k-)/+tmp;
tree[rt].add[index]+=c;
tree[rt].w+=c;
return;
}
if(tree[rt].w) pushdown(rt);
int mid=(tree[rt].l+tree[rt].r)/;
if(a<=mid) update(tmp,rt*);
if(b>mid) update(tmp,rt*+);
// tree[rt].w=tree[rt*2].w+tree[rt*2+1].w;
} void query(int rt){
if(tree[rt].l==y && tree[rt].r==y){
for(int i=;i<=;i++){
int index=i*(i-)/+y%i;
ans+=tree[rt].add[index];
}
return;
}
if(tree[rt].w) pushdown(rt);
int mid=(tree[rt].l+tree[rt].r)/;
if(y<=mid) query(rt*);
else query(rt*+);
} int main(){
while(~scanf("%d",&n)){
for(int i=;i<=n;i++){
scanf("%d",&x[i]);
}
build(,n,);
scanf("%d",&m);
for(int i=;i<=m;i++){
scanf("%d",&op);
if(op==){
scanf("%d%d%d%d",&a,&b,&k,&c);
update(a%k,);
}
if(op==){
ans=;
scanf("%d",&y);
query();
printf("%d\n",x[y]+ans);
}
}
}
return ;
}
 

最新文章

  1. CODEVS3037 线段覆盖 5[序列DP 二分]
  2. mac jdk 6设置
  3. c#将http调用返回额json中的有关中文的unicode转换为中文(转)
  4. ReentrantReadWriteLock读写锁详解
  5. 【iCore2双核心板视频教程二】iM_LAN 100M 以太网模块TCP通信例程
  6. 网络拥塞控制(三) TCP拥塞控制算法
  7. PHP面向对象的一些深入理解
  8. python 优雅的使用正则表达式 ~ 1
  9. .Net 将一个DataTable分解成多个DataTable
  10. APPlication,Session,Cookie,ViewState和Cache之间的区别
  11. Javascript实现打字效果
  12. LIMS系统供应商一览表
  13. SharedPreference简介
  14. 再谈Android应用瘦身
  15. 反编译与调试APK
  16. 浅谈 Java 主流开源类库解析 XML
  17. python全栈开发-Day5 集合
  18. 存储引擎和表的操作(mysql中的数据类型、完整性约束)
  19. 不平衡数据下的机器学习方法简介 imbalanced time series classification
  20. 洛谷P1117 优秀的拆分

热门文章

  1. CSS外边框、边界样式常用组合
  2. flask models循环使用和migrate迁移脚本
  3. OpenStack的基础原理
  4. 11:12:21.924 [main] DEBUG org.apache.ibatis.logging.LogFactory - Logging initialized using &#39;class org.apache.ibatis.logging.slf4j.Slf4jImpl&#39; adapter.
  5. tomcat如何访问非webapp下的资源文件
  6. Dubbo服务端结合maven打jar包
  7. VirtualBox虚拟机中安装XP系统
  8. C语言:使用结构体和指针函数实现面向对象思想(OO编程)
  9. bzoj千题计划309:bzoj4332: JSOI2012 分零食(分治+FFT)
  10. partial.js client-side routing(客户端路由-基于HTML5 SPA特性的历史API)