(2018 Multi-University Training Contest 2)Problem G - Naive Operations
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6315
题目大意:告诉你a,b两个数组,a数组初始化为0,b数组告诉你长度和具体值,接下来有q次操作,add操作是从向区间[l,r]加1,query操作是求区[l,r]的ai/bi的总和。
解题思路:维护一个mn,表示这个区间里的a最少加几次才能有新的贡献。比如1最多对总和造成q的贡献,2最多q/2,q/3,q/4,一直到q/n。最少要加min(b[i]-a[i]%b[i])次才能有新的贡献,如果这个区间+1之后没有贡献,也就是mn>1,就直接打标记.
AC代码:
- #include<iostream>
- using namespace std;
- #define rep(i,a,n) for(int i=a;i<n;i++)
- #define clr(a,x) memset(a,x,sizeof(a))
- #define pb push_back
- #define mp make_pair
- #define inf 0x3f3f3f3f
- #define lson rt<<1
- #define rson rt<<1|1
- #define Lson l,m,lson
- #define Rson m+1,r,rson
- typedef long long ll;
- const ll mod= 1e9+;
- const int maxn=1e5+;
- int n;
- int a[maxn],b[maxn];
- char s[];
- int lazy[maxn<<],sum[maxn<<],mn[maxn<<];
- void pushup(int rt){
- sum[rt]=sum[lson]+sum[rson];
- mn[rt]=min(mn[lson],mn[rson]);
- }
- void pushdown(int rt,int m){
- if(lazy[rt]==){
- return;
- }
- lazy[lson]+=lazy[rt];
- lazy[rson]+=lazy[rt];
- mn[lson]-=lazy[rt];
- mn[rson]-=lazy[rt];
- lazy[rt]=;
- }
- void build(int l,int r,int rt){
- lazy[rt]=;
- sum[rt]=;
- if(l==r){
- mn[rt]=b[l];
- return ;
- }
- int m=(l+r)>>;
- build(Lson);
- build(Rson);
- pushup(rt);
- }
- void update(int L,int R,int add,int l,int r,int rt){
- if(L<=l&&r<=R&&mn[rt]>){
- lazy[rt]++,mn[rt]--;
- return ;
- }
- if(l==r){
- sum[rt]++;
- mn[rt]=b[l];
- return ;
- }
- pushdown(rt,r-l+);
- int m=(l+r)>>;
- if(L<=m) update(L,R,add,Lson);
- if(m<R) update(L,R,add,Rson);
- pushup(rt);
- }
- int query(int L,int R,int l,int r,int rt){
- if(L<=l&&r<=R){
- return sum[rt];
- }
- pushdown(rt,r-l+);
- int m=(r+l)>>,ret=;
- if(L<=m) ret+=query(L,R,Lson);
- if(m<R) ret+=query(L,R,Rson);
- return ret;
- }
- int main(){
- int q;
- while(~scanf("%d%d",&n,&q)){
- for(int i=;i<=n;i++){
- scanf("%d",&b[i]);
- }
- build(,n,);
- while(q--){
- int l,r;
- scanf("%s %d %d",s,&l,&r);
- if(s[]=='a'){
- update(l,r,,,n,);
- }else{
- printf("%d\n",query(l,r,,n,));
- }
- }
- }
- return ;
- }
(2018 Multi-University Training Contest 2)Problem G - Naive Operations的更多相关文章
- (2018 Multi-University Training Contest 3)Problem D. Euler Function
//题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6322 //题目大意:给定 k,求第 k 小的数 n,满足 φ(n) 是合数.显然 φ(1) = 1 ...
- (2018 Multi-University Training Contest 3)Problem L. Visual Cube
//题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6330//题目大意:按照一定格式画出一个 a×b×c 的长方体. #include <b ...
- ( 2018 Multi-University Training Contest 2)
2018 Multi-University Training Contest 2) HDU 6311 Cover HDU 6312 Game HDU 6313 Hack It HDU 6314 Mat ...
- zoj 4020 The 18th Zhejiang University Programming Contest Sponsored by TuSimple - G Traffic Light(广搜)
题目链接:The 18th Zhejiang University Programming Contest Sponsored by TuSimple - G Traffic Light 题解: 题意 ...
- HDU 5726 GCD (2016 Multi-University Training Contest 1)
Time Limit: 5000MS Memory Limit: 65536KB 64bit IO Format: %I64d & %I64u Description Give y ...
- HDU4888 Redraw Beautiful Drawings(2014 Multi-University Training Contest 3)
Redraw Beautiful Drawings Time Limit: 3000/1500 MS (Java/Others) Memory Limit: 65536/65536 K (Jav ...
- HDU 4897 Little Devil I(树链剖分)(2014 Multi-University Training Contest 4)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4897 Problem Description There is an old country and ...
- HDU 4906 Our happy ending(2014 Multi-University Training Contest 4)
题意:构造出n个数 这n个数取值范围0-L,这n个数中存在取一些数之和等于k,则这样称为一种方法.给定n,k,L,求方案数. 思路:装压 每位 第1为表示这种方案能不能构成1(1表示能0表示不能) ...
- hdu6315( 2018 Multi-University Training Contest 2)
bryce1010模板 http://acm.hdu.edu.cn/showproblem.php?pid=6315 /*hdu 1007 首先我们在建立线段树之前应该思考的是线段树的节点维护一个什么 ...
随机推荐
- CentOS7.X中使用yum安装nginx的方法
nginx官方文档说明:http://nginx.org/en/linux_packages.html#RHEL-CentOS 一.安装前准备: yum install yum-utils 二.添加源 ...
- CF Manthan, Codefest 16 B. A Trivial Problem
数学技巧真有趣,看出规律就很简单了 wa 题意:给出数k 输出所有阶乘尾数有k个0的数 这题来来回回看了两三遍, 想的方法总觉得会T 后来想想 阶乘 emmm 1*2*3*4*5*6*7*8*9 ...
- efk学习整理
概念 Logstash 数据收集处理引擎.支持动态的从各种数据源搜集数据,并对数据进行过滤.分析.丰富.统一格式等操作,然后存储以供后续使用. kibana 可视化化平台.它能够搜索.展示存储在 El ...
- 第 10 章 容器监控 - 080 - Weave Scope 容器地图
Weave Scope 容器地图 Weave Scope 的最大特点是会自动生成一张 Docker 容器地图,让我们能够直观地理解.监控和控制容器. 安装 执行如下脚本安装运行 Weave Scope ...
- caffe分类
1.制作数据 标签 label.bat dir/s/on/b >.txt 2.制作lmdb convert_lmdb.bat SET GLOG_logtostderr= E:\ca ...
- springboot killed springboot 无故停止运行解决办法
测试环境的服务部署在阿里云服务器上,运行一段时间总是自动宕掉,在配置文件里加上内存溢出配置,也不能打印出相关日志,一直找不出原因.今天在网上:http://www.cnblogs.com/chener ...
- HDOJ-2011
#include<iostream> #include<cstdio> using namespace std; int main(){ int m,n,i; float su ...
- git 拉取远程代码
git 拉取远程代码 || 利用vscode编辑器自带了git,可在ctrl+~打开控制台拉取代码,非常好用哦~在实际项目开发过程中,往往是已经存在远程项目了,我们定义的需求是只需要简单的操作git, ...
- 『超分辨率重建』从SRCNN到WDSR
超分辨率重建技术(Super-Resolution)是指从观测到的低分辨率图像重建出相应的高分辨率图像.SR可分为两类: 1. 从多张低分辨率图像重建出高分辨率图像 2. 从单张低分辨率图 ...
- pycharm配置QtDesigner
QtDesigner C:\Qt\Qt5.12.2\5.12.2\mingw73_64\bin\designer.exe $ProjectFileDir$ Pyuic C:\Anaconda3\pyt ...