B - Strip

思路:简单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表+单调队列的更多相关文章

  1. 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 ...

  2. 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 ...

  3. 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 ...

  4. 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 ...

  5. 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 ...

  6. Codeforces Round #622 (Div. 2) C2. Skyscrapers (hard version)(单调栈,递推)

    Codeforces Round #622 (Div. 2) C2. Skyscrapers (hard version) 题意: 你是一名建筑工程师,现给出 n 幢建筑的预计建设高度,你想建成峰状, ...

  7. 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 ...

  8. 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 ...

  9. Codeforces Round #278 (Div. 1) D - Conveyor Belts 分块+dp

    D - Conveyor Belts 思路:分块dp, 对于修改将对应的块再dp一次. #include<bits/stdc++.h> #define LL long long #defi ...

随机推荐

  1. thinkphp使用with对关联数据进行预加载

    1.with('relation'),只预加载relation这个关联,如下面 public function relation() { return $this->hasOne(Relatio ...

  2. php输出控制函数存在的意义

    因为http协议的限制(前几行必须是协议信息,然后一个空行,然后才是用户需要的内容), 需要保证header信息在其他内容之前发送,否则浏览器无法解析服务器返回的内容.

  3. libiop网络库数据结构和基础知识

    最近朋友推荐,学习了libiop这个网络库,作者封装的很全面,代码很简洁 适合初学者学习基于事件驱动的网络io 先看看iop_def.h, 这里面定义了常用的数据结构 tag_iop_base_t 主 ...

  4. nginx如何配置虚拟主机

    server { listen 80; #listen [::]:80 default_server ipv6only=on; server_name local.presion.caomall.ne ...

  5. nginx日志增加cookie信息

    一.获取全部cookie信息 这个比较方便,直接在nginx.conf文件中添加$http_cookie log_format main '[$time_local] - $remote_addr:$ ...

  6. Ubuntu+NDK编译openssl

    为了Android上使用libcurl且支持HTTPS协议,需要依赖openssl,因此先来了解一下如何编译OpenSSL1.编译ARM下的共享库(默认的)我使用的是guardianproject的o ...

  7. kvm虚拟机

    ###查看虚拟机的状态 [root@fgeserver2 ~]# virsh list --all Id Name State------------------------------------- ...

  8. CodeBlocks的常用快捷键

    CodeBlocks常用操作快捷键 编辑部分: Ctrl + A:全选 Ctrl + C:复制 Ctrl + X: 剪切 Ctrl + V:粘贴 Ctrl + Z:撤销 Ctrl + S:保存 Ctr ...

  9. ZOJ 3780 E - Paint the Grid Again 拓扑排序

    https://vjudge.net/problem/49919/origin 题意:给你n*n只出现O和X的字符阵.有两种操作,一种操作Ri将i行全变成X,一种操作Ci将i列全变成O,每个不同的操作 ...

  10. JAVA多线程提高一:传统线程技术&传统定时器Timer

    前面我们已经对多线程的基础知识有了一定的了解,那么接下来我们将要对多线程进一步深入的学习:但在学习之前我们还是要对传统的技术进行一次回顾,本章我们回顾的则是:传统线程技术和传统的定时器实现. 一.传统 ...