思路:我们定义F(x) 为以x点为起点,向后(a - b)个里面有多少个白球,虽然x的范围是LL范围内的,但是白球的

个数只有1e5, 那么我们可以把连续一段相同的离散化到一起, 对于一个确定的长度为a的段, Bob选择留下F(x)

最小的那一个,这个可以用st表求出来, 那么对于Alice来说,对于函数F(x)离散化到一起的值域(p - q) , 我们如果

要在(p - q)之间选一个起点那么p这个点是最优的点。那么我们枚举这些p,选一个答案的最大值。

#include<bits/stdc++.h>
#define LL long long
#define fi first
#define se second
#define mk make_pair
#define PII pair<int, int>
#define PLI pair<LL, int>
#define ull unsigned long long
using namespace std; const int N = 2e5 + ;
const int inf = 0x3f3f3f3f;
const LL INF = 0x3f3f3f3f3f3f3f3f;
const int mod = 1e9 + ; ull n, L, R, a, b, c, dis, tot, p[N], range[N];
int f[N], Log[N]; struct ST {
int dp[N][],ty;
void build(int n, int b[], int _ty) {
ty = _ty;
for(int i = ; i <= n; i++) dp[i][] = ty*b[i];
for(int j = ; j <= Log[n]; j++)
for(int i = ; i+(<<j)- <= n; i++)
dp[i][j] = max(dp[i][j-], dp[i+(<<(j-))][j-]);
}
int query(int x, int y) {
if(x > y) return ;
int k = Log[y - x + ];
return ty * max(dp[x][k], dp[y-(<<k)+][k]);
}
} rmq; int main() {
for(int i = -(Log[]=-); i < N; i++)
Log[i] = Log[i - ] + ((i & (i - )) == );
while(scanf("%llu", &n) != EOF) {
tot = ;
scanf("%llu%llu%llu%llu", &L, &R, &a, &b);
for(int i = ; i <= n; i++)
scanf("%llu", &p[i]);
if(a == b) {
puts("");
} else {
c = a - b;
for(ull i = L, j = , k = ; i <= R; i += dis) {
while(k <= n && i > p[k]) k++;
while(j <= n && i+c- >= p[j]) j++;
f[++tot] = j - k;
dis = R - i + ;
if(k <= n) dis = min(dis, p[k]-i+);
if(j <= n) dis = min(dis, p[j]-i-c+);
range[tot] = i;
}
rmq.build(tot, f, -);
int ans = ;
for(int i = , j = ; i <= tot; i++) {
if(range[i]+a- > R) break;
while(j <= tot && range[j] <= range[i]+a-c) j++;
ans = max(ans, rmq.query(i, j-));
}
printf("%llu\n", ans);
}
}
return ;
} /*
*/

HDU - 4420 2013icpc长春A 函数离散化 + st表的更多相关文章

  1. ST函数(ST表)RMQ O(1)查询 离线

    ST算法是基于倍增的动态规划算法. #include<iostream> #include<cstdio> #include<cstdlib> #include&l ...

  2. ECNU 3480 没用的函数 (ST表预处理 + GCD性质)

    题目链接  ECNU 2018 JAN Problem E 这题卡了双$log$的做法 令$gcd(a_{i}, a_{i+1}, a_{i+2}, ..., a_{j}) = calc(i, j)$ ...

  3. Hdu 5289-Assignment 贪心,ST表

    题目: http://acm.hdu.edu.cn/showproblem.php?pid=5289 Assignment Time Limit: 4000/2000 MS (Java/Others) ...

  4. HDU 5875 Function(ST表+二分)

    [题目链接] http://acm.hdu.edu.cn/showproblem.php?pid=5875 [题目大意] 给出一个数列,同时给出多个询问,每个询问给出一个区间,要求算出区间从左边开始不 ...

  5. HDU 4123 Bob's Race:树的直径 + 单调队列 + st表

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4123 题意: 给你一棵树,n个节点,每条边有长度. 然后有m个询问,每个询问给定一个q值. 设dis[ ...

  6. HDU 4123 Bob’s Race 树的直径+ST表

    Bob’s Race Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=41 ...

  7. hdu 6434 Count (欧拉函数)

    题目链接 Problem Description Multiple query, for each n, you need to get $$$$$$ \sum_{i=1}^{n} \sum_{j=1 ...

  8. 2019CCPC网络赛 C - K-th occurrence HDU - 6704(后缀数组+ST表+二分+主席树)

    题意 求区间l,r的子串在原串中第k次出现的位置. 链接:https://vjudge.net/contest/322094#problem/C 思路 比赛的时候用后缀自动机写的,TLE到比赛结束. ...

  9. Find the hotel HDU - 3193 (ST表RMQ)

    Summer again! Flynn is ready for another tour around. Since the tour would take three or more days, ...

随机推荐

  1. day11 细节记忆

    单一职责:一个方法只做一件事. 值传递——java只有值传递. gender(性别) male(男)female(女) 自动生成的set.get方法中,布尔类型的get方法需要手工改为get(默认是i ...

  2. 递归和静态static

    function sum($n){ if($==1){ return 1; } return $n+sum($n-1); } echo sum(100); ---------------------- ...

  3. 用户管理_组管理_权限管理.ziw

    2017年1月10日, 星期二 用户管理_组管理_权限管理 用户管理: useradd, userdel, usermod, passwd, chsh, chfn, finger, id, chage ...

  4. Spring Cloud(十一)声名式服务调用:Feign的使用 (上)

    一.写在前边 最近开发任务比较忙,下班也开始锻炼了,这个系列的文章就放了很久,看github我提交的Feign的入门程序已经好久了,今天正好得空,这就更上一贴,准备分几部分写 注意:之前几个项目中,笔 ...

  5. 【总结】CSS透明度大汇总

    近年来,CSS不透明算得上是一种相当流行的技术,但在跨浏览器支持上,对于开发者来说,可以说是一件令人头疼的事情.目前还没有一个通用方法,以确保透明度设置可以在目前使用的所有浏览器上有效. 这篇汇总主要 ...

  6. 【BearChild】

    \(≧▽≦)/ BearChild is salty. If you want to save him,please call QQ:423339833 to talk♂with him. Have ...

  7. 【转】Graphics.DrawImage 方法 IntPtr 结构 GDI 句柄 知识收集

    Graphics.DrawImage 方法 在指定的位置使用原始物理大小绘制指定的 Image. 命名空间:System.Drawing 程序集:System.Drawing(在 system.dra ...

  8. sql server 查询本周、本月所有天数的数据

    查询本月所有的天数: --本月所有的天数 ),) day from (),,)+'-01' day) t1, ( ) t2 ),) ),,)+'%' 查询本周所有的天数: ),,),) ),,),) ...

  9. 关于onConfigurationChanged

    这两天测试app时,发现一个奇怪问题,app在启动后,Activity会onCreate两次,起初以为是横屏设置导致,随即在Activity中添加了android:configChanges=&quo ...

  10. python 爬虫简单的demo

    ''' @author :Eric-chen @contact:809512722@qq.com @time :2018/1/3 17:55 @desc :通过爬取http://movie.douba ...