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/Others)
Total Submission(s): 0 Accepted Submission(s): 0
b is a static permutation of 1 to n. Initially a is filled with zeroes.
There are two kind of operations:
1. add l r: add one for al,al+1...ar
2. query l r: query ∑ri=l⌊ai/bi⌋
For each test case, in the first line, two integers n,q, representing the length of a,b and the number of queries.
In the second line, n integers separated by spaces, representing permutation b.
In the following q lines, each line is either in the form 'add l r' or 'query l r', representing an operation.
1≤n,q≤100000, 1≤l≤r≤n, there're no more than 5 test cases.
1 5 2 4 3
1
2
4
4
6
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define mid int m = (l + r) >> 1
const int inf = 0x3f3f3f3f;
const int M = 1e5+;
double lazy[M<<];
double b[M],num[M],sum[M<<],minn[M<<];
vector<int>v;
void pushup(int rt){
minn[rt] = min(minn[rt<<],minn[rt<<|]);
} void pushdown(int rt){
if(lazy[rt]){
lazy[rt<<] += lazy[rt];
lazy[rt<<|] += lazy[rt];
minn[rt<<] -= lazy[rt];
minn[rt<<|] -= lazy[rt];
lazy[rt] = ;
}
} void build(int l,int r,int rt){
lazy[rt] = ; minn[rt] = inf;
if(l == r){
minn[rt] = b[l];
return ;
}
mid;
build(lson);
build(rson);
pushup(rt);
} void update(int L,int R,int l,int r,int rt){
if(L <= l&&R >= r){
minn[rt] -= ;
lazy[rt] += ;
return ;
}
pushdown(rt);
mid;
if(L <= m) update(L,R,lson);
if(R > m) update(L,R,rson);
pushup(rt);
} void update2(int p,int l,int r,int rt){
if(l == r){
minn[rt] = b[l];
return ;
}
mid;
pushdown(rt);
if(p <= m) update2(p,lson);
else update2(p,rson);
pushup(rt);
} int Query(int L,int R,int l,int r,int rt){
if(L <= l&&R >= r){
return minn[rt];
}
mid;
pushdown(rt);
int ret = inf;
if(L <= m) ret = min(Query(L,R,lson),ret);
if(R > m) ret = min(Query(L,R,rson),ret);
return ret;
} void query1(int l,int r,int rt){
if(l == r){
v.push_back(l);
return ;
}
mid;
pushdown(rt);
pushdown(rt);
if(minn[rt<<] == ) query1(lson);
if(minn[rt<<|] == ) query1(rson);
} void pushup1(int rt){
sum[rt] = sum[rt<<] + sum[rt<<|];
} void build1(int l,int r,int rt){
sum[rt] = ;
if(l == r){
sum[rt] = ;
return ;
}
mid;
build1(lson);
build1(rson);
pushup1(rt);
} void update1(int p,int l,int r,int rt){
if(l == r){
sum[rt] += ;
return ;
}
mid;
if(p <= m) update1(p,lson);
else update1(p,rson);
pushup1(rt);
} int query(int L,int R,int l,int r,int rt){
if(L <= l&&R >= r){
return sum[rt];
}
mid;
int ret = ;
if(L <= m) ret += query(L,R,lson);
if(R > m) ret += query(L,R,rson);
return ret;
} int main()
{
int n,q,x,l,r;
char op[];
while(scanf("%d%d",&n,&q)!=EOF){
for(int i = ;i <= n;i ++){
scanf("%d",&x);
b[i] = x;
}
build(,n,);
build1(,n,);
while(q--){
scanf("%s",op);
if(op[] == 'a'){
//cout<<"update"<<endl;
scanf("%d%d",&l,&r);
update(l,r,,n,); //将第一棵树的l,r区间-1
int cnt = Query(l,r,,n,);//求第一棵树的l,r区间的最小值
//cout<<"cnt: "<<cnt<<endl;
if(cnt == ){ //如果区间最小值为0
query1(,n,); //找到区间所有0的下表寸进vector里
for(int i = ;i < v.size(); i++){ //遍历
//cout<<"v[i] :"<<v[i]<<endl;
update1(v[i],,n,); //在第二颗数记下更新值
update2(v[i],,n,); //将现在为0的数变成原来的值
}
v.clear();
}
}
else {
//cout<<"query"<<endl;
scanf("%d%d",&l,&r);
int ans = query(l,r,,n,);
printf("%d\n",ans);
}
}
}
return ;
}
hdu 6315 Naive Operations (2018 Multi-University Training Contest 2 1007)的更多相关文章
- HDU 6315 Naive Operations(线段树+区间维护)多校题解
题意:a数组初始全为0,b数组题目给你,有两种操作: 思路:dls的思路很妙啊,我们可以将a初始化为b,加一操作改为减一,然后我们维护一个最小值,一旦最小值为0,说明至少有一个ai > bi,那 ...
- 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
题意:数量为N的序列a和b,a初始全为0,b为给定的1-N的排列.有两种操作:1.将a序列区间[L,R]中的数全部+1:2.查询区间[L,R]中的 ∑⌊ai/bi⌋(向下取整) 分析:对于一个位置i, ...
- 杭电多校第二场 hdu 6315 Naive Operations 线段树变形
Naive Operations Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 502768/502768 K (Java/Other ...
- HDU-DuoXiao第二场hdu 6315 Naive Operations 线段树
hdu 6315 题意:对于一个数列a,初始为0,每个a[ i ]对应一个b[i],只有在这个数字上加了b[i]次后,a[i]才会+1. 有q次操作,一种是个区间加1,一种是查询a的区间和. 思路:线 ...
- HDU 6315: Naive Operations
Naive Operations Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 502768/502768 K (Java/Other ...
- 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 【势能线段树】
<题目链接> 题目大意: 给出两个序列,a序列全部初始化为0,b序列为输入值.然后有两种操作,add x y就是把a数组[x,y]区间内全部+1,query x y是查询[x,y]区间内∑ ...
- HDU 6315 Naive Operations(线段树+复杂度均摊)
发现每次区间加只能加1,最多全局加\(n\)次,这样的话,最后的答案是调和级数为\(nlogn\),我们每当答案加1的时候就单点加,最多加\(nlogn\)次,复杂度可以得当保证. 然后问题就是怎么判 ...
随机推荐
- (三)Lua脚本语言入门(数组)
又要找工作了,变的忧虑了,唯有学习才让内心变得踏实,今天玩了一下午的王者荣耀,正事都忘了...... 如果认为所谓的毅力是每分每秒的“艰苦忍耐”式的奋斗,那这是一种很不足的心理状态.毅力是一种习惯,毅 ...
- C# 自定义类型转换
1.显式转换和隐式转换: ; long b=a; // 从int到long的隐式转换 int c=(int) b; // 从long到int是显式转换 ------------------------ ...
- 【php增删改查实例】第四节 -自己 DIY 一个数据库管理工具
本节介绍如何自己DIY一个数据库管理工具,可以在页面输入sql 进行简单的增删改查操作. 首先,找到xampp的安装目录,打开htdocs: 新建一个php文件,名称为 mysqladmin.php ...
- OpenCV实战:人脸关键点检测(FaceMark)
Summary:利用OpenCV中的LBF算法进行人脸关键点检测(Facial Landmark Detection) Author: Amusi Date: 2018-03-20 ...
- Codeforces 948D Perfect Security(字典树)
题目链接:Perfect Security 题意:给出N个数代表密码,再给出N个数代表key.现在要将key组排序,使key组和密码组的亦或所形成的组字典序最小. 题解:要使密码组里面每个数都找到能使 ...
- 如何解决markdown中图片上传的问题
1.第一种方式(图床) 1.1 google中的插件-新浪微博图床 2.第二种方式,操作流程如下 2.1 下载一个有道云笔记客户端 2.2 然后把图片通过有道云笔记分享出来,见下动态图 3.总结一下 ...
- KVM虚拟机管理——虚拟机创建和操作系统安装
1. 概述2. 交互式安装2.1 图形化-本地安装2.1.1 图形化本地CDROM安装2.2.2 图形化本地镜像安装2.2 命令行-本地安装2.2.1 命令行CDROM安装2.3 图形化-网络安装2. ...
- IDEA2018.1安装配置文档
一.软件安装 1. 下载地址: https://www.jetbrains.com/idea/download/#section=windows 2. 安装: 点击.exe,选择安装路径,点击next ...
- gym101522 [小熊骑士限定]La Salle-Pui Ching Programming Challenge 培正喇沙編程挑戰賽 2017
西瓜队(划掉),Kuma Rider久违的第一场训练,四小时瞎打.jpg A.水题,排序 #include<cstdio> #include<iostream> #includ ...
- kettle开源项目部署文档
kettle开源项目部署文档 1.kettle简介 kettle是一款国外开源的ETL(Extract Transform Load)工具,纯java编写,可以在Windows.Linux.Unix上 ...