让ci = ai / bi, 求sum(ci)的值,因为每次 ai 都是加一的,那么我可以用一颗线段树来维护每个 i 位置的 ai 距离达到 bi 还需要的数的最小值,更新是每次都减一,如果我某一个区间的最小值等于 0, 这就说明我这时候的ai已经满足了ai/bi==1的情况,那么对应的ci的位置就应该加一,所以我每次发现一个区间的最小值是0的话,我就 dfs 去找到为0的地方,把这里重新修改成bi,然后这个位置的答案+1就可以了

#include<map>
#include<set>
#include<ctime>
#include<cmath>
#include<stack>
#include<queue>
#include<string>
#include<vector>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<iostream>
#include<algorithm>
#define first fi
#define second se
#define lowbit(x) (x & (-x)) typedef unsigned long long int ull;
typedef long long int ll;
const double pi = 4.0*atan(1.0);
const int inf = 0x3f3f3f3f;
const int maxn = ;
const int maxm = ;
const int mod = ;
using namespace std; int n, m, tol, T;
int a[maxn];
int b[maxn];
int c[maxn << ];
int sum[maxn << ];
int lazy[maxn << ]; void init() {
memset(a, , sizeof a);
memset(b, , sizeof b);
memset(c, , sizeof c);
memset(sum, inf, sizeof sum);
memset(lazy, , sizeof lazy);
} void pushup(int root) {
sum[root] = min(sum[root << ], sum[root << | ]);
c[root] = c[root << ] + c[root << | ];
} void pushdown(int root) {
if(lazy[root] != ) {
lazy[root << ] += lazy[root];
lazy[root << | ] += lazy[root];
sum[root << ] -= lazy[root];
sum[root << | ] -= lazy[root];
lazy[root] = ;
}
return ;
} void build(int left, int right, int root) {
if(left == right) {
sum[root] = b[left];
return ;
}
int mid = (left + right) >> ;
build(left, mid, root << );
build(mid+, right, root << | );
pushup(root);
} void dfs(int left, int right, int root) {
if(left == right) {
if(sum[root] == ) {
sum[root] = b[left];
c[root]++;
}
return ;
}
pushdown(root);
int mid = (left + right) >> ;
if(sum[root << ] == )
dfs(left, mid, root << );
if(sum[root << | ] == )
dfs(mid+, right, root << | );
pushup(root);
} void update(int left, int right, int prel, int prer, int root) {
if(prel <= left && right <= prer) {
lazy[root]++;
sum[root]--;
while(sum[root] == ) dfs(left, right, root);
return ;
}
pushdown(root);
int mid = (left + right) >> ;
if(prel <= mid) update(left, mid, prel, prer, root << );
if(prer > mid) update(mid+, right, prel, prer, root << | );
pushup(root);
} int query(int left, int right, int prel, int prer, int root) {
if(prel <= left && right <= prer) return c[root];
int mid = (left + right) >> ;
int ans = ;
if(prel <= mid) ans += query(left, mid, prel, prer, root << );
if(prer > mid) ans += query(mid+, right, prel, prer, root << | );
return ans;
} int main() {
while(~scanf("%d%d", &n, &m)) {
init();
for(int i=; i<=n; i++) scanf("%d", &b[i]);
build(, n, );
char str[];
while(m--) {
int l, r;
scanf("%s%d%d", str, &l, &r);
if(str[] == 'a') {
update(, n, l, r, );
} else if(str[] == 'q') {
int ans = query(, n, l, r, );
printf("%d\n", ans);
}
}
}
return ;
}

