Codeforces Round #278 (Div. 1) B - Strip dp+st表+单调队列
思路:简单dp,用st表+单调队列维护一下。
#include<bits/stdc++.h>
#define LL long long
#define fi first
#define se second
#define mk make_pair
#define PII pair<int, int>
#define y1 skldjfskldjg
#define y2 skldfjsklejg
using namespace std; const int N = 1e5 + ;
const int M = 1e7 + ;
const int inf = 0x3f3f3f3f;
const LL INF = 0x3f3f3f3f3f3f3f3f;
const int mod = ; int n, s, l, tot, head, rear, a[N], dp[N], stk[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) {
int k = Log[y - x + ];
return ty * max(dp[x][k], dp[y-(<<k)+][k]);
}
}mx, mn; bool check(int L, int R) {
return mx.query(L, R) - mn.query(L, R) <= s;
} int main() { for(int i = -(Log[]=-); i < N; i++)
Log[i] = Log[i - ] + ((i & (i - )) == ); memset(dp, -, sizeof(dp)); scanf("%d%d%d", &n, &s, &l);
for(int i = ; i <= n; i++) scanf("%d", &a[i]);
mx.build(n, a, ); mn.build(n, a, -); head = , rear = ;
for(int i = ; i <= n; i++) {
if(i >= l && check(, i)) {
dp[i] = ;
stk[++rear] = i;
continue;
}
while(rear >= head && !check(stk[head] + , i)) head++;
if(rear >= head && i - stk[head] >= l) {
dp[i] = dp[stk[head]] + ;
stk[++rear] = i;
}
}
printf("%d\n", dp[n]);
return ;
} /*
76 63 14
89 87 35
20 15 56
*/
Codeforces Round #278 (Div. 1) B - Strip dp+st表+单调队列的更多相关文章
- Codeforces Round #422 (Div. 2)E. Liar sa+st表+dp
题意:给你两个串s,p,问你把s分开顺序不变,能不能用最多k段合成p. 题解:dp[i][j]表示s到了前i项,用了j段的最多能合成p的前缀是哪里,那么转移就是两种,\(dp[i+1][j]=dp[i ...
- Codeforces Round #189 (Div. 1) B. Psychos in a Line 单调队列
B. Psychos in a Line Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/problemset/p ...
- Codeforces Round #278 (Div. 1) B. Strip multiset维护DP
B. Strip Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/487/problem/B De ...
- Codeforces Round #278 (Div. 2) D. Strip 线段树优化dp
D. Strip time limit per test 1 second memory limit per test 256 megabytes input standard input outpu ...
- Codeforces Round #189 (Div. 2) D. Psychos in a Line 单调队列dp
D. Psychos in a Line time limit per test 1 second memory limit per test 256 megabytes input standard ...
- Codeforces Round #622 (Div. 2) C2. Skyscrapers (hard version)(单调栈,递推)
Codeforces Round #622 (Div. 2) C2. Skyscrapers (hard version) 题意: 你是一名建筑工程师,现给出 n 幢建筑的预计建设高度,你想建成峰状, ...
- VK Cup 2016 - Round 1 (Div. 2 Edition) E. Bear and Contribution 单调队列
E. Bear and Contribution 题目连接: http://www.codeforces.com/contest/658/problem/E Description Codeforce ...
- Codeforces Round #278 (Div. 1) Strip (线段树 二分 RMQ DP)
Strip time limit per test 1 second memory limit per test 256 megabytes input standard input output s ...
- Codeforces Round #278 (Div. 1) D - Conveyor Belts 分块+dp
D - Conveyor Belts 思路:分块dp, 对于修改将对应的块再dp一次. #include<bits/stdc++.h> #define LL long long #defi ...
随机推荐
- idea plugin 插件开发之检测文件修改
实现 ApplicationComponent,BulkFileListener 接口,当然由于是 ApplicationComponent,因此需要在 plugin.xml 加上相关配置. plug ...
- 4.UiCollection API 详细介绍
一.UiCollection类介绍 UiCollection类两大功能:从集合中查找对象:获取某种搜索条件组件的数量 1.UiCollection类说明 1)UiCollection是UiObject ...
- (转) 使用vivado创建工程 4[完结]
由于自己手头暂时没有开发板,因此本节没有测试,故告之. Connecting to ZedBoardBefore we can run the application we have to conne ...
- HNOI2004 宠物收养所 (Treap)
1285 宠物收养所 http://codevs.cn/problem/1285/ 时间限制: 1 s 空间限制: 128000 KB 题目描述 Description 最近,阿Q开了一间 ...
- HDU 6053 TrickGCD 莫比乌斯函数/容斥/筛法
题意:给出n个数$a[i]$,每个数可以变成不大于它的数,现问所有数的gcd大于1的方案数.其中$(n,a[i]<=1e5)$ 思路:鉴于a[i]不大,可以想到枚举gcd的值.考虑一个$gcd( ...
- 51nod1471 小S的兴趣
题目来源: CodeForces 基准时间限制:1.5 秒 空间限制:131072 KB 分值: 320 小S喜欢有趣的事.但是,每个人的兴趣都是独特的.小S热衷于自问自答.有一天,小S想出了一个问题 ...
- 【BZOJ】2693: jzptab 莫比乌斯反演
[题意]2154: Crash的数字表格 莫比乌斯反演,多组询问,T<=10000. [算法]数论(莫比乌斯反演) [题解]由上一题, $ans=\sum_{g\leq min(n,m)}g\s ...
- CentOS7 升级gcc版本
CentOS7自带的GCC版本是4.8.5,如下所示: # cat /etc/redhat-release CentOS Linux release 7.6.1810 (Core) # which g ...
- Xcode下 gdb 调试命令
Xcode的调试器为用户提供了一个GDB的图形化界面,GDB是GNU组织的开放源代码调试器.您可以在Xcode的图形界面里做任何事情:但是,如果您需要您可以在命令行里使用GDB的命令,且gdb可以在终 ...
- AJAX的前世今生与未来
一.通过三个问答来认识一下Ajax 什么是Ajax? Ajax是Asynchronous Javascript And XML的缩写,它是一种技术. Ajax有什么用? 这一技术能够向服务器请求额外的 ...