题意:

两个序列a和b,初始a[i]=0,b[i]给定且为一个1到n的排列,要求维护以下两种操作:
1.区间[L,R]内a[i]加1

2.询问[L,R]内a[i]/b[i](下取整)之和

n,q<=1e5

思路:

实际上a[i]/b[i]的线段树可以改为树状数组,因为只需要支持单点修改和前缀区间求和

 #include<cstdio>
#include<cstring>
#include<string>
#include<cmath>
#include<iostream>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<vector>
using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int,int> PII;
typedef vector<int> VI;
#define fi first
#define se second
#define MP make_pair
const int N=;
int ad[N<<],mn[N<<],T[N],b[N],n,m,cas; void pushdown(int p)
{
if(ad[p])
{
ad[p<<]+=ad[p];
mn[p<<]+=ad[p];
ad[p<<|]+=ad[p];
mn[p<<|]+=ad[p];
ad[p]=;
}
} void pushup(int p)
{
mn[p]=min(mn[p<<],mn[p<<|]);
} void build(int l,int r,int p)
{
ad[p]=;
if(l==r)
{
mn[p]=b[l];
return;
}
int mid=(l+r)>>;
build(l,mid,p<<);
build(mid+,r,p<<|);
pushup(p);
} void modify(int x)
{
for(int i=x;i<=n;i+=i&-i) T[i]++;
} int ask(int x)
{
int ans=;
for(int i=x;i;i-=i&-i) ans+=T[i];
return ans;
} void update(int l,int r,int x,int y,int p)
{
if((x<=l)&&(r<=y))
{
ad[p]--;
mn[p]--;
return;
}
pushdown(p);
int mid=(l+r)>>;
if(x<=mid) update(l,mid,x,y,p<<);
if(y>mid) update(mid+,r,x,y,p<<|);
pushup(p);
} void clear(int l,int r,int p)
{
if(l==r)
{
if(!mn[p])
{
mn[p]=b[l];
modify(l);
}
return;
}
pushdown(p);
int mid=(l+r)>>;
if(!mn[p<<]) clear(l,mid,p<<);
if(!mn[p<<|]) clear(mid+,r,p<<|);
pushup(p);
} int main()
{ while(scanf("%d%d",&n,&m)!=EOF)
{
for(int i=;i<=n;i++) scanf("%d",&b[i]);
build(,n,);
for(int i=;i<=n;i++) T[i]=;
for(int i=;i<=m;i++)
{
char ch[];
scanf("%s",ch);
if(ch[]=='a')
{
int l,r;
scanf("%d%d",&l,&r);
update(,n,l,r,);
clear(,n,);
}
else
{
int l,r;
scanf("%d%d",&l,&r);
printf("%d\n",ask(r)-ask(l-));
}
}
}
return ;
}

【HDOJ6315】Naive Operations(线段树,树状数组)的更多相关文章

  1. hdu Naive Operations 线段树

    题目大意 题目链接Naive Operations 题目大意: 区间加1(在a数组中) 区间求ai/bi的和 ai初值全部为0,bi给出,且为n的排列,多组数据(<=5),n,q<=1e5 ...

  2. 杭电多校第二场 hdu 6315 Naive Operations 线段树变形

    Naive Operations Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 502768/502768 K (Java/Other ...

  3. 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,另一种操 ...

  4. HDU 6315 Naive Operations(线段树区间整除区间)

    Problem DescriptionIn a galaxy far, far away, there are two integer sequence a and b of length n.b i ...

  5. 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, ...

  6. HDU6315 Naive Operations(线段树 复杂度分析)

    题意 题目链接 Sol 这题关键是注意到题目中的\(b\)是个排列 那么最终的答案最多是\(nlogn\)(调和级数) 设\(d_i\)表示\(i\)号节点还需要加\(d_i\)次才能产生\(1\)的 ...

  7. HDU 6315 Naive Operations(线段树+复杂度均摊)

    发现每次区间加只能加1,最多全局加\(n\)次,这样的话,最后的答案是调和级数为\(nlogn\),我们每当答案加1的时候就单点加,最多加\(nlogn\)次,复杂度可以得当保证. 然后问题就是怎么判 ...

  8. HDU-DuoXiao第二场hdu 6315 Naive Operations 线段树

    hdu 6315 题意:对于一个数列a,初始为0,每个a[ i ]对应一个b[i],只有在这个数字上加了b[i]次后,a[i]才会+1. 有q次操作,一种是个区间加1,一种是查询a的区间和. 思路:线 ...

  9. 2018HDU多校二 -F 题 Naive Operations(线段树)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6315 In a galaxy far, far away, there are two integer ...

  10. HDU6315 Naive Operations 线段树

    目录 Catalog Solution: (有任何问题欢迎留言或私聊 && 欢迎交流讨论哦 Catalog Problem:Portal传送门  原题目描述在最下面. Solution ...

随机推荐

  1. (转)为Spring集成的Hibernate配置二级缓存

    http://blog.csdn.net/yerenyuan_pku/article/details/52896195 前面我们已经集成了Spring4.2.5+Hibernate4.3.11+Str ...

  2. No-10.高级变量类型

    高级变量类型 目标 列表 元组 字典 字符串 公共方法 变量高级 知识点回顾 Python 中数据类型可以分为 数字型 和 非数字型 数字型 整型 (int) 浮点型(float) 布尔型(bool) ...

  3. Moebius for SQLServer负载均衡

    搞数据库的都知道:在Oracle上有RAC集群,MySQL也有对应的方案,而SQL Server上直到SQL Server 2012版本的AlwaysOn到来,微软都没有提供一个负载均衡方案,在网上看 ...

  4. docker-compose nginx

    docker-compose nginx example source code docker-compose nginx balancing

  5. VR技术在数据中心3D机房中的应用 (下)

    VR技术在数据中心3D机房中的应用 (下) 前面给大家简单科普了一下VR的硬件设备以及VR在各个领域的应用,是不是觉得非常高大上?千言万语概括成一句话,VR能给用户带来前所未有的沉浸感和交互方式,让人 ...

  6. 695. Max Area of Island@python

    Given a non-empty 2D array grid of 0's and 1's, an island is a group of 1's (representing land) conn ...

  7. 重载操作符 'operator'

    operator 是 C++ 的(运算符的)重载操作符.用作扩展运算符的功能. 它和运算符一起使用,表示一个运算符函数,理解时应将  [operator+运算符] 整体上视为一个函数名. 要注意的是: ...

  8. HDU - 5438 Ponds(拓扑排序删点+并查集判断连通分量)

    题目: 给出一个无向图,将图中度数小于等于1的点删掉,并删掉与他相连的点,直到不能在删为止,然后判断图中的各个连通分量,如果这个连通分量里边的点的个数是奇数,就把这些点的权值求和. 思路: 先用拓扑排 ...

  9. POJ-2442-Sequence(二叉堆)

    POJ-2442 Description Given m sequences, each contains n non-negative integer. Now we may select one ...

  10. ubuntu中执行docker info出现警告信息WARNING: No memory limit support 或 WARNING: No swap limit support

    docker info 指令报若下错误:WARNING: No memory limit support 或WARNING: No swap limit support 解决方法: 1.打开/etc/ ...