[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 ...
随机推荐
- Code Forces 21 A(模拟)
A. Jabber ID time limit per test 0.5 second memory limit per test 256 megabytes input standard input ...
- NoSQL 常用资源
Hadoop:http://www.apache.org/dyn/closer.cgi/hadoop/common/ easyhadoop:https://github.com/xianglei/ea ...
- 数字货币量化分析报告_20170905_P
[分析时间]2017-09-05 16:36:46 [数据来源]中国比特币 https://www.chbtc.com/ef4101d7dd4f1faf4af825035564dd81聚币网 http ...
- Linux包管理及yum
1.光盘挂载 mount /dev/cdrom /mntcd /mnt 2.安装rpm包 rpm -ivh vsftpd-3.0.2-22.el7.x86_64.rpm rpm -Uvh vsftp ...
- django组件之ContentType
ContentTyep组件: 帮助我们关联所有数据库的表 帮助我们反向查询关联数据表中的所有策略信息 GenericForeignkey(帮助我们快速插入数据) GenericRelation(用于反 ...
- mysql参照完整性 策略设置之 on update 和 on delete
一.当表中有外键约束的时候参照表中数据的删除和修改违背参照完整性时 可根据以下策略进行处理 1.两条策略设置为cascade的时候 参照表中的数据修改或者删除的时候改表中数据也会被删除 2.两条策略设 ...
- MyEclipse如何调试
我们在MyEclipse中jav添加断点,运行debug as-->open debug Dialog,然后在对话框中选类后--> Run在debug视图下.2.F5键与F6键均为单步调试 ...
- 对BeforeSuite和BeforeTest的理解
在BeforeSuite.BeforeTest.BeforeClass.BeforeMethod及BeforeGroups中,后面三个注解都比较好理解,其实BeforeSuite.BeforeTest ...
- Spring框架第二篇之Bean的装配
一.默认装配方式 代码通过getBean();方式从容器中获取指定的Bean实例,容器首先会调用Bean类的无参构造器,创建空值的实例对象. 举例: 首先我在applicationContext.xm ...
- jmeter接口测试实战
请求方法:get/post 接口请求地址:http://172.22.24.26:8080/fundhouse/external/getdata?name=xxxx &fund_udid=35 ...