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 ...
随机推荐
- Mac 上有哪些值得推荐的软件?冷门小众软件但实用
确实Mac上有很多小众.冷门,但却是十分实用.值得推荐的工具,小编针对用的比较多的软件,整理了一些,希望有帮助. The Unarchive:解压缩工具 macOS 对于压缩文件的处理不是很好.如果你 ...
- python中执行shell命令的几个方法小结
原文 http://www.jb51.net/article/55327.htm 最近有个需求就是页面上执行shell命令,第一想到的就是os.system, os.system('cat /proc ...
- influxDB和grafana
influxdb启动服务 sudo service influxdb start 登录数据库 influx 在influxDB中,measurement相当于sql中的table, 插入measure ...
- Perl参数
一.#!/usr/bin/perl -w -w:prints warnings about dubious(可疑的,不确定的) constructs perldoc perlrun#可以查看参数详情 ...
- 【JS】JS格式化文件大小 单位:Bytes、KB、MB、GB
输入一个表示文件大小的数字,自适应转换到KB,MB,GB 方法一:bytes自适应转换到KB,MB,GB /// <summary> /// 格式化文件大小的JS方法 /// </s ...
- thymeleaf 基础
(一)Thymeleaf 是个什么? 简单说, Thymeleaf 是一个跟 Velocity.FreeMarker 类似的模板引擎,它可以完全替代 JSP .相较与其他的模板引擎,它有如下 ...
- node的优缺点及应用场景
Node.js是一个事件驱动I/O服务端JavaScript环境,基于Google的V8引擎(V8引擎执行Javascript的速度非常快,性能非常好) 可以说node是运行在服务器端V8引擎上的Ja ...
- vue input添加回车触发
普通vue input @keyup.enter="onSubmit" element el-input @keyup.enter.native="onSubmit&qu ...
- DevC++ return 1 exit status
当使用DevC++时编译运行程序出现 return 1 exit status 有可能是因为有在运行的命令窗口未关闭.
- idea JRebe插件激活方法
具体方法请看创始人博客及github