[Hdu6315]Naive Operations
题意:给定一个初始数组b和一个初始值全部为0的数组a,每次操作可以在给定的区间(l,r)内让a[i](l=<i<=r)加一,或者查询区间区间(l,r)中a[i]/b[i](l=<i<=r)(取整)的和。
可以知道,$\sum_{\frac{a_i}{b_i}}\le nlogn$,所以我们只要暴力找到需要修改的位置修改即可。。
代码:
#include<iostream>
#include<cstdio>
#include<cstring>
#define M 100010
#define ls node<<1
#define rs node<<1|1
using namespace std;
int n,q;
int maxn[M<<],minn[M<<],cnt[M<<],tag[M<<],b[M]; void update(int node)
{
minn[node]=min(minn[ls],minn[rs]);
cnt[node]=cnt[ls]+cnt[rs];
maxn[node]=max(maxn[ls],maxn[rs]);
} void build(int node,int l,int r)
{
if(l==r) {minn[node]=b[l];return;}
int mid=(l+r)/;
build(ls,l,mid);
build(rs,mid+,r);
update(node);
} void push(int node)
{
if(tag[node])
{
maxn[ls]+=tag[node];
maxn[rs]+=tag[node];
tag[ls]+=tag[node];
tag[rs]+=tag[node];
tag[node]=;
}
} void change(int node,int l,int r,int l1,int r1)
{
if(l1<=l&&r1>=r)
{
maxn[node]++;
if(maxn[node]<minn[node])
{
tag[node]++;
return;
}
if(l==r&&maxn[node]>=minn[node])
{
cnt[node]++;
minn[node]+=b[l];
return;
}
}
int mid=(l+r)/;push(node);
if(l1<=mid) change(ls,l,mid,l1,r1);
if(r1>mid) change(rs,mid+,r,l1,r1);
update(node);
} int query(int node,int l,int r,int l1,int r1)
{
if(l1<=l&&r1>=r) return cnt[node];
int mid=(l+r)/; push(node);
int ans=;
if(l1<=mid) ans+=query(ls,l,mid,l1,r1);
if(r1>mid) ans+=query(rs,mid+,r,l1,r1);
return ans;
} int main()
{
while(~scanf("%d%d",&n,&q))
{
memset(maxn,,sizeof(maxn));
memset(minn,,sizeof(minn));
memset(cnt,,sizeof(cnt));
memset(tag,,sizeof(tag));
for(int i=;i<=n;i++) scanf("%d",&b[i]);
build(,,n);
while(q--)
{
int l,r;char s[];
scanf("%s%d%d",s,&l,&r);
if(s[]=='a') change(,,n,l,r);
else printf("%d\n",query(,,n,l,r));
}
}
return ;
}
[Hdu6315]Naive Operations的更多相关文章
- HDU6315 Naive Operations(多校第二场1007)(线段树)
Naive Operations Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 502768/502768 K (Java/Other ...
- 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(线段树+树状数组)
构造一个序列B[i]=-b[i],建一颗线段树,维护区间max, 每次区间加后再询问该区间最大值,如果为0就在树状数组中对应的值+1(该操作可能进行多次) 答案在树状数组中找 其实只用一颗线段树也是可 ...
- 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(线段树+思维)
链接:HDU-6315:Naive Operations 题意: In a galaxy far, far away, there are two integer sequence a and b o ...
- HDU 6351 Naive Operations(线段树)
题目: http://acm.hdu.edu.cn/showproblem.php?pid=6315 Naive Operations Time Limit: 6000/3000 MS (Java/O ...
- 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/Other ...
- hdu Naive Operations 线段树
题目大意 题目链接Naive Operations 题目大意: 区间加1(在a数组中) 区间求ai/bi的和 ai初值全部为0,bi给出,且为n的排列,多组数据(<=5),n,q<=1e5 ...
随机推荐
- Windows MFC 打开文本
MFC的CFileDialog自动封装了文件相关的对话框,提供一种简单的文件打开和文件存盘对话框功能. 要使用CFileDialog类,首先要构造一个对象, 项目实例: CFileDialog fil ...
- JavaBean的任务就是: “Write once, run anywhere, reuse everywhere” Enterprise JavaBeans
javaBean_百度百科 https://baike.baidu.com/item/javaBean/529577?fr=aladdin 区别EJB JavaBean 和 Server Bean(通 ...
- googlr 黄金法则 监控
googlr 黄金法则 监控
- 安装和使用PhantomJS
一.安装PhantomJS(linux环境安装) 将PhantomJS下载在/usr/local/src/packet/目录下(这个看个人喜好) 操作系统:CentOS 7 64-bit 1.下载地址 ...
- mongodb批量插入数据
年前由于公司业务需要,后台需要获取流水记录,需要每天定时跑脚本,将流水记录跑入库里边,每天大概有个一百万左右,使用的数据库是mongodb,考虑到一条一条录入数据,100多万会跑断,就想着批量录入数据 ...
- Apache 2.4 配置多个虚拟主机的问题
以前一直用Apache2.2的版本,最近升级到了2.4的版本,尝尝新版本嘛. 不过遇到了几个问题,一个就是配置了多个virtualhost,虽然没有报错,不过除了第一可以正常访问外,其他的都存在403 ...
- post 传递参数中包含 html 代码解决办法,js加密,.net解密
今天遇到一个问题,就是用post方式传递参数,程序在vs中完美调试,但是在iis中,就无法运行了,显示传递的参数获取不到,报错了,查看浏览器请求情况,错误500,服务器内部错误,当时第一想法是接收方式 ...
- IT开发工程师的悲哀现状和可能前途
IT开发工程师的悲哀现状和可能前途 本文所指的开发工程师,仅指程序开发人员和以数字电路开发为主的电子工程师.当你选择计算机或者电子.自控等专业进入大学时,你本来还是有机会从事其它行业的,可你毕业时执迷 ...
- 详解Spark sql用户自定义函数:UDF与UDAF
UDAF = USER DEFINED AGGREGATION FUNCTION Spark sql提供了丰富的内置函数供猿友们使用,辣为何还要用户自定义函数呢?实际的业务场景可能很复杂,内置函数ho ...
- 宏表达式与函数、#undef、条件编译、
宏表达式在预编译期被处理,编译器不知道宏表达式的存在. 宏表达式没有任何的调用开销 宏表达式中不能出现递归定义. C语言中强大的内置宏 __FILE__:被编译的文件名 //双底线 __LINE__: ...