Naive Operations HDU6315 (杭电多校2G)的更多相关文章

  1. 可持久化线段树的学习(区间第k大和查询历史版本的数据)(杭电多校赛第二场1011)

    以前我们学习了线段树可以知道,线段树的每一个节点都储存的是一段区间,所以线段树可以做简单的区间查询,更改等简单的操作. 而后面再做有些题目,就可能会碰到一种回退的操作.这里的回退是指回到未做各种操作之 ...

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

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

  3. 2018 Multi-University Training Contest 2 杭电多校第二场

    开始逐渐习惯被多校虐orz  菜是原罪 1004  Game    (hdoj 6312) 链接:http://acm.hdu.edu.cn/showproblem.php?pid=6312 虽然披着 ...

  4. 2018 Multi-University Training Contest 1 杭电多校第一场

    抱着可能杭电的多校1比牛客的多校1更恐怖的想法 看到三道签到题 幸福的都快哭出来了好吗 1001  Maximum Multiple(hdoj 6298) 链接:http://acm.hdu.edu. ...

  5. 2018 杭电多校2 - Naive Operations

    题目链接 Problem Description In a galaxy far, far away, there are two integer sequence a and b of length ...

  6. 2018 Multi-University Training Contest 9 杭电多校第九场 (有坑待补)

    咕咕咕了太久  多校博客直接从第三场跳到了第九场orz 见谅见谅(会补的!) 明明最后看下来是dp场 但是硬生生被我们做成了组合数专场…… 听说jls把我们用组合数做的题都用dp来了遍 这里只放了用组 ...

  7. hdu6356 Glad You Came 杭电多校第五场 RMQ ST表(模板)

    Glad You Came Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others) ...

  8. 2019杭电多校&CCPC网络赛&大一总结

    多校结束了, 网络赛结束了.发现自己还是太菜了,多校基本就是爆零和签到徘徊,第一次打这种高强度的比赛, 全英文,知识点又很广,充分暴露了自己菜的事实,发现数学还是很重要的.还是要多刷题,少玩游戏. 网 ...

  9. 杭电多校第一场-B-Operation

    题目描述 There is an integer sequence a of length n and there are two kinds of operations:0 l r: select ...

随机推荐

  1. 常见的 CSRF、XSS、sql注入、DDOS流量攻击

    CSRF攻击 :跨站请求伪造攻击 ,CSRF全名是Cross-site request forgery,是一种对网站的恶意利用,CSRF比XSS更具危险性 攻击者一般会使用吸引人的图片去引导用户点击进 ...

  2. java设计模式:概述与GoF的23种设计模式

    软件设计模式的产生背景 设计模式这个术语最初并不是出现在软件设计中,而是被用于建筑领域的设计中. 1977 年,美国著名建筑大师.加利福尼亚大学伯克利分校环境结构中心主任克里斯托夫·亚历山大(Chri ...

  3. freemarker数值格式化

    语法:number?string(exp) 说明:根据给定的格式化表达式将数值格式化为字符串. 参数:格式化字符串,"0"表示固定占位(至少有这个位数,不足位数用0代替),&quo ...

  4. [转帖]NUMA

    作者:ibless 来源:CSDN 原文:https://blog.csdn.net/ibless/article/details/80114009 其实 很早之前对这一块有了解 比较多的的是 CCN ...

  5. CentOS7配置gradle,或配置maven

    借鉴博客: https://www.cnblogs.com/imyalost/p/8746527.html 特简单,不多说了,自己看 1.下载gradle4.6版本:wget https://down ...

  6. mysql 允许特定IP访问

      1. 测试是否允许远程连接 $ telnet 192.168.1.8 3306 host 192.168.1.4 is not allowed to connect to this mysql s ...

  7. flask 下载本地文件

    下载本地文件就是找到文件路径  调用flask自带的send_file(路径)下载, 并返回 flask: # 下载文件 from flask import send_file@task_mgm.ro ...

  8. MySQL 5.7 关闭严格模式

    If your app was written for older versions of MySQL and is not compatible with strict SQL mode in My ...

  9. Python学习之路—————day04

    今日内容: 1. 循环语句 1.1 if判断 1.2 while循环 1.3 for循环 一.if判断 语法一: if 条件 代码块1 代码块2 代码块3 # 例: sex='female' age= ...

  10. vue axios 封装(二)

    封装二: http.js import axios from 'axios' import storeHelper from './localstorageHelper' // 全局设置 const ...