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, ...
随机推荐
- SecureCRT无法使用root正常连接Ubuntu 14.0.4.1的解决办法
问题描述 通过VirtualBox重新安装了Ubuntu 14.0.4.1 虚拟服务器,在SercureCRT中使用root帐号连接Ubuntu14.0.4.1的时候,提示“Password Auth ...
- vue2借助animate.css实现路由动画效果
第一步: npm install animate.css --save 第二步:打开main.js import animate from 'animate.css' Vue.use(animate) ...
- COGS 5. P服务点设置
5. P服务点设置 http://www.cogs.pro/cogs/problem/problem.php?pid=5 ★★ 输入文件:djsc.in 输出文件:djsc.out 简单对 ...
- Chip Factory(HDU5536 + 暴力 || 01字典树)
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5536 题目: 题意: 对于给定的n个数,求出三个下标不同的数使得(si+sj)^sk最大. 思路: ...
- Linux基础-swap交换分区
任务:对一块15G大小的硬盘进行分区,主分区为5G,扩展分区10G,一个逻辑分区5G作为swap交换分区,并激活查看新的swap分区 第一步,建立的新的SCSI硬盘,开启Linux系统前添加一块大小为 ...
- Fetch API 了解 及对比ajax、axois
Fetch是什么 Fetch 是一个现代的概念, 等同于 XMLHttpRequest.它提供了许多与XMLHttpRequest相同的功能,但被设计成更具可扩展性和高效性.Fetch被很多浏览器所支 ...
- WeX5入门之欢乐捕鱼打包
一.下载欢乐捕鱼的素材包 https://files.cnblogs.com/files/wordblog/%E7%B4%A0%E6%9D%90.zip 二.把欢乐捕鱼素材放入项目中 并启动tomca ...
- 从Python到Web开发
基础部分: 1-编程基础及Python环境部署 2-Python基础语法-内存管理-运算符-程序控制 3-Python内置结构-列表 4-Python数据类型之元组-字符串 5-python的封装与结 ...
- Flask小demo---代码统计系统
功能要求: 管理员登录 # 第一天 班级管理 # 第一天 学生管理 # 第一天 学生登录 上传代码(zip文件和.py文件) 查看个人提交记录列表 highchar统计 学生列表上方使用柱状图展示现班 ...
- poj1067
题意:有两堆石子,两人轮流取,每次可以取一堆中的任意个,或两堆中取相同多个.谁先取光所有堆谁赢.问先手能否获胜. 分析:威佐夫博弈,如果是奇异态则先手输,否则先手赢.直接套用公式判断是否为奇异态,设第 ...