HDU - 4420 2013icpc长春A 函数离散化 + st表
思路:我们定义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表的更多相关文章
- ST函数(ST表)RMQ O(1)查询 离线
ST算法是基于倍增的动态规划算法. #include<iostream> #include<cstdio> #include<cstdlib> #include&l ...
- ECNU 3480 没用的函数 (ST表预处理 + GCD性质)
题目链接 ECNU 2018 JAN Problem E 这题卡了双$log$的做法 令$gcd(a_{i}, a_{i+1}, a_{i+2}, ..., a_{j}) = calc(i, j)$ ...
- Hdu 5289-Assignment 贪心,ST表
题目: http://acm.hdu.edu.cn/showproblem.php?pid=5289 Assignment Time Limit: 4000/2000 MS (Java/Others) ...
- HDU 5875 Function(ST表+二分)
[题目链接] http://acm.hdu.edu.cn/showproblem.php?pid=5875 [题目大意] 给出一个数列,同时给出多个询问,每个询问给出一个区间,要求算出区间从左边开始不 ...
- HDU 4123 Bob's Race:树的直径 + 单调队列 + st表
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4123 题意: 给你一棵树,n个节点,每条边有长度. 然后有m个询问,每个询问给定一个q值. 设dis[ ...
- 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 ...
- hdu 6434 Count (欧拉函数)
题目链接 Problem Description Multiple query, for each n, you need to get $$$$$$ \sum_{i=1}^{n} \sum_{j=1 ...
- 2019CCPC网络赛 C - K-th occurrence HDU - 6704(后缀数组+ST表+二分+主席树)
题意 求区间l,r的子串在原串中第k次出现的位置. 链接:https://vjudge.net/contest/322094#problem/C 思路 比赛的时候用后缀自动机写的,TLE到比赛结束. ...
- 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, ...
随机推荐
- python---基础知识回顾(十)进程和线程(协程gevent:线程在I/O请求上的优化)
优点:使用gevent协程,可以更好的利用线程资源.(基于线程实现) 需求:使用一个线程,去请求多个网站的资源(注意,请求上会有延时)<实际上是去请求了大量的网站信息,我们使用了多线程,只不过每 ...
- "\n" 与"\r" 区别
关于换行和回车其实平时我们不太在意,所以关于两者的区别也不太清楚,在平时开发时可能会遇到一些文件处理的问题,放到不同的操作系统上出现各种坑.那么回车和换行到底有哪些区别呢?今天咱们就来总结一下. 1. ...
- springmvc转springboot过程中访问jsp报Whitelabel Error Page错误
前言: 虽然springboot内嵌了一个tomcat,但是这个内嵌的tomcat不支持jsp页面,所以需要引入其他包 解决: maven引入以下包即可 <dependency> < ...
- 【Foreign】动态规划 [分治][DP]
动态规划 Time Limit: 50 Sec Memory Limit: 128 MB Description 一开始有n个数,一段区间的价值为这段区间相同的数的对数. 我们想把这n个数切成恰好k ...
- input输出类型
http://www.w3school.com.cn/html5/html_5_form_input_types.asp
- ORA 00972 错误处理
Oracle 11G SQL 写好的脚本执行后报错:ORA 00972 标识符过长 可能的原因一: select 语句中的字段别名太长,中文字符别名最长为10个汉字,简化别名名称,问题得到解决. 可能 ...
- sql server 查询本年的每个月的数据
一.以一行数据的形式,显示本年的12月的数据,本示例以2017年为例,根据CreateDate字段判断,计算总和,查询语句如下: end) as '1月', end) as '2月', end) as ...
- Django框架下的小人物--Cookie
1. 什么是Cookie,它的用途是什么? Cookies是一些存储在用户电脑上的小文件.它是被设计用来保存一些站点的用户数据,这样能够让服务器为这样的用户定制内容,后者页面代码能够获取到Cookie ...
- 【译】第九篇 Replication:复制监视器
本篇文章是SQL Server Replication系列的第九篇,详细内容请参考原文. 复制监视器允许你查看复制配置组件的健康状况.这一篇假设你遵循前八篇,并且你已经有一个合并发布和事务发布.启动复 ...
- js 语法简写积累
if (!a || !b || !c || !d){//} 简写为:if([a, b, c, d].map(Boolean).includes(false)){//};