HDOJ 4267 A Simple Problem with Integers (线段树)
题目:
思路:
代码:
#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 (线段树)的更多相关文章
- 2018 ACMICPC上海大都会赛重现赛 H - A Simple Problem with Integers (线段树,循环节)
2018 ACM 国际大学生程序设计竞赛上海大都会赛重现赛 H - A Simple Problem with Integers (线段树,循环节) 链接:https://ac.nowcoder.co ...
- POJ 3468 A Simple Problem with Integers(线段树 成段增减+区间求和)
A Simple Problem with Integers [题目链接]A Simple Problem with Integers [题目类型]线段树 成段增减+区间求和 &题解: 线段树 ...
- poj3468 A Simple Problem with Integers (线段树区间最大值)
A Simple Problem with Integers Time Limit: 5000MS Memory Limit: 131072K Total Submissions: 92127 ...
- POJ3648 A Simple Problem with Integers(线段树之成段更新。入门题)
A Simple Problem with Integers Time Limit: 5000MS Memory Limit: 131072K Total Submissions: 53169 Acc ...
- 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 ...
- Poj 3468-A Simple Problem with Integers 线段树,树状数组
题目:http://poj.org/problem?id=3468 A Simple Problem with Integers Time Limit: 5000MS Memory Limit ...
- [POJ] 3468 A Simple Problem with Integers [线段树区间更新求和]
A Simple Problem with Integers Description You have N integers, A1, A2, ... , AN. You need to deal ...
- 【POJ】3468 A Simple Problem with Integers ——线段树 成段更新 懒惰标记
A Simple Problem with Integers Time Limit:5000MS Memory Limit:131072K Case Time Limit:2000MS Descr ...
- A Simple Problem with Integers(线段树,区间更新)
A Simple Problem with Integers Time Limit: 5000MS Memory Limit: 131072K Total Submissions: 83822 ...
随机推荐
- 发送HTTP_GET请求 表头application/json
/** * 发送HTTP_GET请求 * 该方法会自动关闭连接,释放资源 * @param reqURL 请求地址(含参数) * @param decodeCharset 解码字符集,解析响应数据时用 ...
- 剑指Offer_编程题_7
题目描述 大家都知道斐波那契数列,现在要求输入一个整数n,请你输出斐波那契数列的第n项. n<=39 class Solution { public: int Fibonacci(int n) ...
- 比Kafka Mangaer更优秀的开源监控工具-Kafka Eagle
比Kafka Mangaer更优秀的开源监控工具-Kafka Eagle 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 在Kafka的监控系统中有很多优秀的开源监控系统.比如Kaf ...
- Mybatis笔记三:全局配置文件
目录 配置文件 dtd提示 properties标签(不怎么用) typeAliases 自动把下划线换成驼峰命名 配置文件 看着这个配置文件,我们将对这个配置文件进行细致的讲解 <?xml v ...
- Docker 容器管理
单一容器管理 容器的标识符 每个容器被创建后都会分配一个CONTAINER_ID作为容器的唯一标识符,后续的启动.停止等操作都通过CONTAINER_ID来完成的. CONTAINER_ID很难记忆, ...
- http-request详解
HTTP请求 请求数据格式 响应数据格式 request
- 利用spring的MultipartFile实现文件上传【原】
利用spring的MultipartFile实现文件上传 主要依赖jar包 spring-web-3.0.6.RELEASE.jar 用到 (org.springframework.web.multi ...
- vue常用指令
1.v-if系列 v-if="数据|判断" 只要条件成立,就显示if中的元素 v-else (注意:必须跟在v-if或者v-if-else的后面,不然失效) 如果if条件不成立显示 ...
- springboot(十六):springboot整合shiro
数据库有五张表(userInfo,uerrole,role,rolepermission,permission) userInfo(id,username,password) userrole(uid ...
- 20155324 2016-2017-2 《Java程序设计》第4周学习总结
20155324 2016-2017-2 <Java程序设计>第4周学习总结 教材学习内容总结 继承 面对对象中,子类继承父类,避免重复定义行为就使用继承.在Java中,继承时使用exte ...