原题链接

神仙\(DP\)啊。。。

题解请移步隔壁大佬的博客\(QAQ\)

#include<cstdio>
using namespace std;
const int N = 2e5 + 10;
int L[N], R[N], q[N], f[N];
inline int re()
{
int x = 0;
char c = getchar();
bool p = 0;
for (; c < '0' || c > '9'; c = getchar())
p |= c == '-';
for (; c >= '0' && c <= '9'; c = getchar())
x = x * 10 + c - '0';
return p ? -x : x;
}
inline int minn(int x, int y)
{
return x < y ? x : y;
}
inline int maxn(int x, int y)
{
return x > y ? x : y;
}
int main()
{
int i, j = 0, n, m, x, y, l = 1, r = 0;
n = re();
m = re();
for (i = 2; i <= n + 1; i++)
R[i] = i - 1;
for (i = 1; i <= m; i++)
{
x = re();
y = re();
R[y] = minn(R[y], x - 1);
L[y + 1] = maxn(L[y + 1], x);
}
for (i = n; i; i--)
R[i] = minn(R[i], R[i + 1]);
for (i = 2; i <= n + 1; i++)
L[i] = maxn(L[i], L[i - 1]);
for (i = 1; i <= n + 1; i++)
{
for (; j <= R[i]; j++)
if (f[j] >= 0)
{
for (; l <= r && f[q[l]] < f[j]; r--);
q[++r] = j;
}
for (; l <= r && q[l] < L[i]; l++);
if (l <= r)
f[i] = f[q[l]] + 1;
else
f[i] = -1;
}
printf("%d", f[n + 1] > 0 ? f[n + 1] - 1 : -1);
return 0;
}

洛谷3084 [USACO13OPEN]照片Photo的更多相关文章

  1. 洛谷 P3084 [USACO13OPEN]照片Photo 解题报告

    [USACO13OPEN]照片Photo 题目描述 农夫约翰决定给站在一条线上的\(N(1 \le N \le 200,000)\)头奶牛制作一张全家福照片,\(N\)头奶牛编号\(1\)到\(N\) ...

  2. Luugu 3084 [USACO13OPEN]照片Photo

    很神仙的dp...假装自己看懂了,以后回来复习复习... 设$f_{i}$表示从$1$到$i$,且$i$这个点必放的最大数量. 一个区间有两个限制条件:至少放一个,至多放一个. 因为一个区间至多要放一 ...

  3. 洛谷P3084 [USACO13OPEN]照片

    题目 \(DP\) 设状态\(dp[i]\)为\(i\)位置放了斑点牛,前\(i\)个位置能得到的最多的牛. 有方程\(dp[i]=max(dp[j]+1,dp[i])\),而我们并不知道什么\(j\ ...

  4. 洛谷P3085 [USACO13OPEN]阴和阳Yin and Yang(点分治,树上差分)

    洛谷题目传送门 闲话 偶然翻到一道没有题解的淀粉质,想证明一下自己是真的弱 然而ZSYC(字符串组合)早就切了 然后证明成功了,WA到怀疑人生,只好借着ZSY的代码拍,拍了几万组就出来了... 思路 ...

  5. 洛谷P3608 [USACO17JAN]Balanced Photo平衡的照片

    P3608 [USACO17JAN]Balanced Photo平衡的照片 题目描述 Farmer John is arranging his NN cows in a line to take a ...

  6. [USACO13OPEN]照片Photo

    题目描述 Farmer John has decided to assemble a panoramic photo of a lineup of his N cows (1 <= N < ...

  7. P3084 [USACO13OPEN]照片Photo (dp+单调队列优化)

    题目链接:传送门 题目: 题目描述 Farmer John has decided to assemble a panoramic photo of a lineup of his N cows ( ...

  8. P3084 [USACO13OPEN]照片Photo

    题目描述 农夫约翰决定给站在一条线上的N(1 <= N <= 200,000)头奶牛制作一张全家福照片,N头奶牛编号1到N. 于是约翰拍摄了M(1 <= M <= 100,00 ...

  9. 洛谷 P1583 魔法照片【二级结构体排序】

    题目描述 一共有n(n≤20000)个人(以1--n编号)向佳佳要照片,而佳佳只能把照片给其中的k个人.佳佳按照与他们的关系好坏的程度给每个人赋予了一个初始权值W[i].然后将初始权值从大到小进行排序 ...

随机推荐

  1. tensorflow serving 中 No module named tensorflow_serving.apis,找不到predict_pb2问题

    最近在学习tensorflow serving,但是运行官网例子,不使用bazel时,发现运行mnist_client.py的时候出错, 在api文件中也没找到predict_pb2,因此,后面在网上 ...

  2. 上任com的发布流程

    参考:https://blog.csdn.net/qq_19674905/article/details/80268815 首先把本地代码提交到远程自己的git分支,然后merge request到m ...

  3. GitLab 汉化

    汉化Gitlab Gitlab默认语言是英文,对于想加强英文的同学,建议继续使用英文,但要求使用中文,这里需要下载一个汉化包下载最新的汉化包: 下载最新的汉化包: [root@gitlab ~]# g ...

  4. @JsonInclude(JsonInclude.Include.NON_NULL) 加在对象上

    @JsonInclude(JsonInclude.Include.NON_NULL) public class ViewWorkermessage implements Serializable { ...

  5. appium桌面版本以及一些自动化测试方方封装

    appium_desktop 标签(空格分隔): appium_desktop 一 appium_desktop_v1.2.6 1.appium_desktop在github上最新下载地址:appiu ...

  6. CRTD模拟MFG工单进行绑定优化

    需求:按单按库生产的CRTD状态半成品工单重复创建问题 绑定成功案例: SELECT DEMANDLINEID,SUPPLYORDERID,DEMANDORDERID,QTYALLOCATED,ITE ...

  7. day31 粘包问题

    TCP粘包问题 cmd客户端代码 import socket import struct import socket import json c = socket.socket() c.connect ...

  8. eCharts 折线图,动态绑定数据不更新图表的问题,

    官方文档 : http://echarts.baidu.com/tutorial.html npm install echarts --save let lineChart = echarts.ini ...

  9. vue confirm确认

    this.$confirm('您确定删除吗?').then(_ => { do something ... (确认) }).catch(_ => { do something ... (取 ...

  10. CentOS 下搭建Gitlab

    centos7安装部署gitlab服务器   我这里使用的是centos 7 64bit,我试过centos 6也是可以的! 1. 安装依赖软件 yum -y install policycoreut ...