题目:

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 ;
}
 

HDOJ 4267 A Simple Problem with Integers (线段树)的更多相关文章

  1. 2018 ACMICPC上海大都会赛重现赛 H - A Simple Problem with Integers (线段树,循环节)

    2018 ACM 国际大学生程序设计竞赛上海大都会赛重现赛 H - A Simple Problem with Integers (线段树,循环节) 链接:https://ac.nowcoder.co ...

  2. POJ 3468 A Simple Problem with Integers(线段树 成段增减+区间求和)

    A Simple Problem with Integers [题目链接]A Simple Problem with Integers [题目类型]线段树 成段增减+区间求和 &题解: 线段树 ...

  3. poj3468 A Simple Problem with Integers (线段树区间最大值)

    A Simple Problem with Integers Time Limit: 5000MS   Memory Limit: 131072K Total Submissions: 92127   ...

  4. POJ3648 A Simple Problem with Integers(线段树之成段更新。入门题)

    A Simple Problem with Integers Time Limit: 5000MS Memory Limit: 131072K Total Submissions: 53169 Acc ...

  5. poj 3468 A Simple Problem with Integers 线段树第一次 + 讲解

    A Simple Problem with Integers Description You have N integers, A1, A2, ... , AN. You need to deal w ...

  6. Poj 3468-A Simple Problem with Integers 线段树,树状数组

    题目:http://poj.org/problem?id=3468   A Simple Problem with Integers Time Limit: 5000MS   Memory Limit ...

  7. [POJ] 3468 A Simple Problem with Integers [线段树区间更新求和]

    A Simple Problem with Integers   Description You have N integers, A1, A2, ... , AN. You need to deal ...

  8. 【POJ】3468 A Simple Problem with Integers ——线段树 成段更新 懒惰标记

    A Simple Problem with Integers Time Limit:5000MS   Memory Limit:131072K Case Time Limit:2000MS Descr ...

  9. A Simple Problem with Integers(线段树,区间更新)

    A Simple Problem with Integers Time Limit: 5000MS   Memory Limit: 131072K Total Submissions: 83822   ...

随机推荐

  1. Tensorflow object detection API 搭建物体识别模型(一)

    一.开发环境 1)python3.5 2)tensorflow1.12.0 3)Tensorflow object detection API :https://github.com/tensorfl ...

  2. 【JS】js将 /Date(1518943415760+0800)/ 转换为2018-2-18 16:43:35格式

    function formatDate(dt) { var year = dt.getFullYear(); var month = dt.getMonth() + 1; var date = dt. ...

  3. C# Selenium学习

    https://blog.csdn.net/hjkl950217/article/details/54314760 https://www.cnblogs.com/vaevvaev/p/7041842 ...

  4. Django基于正则表达式匹配URL

    在Django1.X中,是这样匹配的. 在Django2.X中,是这样匹配的. Django2.X中开始需要用re_path模块进行正则表达式匹配了,太JB坑了,卡了好久这个问题,最后还是问群里面的高 ...

  5. vue-router中query与params区别

    query和params两者都是在Vue路由中传参. 用法: query用path来引入,params只能用name来传递,不能使用path 展示效果:query更像ajax中get请求(会在地址栏显 ...

  6. [Android] Android ViewPager 中加载 Fragment的两种方式 方式(一)

    Android ViewPager 中加载 Fragmenet的两种方式 一.当fragment里面的内容较少时,直接 使用fragment xml布局文件填充 文件总数 布局文件:view_one. ...

  7. redis集群之主从架构

    https://redis.io/topics/replication1. redis主从架构概述(1)一个master可以配置多个slave(2)slave与master之间使用异步复制进行数据同步 ...

  8. Mac 建PHP 环境 及 配置 apache 默认目录

    网上找的帮助,试一下,记录在此: 在Mac下配置php开发环境:Apache+php+MySql  https://www.imooc.com/article/15705?block_id=tuiji ...

  9. DotNetBar的一个MDIView不正常显示的问题

    现象,使用tabStrip MDIView后,子窗体会被遮挡一部分,两种解决办法 1.tabStrip的 MdiAutoHide=False 2.tabStrip 设置MultilineWithNav ...

  10. 【十一】jvm 性能调优工具之 jmap

    jvm 性能调优工具之 jmap 概述 命令jmap是一个多功能的命令.它可以生成 java 程序的 dump 文件, 也可以查看堆内对象示例的统计信息.查看 ClassLoader 的信息以及 fi ...