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 ...
随机推荐
- C++ vector的运用
C++ vector 用法(#include <vector>) 标准库Vector类型 使用需要的头文件: #include <vector> Vector:Vector 是 ...
- 推荐几个Mac插件帮你提升工作效率
下面这篇文章是小编看到的很好的文章,分享给大家,小编前几天也整理了很多mac专题文章.更多专题,可关注[磨人的小妖精],查看我的文章,也可上[风云社区 SCOEE],查找和下载相关软件资源. (一)综 ...
- bzoj1497 最小割
题意: 新的技术正冲击着手机通讯市场,对于各大运营商来说,这既是机遇,更是挑战.THU集团旗下的CS&T通讯公司在新一代通讯技术血战的前夜,需要做太多的准备工作,仅就站址选择一项,就需要完成前 ...
- centos 7.4 安装gitlab
centos 7.4 安装gitlab #curl -s https://packages.gitlab.com/install/repositories/gitlab/gitlab-ce/scrip ...
- vue基础篇---vue组件《2》
定义全局组件 我们通过Vue的component方法来定义一个全局组件. <div id="app"> <!--使用定义好的全局组件--> <coun ...
- Mac下显示网页全屏快捷键
control+command+F mac下谷歌浏览器全屏时隐藏头部:(隐藏标签页和地址栏) command+shift+B
- Sql Server时间格式化笔记
Select CONVERT(varchar(100), GETDATE(), 0): 05 16 2006 10:57AMSelect CONVERT(varchar(100), GETDATE() ...
- jQuery克隆html元素并改变id
如题,前端操作经常需要ajax异步刷新html页面数据.有时候js里面拼接html代码很麻烦. 因此选择一个div克隆并改变一些值就省了很多事.这个div也可以提前写在html里面hide() 下面是 ...
- mysql根据出生日期查询年龄
如题,根据出生日期查找计算出年龄,网上找了一大堆,数据库可以用,但是集成到mybatis它不答应了,报错.具体是大于号,小于号的问题.要我解决那个错误吗?不存在的.换一种方式就好了.而且sql语句一大 ...
- 数据库操作中如何批量执行多个sql文件?
数据库操作中如何批量执行多个sql文件? 1.应用场景:在历史数据导入过程中,会发现有很多个表形成的.sql文件,要是一个一个文件去手动执行,实在是费时间,所以采取以下方法. 2.将文件放在一定位置, ...