[HDU6315]Naive Operations(线段树+树状数组)
构造一个序列B[i]=-b[i],建一颗线段树,维护区间max,
每次区间加后再询问该区间最大值,如果为0就在树状数组中对应的值+1(该操作可能进行多次)
答案在树状数组中找
其实只用一颗线段树也是可以的
Code
#include <cstdio>
#include <algorithm>
#include <cstring>
#define mst(a) memset(a,0,sizeof(a))
#define N 100010
using namespace std; int n,m,b[N]; inline int read(){
int x=0,f=1;char ch=getchar();
while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
return x*f;
} namespace BT{
int T[N];
#define lowbit(x) ((x)&(-x))
void add(int x,int v){for(;x<=n;x+=lowbit(x))T[x]+=v;}
int Q(int x){int r=0;for(;x;x-=lowbit(x))r+=T[x];return r;}
void ntt(){mst(T);}
} namespace Seg{
#define MID int mid=(l+r)>>1,ls=id<<1,rs=id<<1|1
int tag[N*4];
struct info{
int x,id;
info(){x=id=0;}
info(int a,int b):x(a),id(b){}
friend info operator+(info a,info b){
return a.x>b.x?a:b;
}
}T[N*4];
void build(int l,int r,int id){
if(l==r){T[id]=info(-b[l],l);return;}
MID;
build(l,mid,ls),build(mid+1,r,rs);
T[id]=T[ls]+T[rs];
}
void pushdown(int l,int r,int id){
int &tmp=tag[id];
if(!tmp)return;
MID;
tag[ls]+=tmp,tag[rs]+=tmp;
T[ls].x+=tmp,T[rs].x+=tmp;
tmp=0;
}
void upd(int l,int r,int id,int L,int R,int v){
if(L<=l&&r<=R){tag[id]+=v;T[id].x+=v;return;}
pushdown(l,r,id);
MID;
if(L<=mid)upd(l,mid,ls,L,R,v);
if(R>=mid+1)upd(mid+1,r,rs,L,R,v);
T[id]=T[ls]+T[rs];
}
info Q(int l,int r,int id,int L,int R){
if(L<=l&&r<=R){return T[id];}
pushdown(l,r,id);
MID;
info res(-1e9,0);
if(L<=mid)res=res+Q(l,mid,ls,L,R);
if(R>=mid+1)res=res+Q(mid+1,r,rs,L,R);
return res;
}
void fft(){mst(tag),mst(T);}
}
void fwt(){Seg::fft(),BT::ntt();}
int main(){
for(;~scanf("%d%d",&n,&m);){
fwt();
for(int i=1;i<=n;++i)b[i]=read();
Seg::build(1,n,1);
for(int i=1;i<=m;++i){
char s[10];scanf("%s",s);
int l=read(),r=read();
if(s[0]=='a'){
Seg::upd(1,n,1,l,r,1);
for(;;){
Seg::info tmp=Seg::Q(1,n,1,l,r);
if(tmp.x==0){
Seg::upd(1,n,1,tmp.id,tmp.id,-b[tmp.id]);
BT::add(tmp.id,1);
}else break;
} }else printf("%d\n",BT::Q(r)-BT::Q(l-1));
}
}
return 0;
}
[HDU6315]Naive Operations(线段树+树状数组)的更多相关文章
- HDU6315 Naive Operations(线段树 复杂度分析)
题意 题目链接 Sol 这题关键是注意到题目中的\(b\)是个排列 那么最终的答案最多是\(nlogn\)(调和级数) 设\(d_i\)表示\(i\)号节点还需要加\(d_i\)次才能产生\(1\)的 ...
- HDU6315 Naive Operations 线段树
目录 Catalog Solution: (有任何问题欢迎留言或私聊 && 欢迎交流讨论哦 Catalog Problem:Portal传送门 原题目描述在最下面. Solution ...
- HDU-6315 Naive Operations//2018 Multi-University Training Contest 2___1007 (线段树,区间除法)
原题地址 Naive Operations Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 502768/502768 K (Java/ ...
- HDU6315 Naive Operations(多校第二场1007)(线段树)
Naive Operations Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 502768/502768 K (Java/Other ...
- hdu Naive Operations 线段树
题目大意 题目链接Naive Operations 题目大意: 区间加1(在a数组中) 区间求ai/bi的和 ai初值全部为0,bi给出,且为n的排列,多组数据(<=5),n,q<=1e5 ...
- 杭电多校第二场 hdu 6315 Naive Operations 线段树变形
Naive Operations Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 502768/502768 K (Java/Other ...
- HDU - 6315(2018 Multi-University Training Contest 2) Naive Operations (线段树区间操作)
http://acm.hdu.edu.cn/showproblem.php?pid=6315 题意 a数组初始全为0,b数组为1-n的一个排列.q次操作,一种操作add给a[l...r]加1,另一种操 ...
- HDU 6315 Naive Operations(线段树区间整除区间)
Problem DescriptionIn a galaxy far, far away, there are two integer sequence a and b of length n.b i ...
- HDU - 6315 Naive Operations (线段树+思维) 2018 Multi-University Training Contest 2
题意:数量为N的序列a和b,a初始全为0,b为给定的1-N的排列.有两种操作:1.将a序列区间[L,R]中的数全部+1:2.查询区间[L,R]中的 ∑⌊ai/bi⌋(向下取整) 分析:对于一个位置i, ...
随机推荐
- Can't create new folder in windows7
First, please use System File Checker tool to troubleshoot(诊断) this issue. If the issue persists, im ...
- tree 向上查找(更新删除后页面的数据)
需求 : 根据选择的id,需要找到一整条tree,id以及id数据的子集都已被删除(向下查找-----上一篇笔记),此时需要更新页面的数据(向上查找) //知道最底层的节点的id,查找满足id的整个t ...
- 【Z】段错误Segment Fault定位,即core dump文件与gdb定位
使用C++开发系统有时会出现段错误,即Segment Fault.此类错误程序直接崩溃,通常没有任何有用信息输出,很难定位bug,因而无从解决问题.今天我们介绍core dump文件,并使用gdb进行 ...
- Java内存使用情况查看工具
Java通过jvm自己管理内存,同时Java提供了一些命令行工具,用于查看内存使用情况.这里主要介绍一下jstat.jmap命令以及相关工具. 一.jstat查看 gc实时执行情况 jstat命令命令 ...
- 在Java中字符串是通过引用传递的?
这是一个经典的java问题.在stackoverflow上,许多类似的问题已经被问过了,但是许多回答是错误的或不完整的. 如果你不想深入思考的话,这个问题很简单.如果你想明白的更彻底,那么问题可能容易 ...
- 入门摄影——尼康DX
学习链接 单反应当怎样入门? - Williams的回答 - 知乎 [摄影教程]尼康数码单反相机使用视频教程_哔哩哔哩 (゜-゜)つロ 干杯~-bilibili 图像品质与图像大小 图像品质:暂选JP ...
- ClipboardJS 实现JS复制到剪切板
根据官方文档的说法这个支持IE9+以及大部分主流浏览器,地址:https://clipboardjs.com/ 下面写个简单的例子:HTML:注意,这里最好是button,并非所有的元素都支持该JS ...
- 哈哈,原来IOC容器的bean是存在DefaultSingletonBeanRegistry的一个Map类型的属性当中。
经过查看源代码发现IOC容器中的bean实例(不知道是不是所有的bean)是存储在一个DefaultSingletonBeanRegistry类实例的一个Map类型的属性当中. 下面是DefaultS ...
- Yii2控制器 返回 json 格式数据
Yii::$app->response->format = Response::FORMAT_JSON; $data = User::find()->where([])->as ...
- Redis(RedisTemplate)使用string字符串
RedisTemplate配置:https://www.cnblogs.com/weibanggang/p/10188682.html ApplicationContext applicationCo ...