分析:

最长不降子序列,n很大o(n^2)肯定超,想到了小明序列那个题用线段树维护前面的最大值即可

该题也可用二分搜索来做。

注意问题输出时的坑,路复数后加s

#include <map>
#include <set>
#include <list>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdio>
#include <vector>
#include <string>
#include <cctype>
#include <complex>
#include <cassert>
#include <utility>
#include <cstring>
#include <cstdlib>
#include <iostream>
#include <algorithm>
using namespace std;
typedef pair<int,int> PII;
typedef long long ll;
#define lson l,m,rt<<1
#define pi acos(-1.0)
#define rson m+1,r,rt<<1|1
#define All 1,N,1
#define N 500010
#define read freopen("in.txt", "r", stdin)
const ll INFll = 0x3f3f3f3f3f3f3f3fLL;
const int INF= 0x7ffffff;
const int mod = ;
struct city{
int p,r;
}t[N];
bool cmp(city x,city y){
return x.p<y.p;
}
int maxv[N*],n,dp[N];
void pushup(int rt){
maxv[rt]=max(maxv[rt<<],maxv[rt<<|]);
}
void build(int l,int r,int rt){
maxv[rt]=;
if(l==r){
return;
}
int m=(l+r)>>;
build(lson);
build(rson);
}
void update(int p,int v,int l,int r,int rt){
if(l==r){
maxv[rt]=max(maxv[rt],v);
return;
}
int m=(l+r)>>;
if(p<=m)update(p,v,lson);
else update(p,v,rson);
pushup(rt);
}
int query(int L,int R,int l,int r,int rt){
if(L<=l&&R>=r)
return maxv[rt];
int m=(l+r)>>;
int ans=;
if(L<=m)ans=max(ans,query(L,R,lson));
if(R>m)ans=max(ans,query(L,R,rson));
return ans;
}
int main()
{
int ca=;
while(~scanf("%d",&n)){
memset(dp,,sizeof(dp));
for(int i=;i<n;++i)
scanf("%d%d",&t[i].p,&t[i].r);
sort(t,t+n,cmp);
build(,n,);
int maxn=;
for(int i=;i<n;++i){
dp[i]=query(,t[i].r,,n,)+;
maxn=max(maxn,dp[i]);
update(t[i].r,dp[i],,n,);
}
printf("Case %d:\n",++ca);
if(maxn>)
printf("My king, at most %d roads can be built.\n",maxn);
else
printf("My king, at most %d road can be built.\n",maxn);
printf("\n");
}
return ;
}

最新文章

  1. 让你的网站免费支持 HTTPS 及 Nginx 平滑升级
  2. Python小练习四
  3. centos6.5编译安装git
  4. .NET框架面向对象分层的个人想理
  5. hdu 2050
  6. mapreduce执行流程
  7. 解决iPhone上select时常失去焦点,随意跳到下一个输入框,影响用户操作
  8. su Authentication failure解决
  9. IIS7和IIS7.5备份和还原的方法
  10. 设计模式20---设计模式之备忘录模式(Memento)(行为型)
  11. Gentoo:Xorg:Failed to load module &quot;……&quot; 问题
  12. Struts2学习笔记②
  13. activemq Linux下的编译
  14. ASP.NET Core学习之三 NLog日志
  15. Luogu P1226 取余运算||快速幂_快速幂
  16. JUC--volatiley&amp;CAS
  17. vue.js实战——splice使用
  18. git学习小游戏
  19. QSS独门秘籍:subcontrol
  20. Oracle实用操作

热门文章

  1. lintcode:previous permutation上一个排列
  2. GDB笔记
  3. 【nginx运维基础(4)】Nginx的日志管理(日志格式与定时分割日志)
  4. 【Linux高频命令专题(20)】du
  5. 【nginx运维基础(2)】Nginx的配置文件说明及虚拟主机配置示例
  6. Hibernate逍遥游记-第13章 映射实体关联关系-006双向多对多(分解为一对多)
  7. Qt网络通信骨架解析,QtClient QtServer QtSerialPort
  8. Map.putAll方法——追加另一个Map对象到当前Map集合(转)
  9. showdialog()与show的区别
  10. shell bash判断文件或文件夹是否存在