[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 ...
随机推荐
- 解决VMware Workstation虚拟机不能联网的解决办法
在windows服务中查看,以下几个服务是否正常开启,没有就开启
- Struts2中获取Web元素request、session、application对象的四种方式
我们在学习web编程的时候,一般都是通过requet.session.application(servletcontext)进行一系列相关的操作,request.session.和applicatio ...
- IPTABLES简介
iptables防火墙工作原理 简介:iptables防火墙工作在网络层,针对TCP/IP数据包实施过滤和限制,iptables防火墙基于内核编码实现,具有非常稳定的性能和高效率: iptables属 ...
- 一直深深困扰我的问题——hadoop 重启集群后,之前运行的job运行状态都丢失了
努力之后总是存在回报的,我花了三天时间终于找到了问题所在: 配置文件yarn-site.xml: <property> <name>yarn.resourcema ...
- If the parts of an organization (e.g., teams, departments, or subdivisions) do not closely reflect the essential parts of the product, or if the relationship between organizations do not reflect the r
https://en.wikipedia.org/wiki/Conway%27s_law
- openssl生成证书server.key server.crt
Key是私用秘钥,通常是RSA算法 Csr是证书请求文件,用于申请证书.在制作csr文件时,必须使用自己的私钥来签署申,还可以设定一个密钥. crt是CA认证后的证书文,签署人用自己的key给你签署凭 ...
- sql server常用性能计数器
https://blog.csdn.net/kk185800961/article/details/52462913?utm_source=blogxgwz5 https://blog.csdn.ne ...
- (0.2.3)Mysql安装——二进制安装
Linux平台下二进制方式安装卸载mysql 本章节:二进制安装mysql 目录: 1.基于Linux平台的Mysql项目场景介绍 2.mysql数据库运行环境准备-最优配置 3.如何下载mysql数 ...
- 008-Hadoop Hive sql语法详解3-DML 操作:元数据存储
一.概述 hive不支持用insert语句一条一条的进行插入操作,也不支持update操作.数据是以load的方式加载到建立好的表中.数据一旦导入就不可以修改. DML包括:INSERT插入.UPDA ...
- Spring框架第四篇之基于注解的DI注入
一.说明 与@Component注解功能相同,但意义不同的注解还有三个: 1)@Repository:注解在Dao实现类上 2)@Service:注解在Service实现类上 3)@Controlle ...