(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 首先我们在建立线段树之前应该思考的是线段树的节点维护一个什么 ...
随机推荐
- WebAPI前置知识:HTTP与RestfulAPI
对HTTP协议的基本了解是能理解并使用RestFul风格API的基础,在了解了这些基础之后,使用各种RestFul的开发框架才能得心应手.我一开始使用WebApi的时候就因为对这些知识缺乏了解,觉得用 ...
- anaconda中安装TensorFlow的方法
作为一个新手党加手残党真的折腾了好久才搞定,记录一下. step1:在anaconda prompt终端中输入 pip3 install -i https://pypi.tuna.tsinghua.e ...
- 从Scratch到Python——Python生成二维码
# Python利用pyqrcode模块生成二维码 import pyqrcode import sys number = pyqrcode.create('从Scratch到Python--Pyth ...
- Xiangqi(简单模拟)
4746: Xiangqi 时间限制(普通/Java):1000MS/3000MS 内存限制:65536KByte 总提交: 15 测试通过:2 描述 Xiangqi i ...
- Java中的集合类,集合类有哪些,如何增添删除元素,如何遍历
http://www.cnblogs.com/LittleHann/p/3690187.html import java.util.*; public class TestCollection { p ...
- JS 作用域与变量提升---JS 学习笔记(三)
你知道下面的JavaScript代码执行时会输出什么吗? var foo = 1; function bar() { if (!foo) { var foo = 10; } console.log(f ...
- Kotlin 类和对象
类定义 Kotlin 类可以包含:构造函数和初始化代码块.函数.属性.内部类.对象声明. Kotlin 中使用关键字 class 声明类,后面紧跟类名: class Runoob { // 类名为 R ...
- Project Euler 75: Singular integer right triangles
题目链接 思路: 勾股数组,又称毕达格拉斯三元组. 公式:a = s*t b = (s^2 - t^2) / 2 c = (s^2 + t^2) / 2 s > t >=1 且为互质的奇数 ...
- Go语言学习之14 商品秒杀架构设计与开发
本节主要内容 1. 秒杀抢购背景2. 秒杀抢购架构设计&模块划分3. 秒杀抢购接入层实现 1. 秒杀抢购背景 (1)架构分析 电商网站架构 秒杀抢购1.0 (2)上述网站架构问题 和已有电商逻 ...
- 倍增法求LCA(最近公共最先)
对于有根树T的两个结点u.v,最近公共祖先x=LCA(u,v)表示一个结点x,满足x是u.v的祖先且x的深度尽可能大. 如图,根据定义可以看出14和15的最近公共祖先是10, 15和16的最近公共 ...