根据题意很容易得到最原始的做法:

#include<iostream>
#include<cstdio>
#include<cstring>
#include<vector>
using namespace std;
const int N=100005;
int n,m,f[N];
int main(){scanf("%d",&n);int x;for(int i=1;i<=n;i++){scanf("%d",&x);for(int j=i-1;j>=x+1;j--)f[j+1]=f[j];int maxn=0;for(int j=0;j<=x;j++)maxn=max(maxn,f[j]);f[x+1]=maxn+1;maxn=0;for(int j=0;j<=i;j++)maxn=max(maxn,f[j]);printf("%d\n",maxn);}return 0;
}

接着,用splay,fhq_treap…这些数据结构实现在 f[ ] 数组中插入一个数、求区间最大值的操作就可以了

#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
#define Key_value ch[ch[root][1]][0]
const int N=100005*2;
const int inf=0x3f3f3f3f;
int fa[N],ch[N][2],key[N],sz[N],maxn[N];
int root,tot1;
int s[N],tot2;
int n;
void NewNode(int &x,int pre,int k){if(tot2) x=s[tot2--];else x=++tot1;ch[x][0]=ch[x][1]=0;fa[x]=pre;sz[x]=1;key[x]=maxn[x]=k;
}
void push_up(int x){sz[x]=sz[ch[x][0]]+sz[ch[x][1]]+1;maxn[x]=key[x];if(ch[x][0]) maxn[x]=max(maxn[x],maxn[ch[x][0]]);if(ch[x][1]) maxn[x]=max(maxn[x],maxn[ch[x][1]]);
}
void rotate(int x,int d){int y=fa[x];ch[y][!d]=ch[x][d];fa[ch[x][d]]=y;if(fa[y]) ch[fa[y]][ch[fa[y]][1]==y]=x;fa[x]=fa[y];ch[x][d]=y;fa[y]=x;push_up(y);
}
void splay(int x,int goal){while(fa[x]!=goal){if(fa[fa[x]]==goal)rotate(x,ch[fa[x]][0]==x);else{int y=fa[x];int d=(ch[fa[y]][0]==y);if(ch[y][d]==x){rotate(x,!d);rotate(x,d);}else{rotate(y,d);rotate(x,d);}}}push_up(x);if(goal==0) root=x;
}
int get_kth(int x,int k){int t=sz[ch[x][0]]+1;if(t==k) return x;if(t>k) return get_kth(ch[x][0],k);else get_kth(ch[x][1],k-t);
}
void update_insert(int x,int p){splay(get_kth(root,x+1),0);splay(get_kth(root,x+2),root);NewNode(Key_value,ch[root][1],p);push_up(ch[root][1]);push_up(root);
}
int query_maxn(int l,int r){splay(get_kth(root,l),0);splay(get_kth(root,r+2),root);return maxn[Key_value];
}
int main(){NewNode(root,0,inf);NewNode(ch[root][1],root,inf);NewNode(Key_value,ch[root][1],0);scanf("%d",&n);int x,p;for(int i=1;i<=n;i++){scanf("%d",&x);x++;p=query_maxn(1,x)+1;update_insert(x,p);printf("%d\n",query_maxn(1,i+1));}return 0;
}

(加1减1什么的真的快把我调疯了)

[BZOJ 3173] [TJOI 2013] 最长上升子序列(splay)相关推荐

  1. 【bzoj 3173】[Tjoi2013]最长上升子序列

    Description 给定一个序列,初始为空.现在我们将1到N的数字插入到序列中,每次将一个数字插入到一个特定的位置.每插入一个数字,我们都想知道此时最长上升子序列长度是多少? Input 第一行一 ...

  2. BZOJ 3170: [Tjoi 2013]松鼠聚会 切比雪夫距离

    3170: [Tjoi 2013]松鼠聚会 Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://www.lydsy.com/JudgeOnline/p ...

  3. bzoj 3170: [Tjoi 2013]松鼠聚会

    3170: [Tjoi 2013]松鼠聚会 Description 有N个小松鼠,它们的家用一个点x,y表示,两个点的距离定义为:点(x,y)和它周围的8个点即上下左右四个点和对角的四个点,距离为1. ...

  4. BZOJ3173:[TJOI2013]最长上升子序列(Splay)

    Description 给定一个序列,初始为空.现在我们将1到N的数字插入到序列中,每次将一个数字插入到一个特定的位置.每插入一个数字,我们都想知道此时最长上升子序列长度是多少? Input 第一行一 ...

  5. BZOJ 3173: [Tjoi2013]最长上升子序列

    3173: [Tjoi2013]最长上升子序列 Time Limit: 10 Sec  Memory Limit: 128 MB Submit: 1524  Solved: 797 [Submit][ ...

  6. [BZOJ]3173: [Tjoi2013]最长上升子序列

    题解:   考虑按照元素升序加入  所以对位置在其后的元素LIS无影响 然后从前面位置的最大值转移过来就行 ,,,,平衡树无脑模拟 #include <algorithm> #includ ...

  7. bzoj 3173: [Tjoi2013]最长上升子序列(离线二分+树状数组)

    3173: [Tjoi2013]最长上升子序列 Time Limit: 10 Sec  Memory Limit: 128 MB Submit: 2051  Solved: 1041 [Submit] ...

  8. bzoj 3173 最长上升子序列

    Written with StackEdit. Description 给定一个序列,初始为空.现在我们将\(1\)到\(N\)的数字插入到序列中,每次将一个数字插入到一个特定的位置.每插入一个数字, ...

  9. BZOJ 3304: [Shoi2005]带限制的最长公共子序列( LCS )

    求个LCS, 只是有了限制, 多加一维表示匹配到z串的第几个, 然后用滚动数组 ------------------------------------------------------------ ...

最新文章

  1. key mysql_mysql中key 、primary key 、unique key 与index区别
  2. Oracle创建表管理表
  3. c++ socket error 10038错误
  4. python人工智能-Python之人工智能(一)
  5. python 3d绘图 拖动_使用python-matplotlib连续3D绘图(即图形更新)?
  6. [转]Git分支管理策略
  7. 关于input type=file 限制文件上传类型
  8. [剑指offer]面试题第[35]题[Leetcode][第138题][JAVA][复杂链表的复制][暴力][HashMap][复制链表]
  9. 6大分布式定时任务对比
  10. 人工智能行业有哪些岗位_电力人有哪些岗位将被人工智能取代?
  11. 李梁北京大学 计算机,【资环学院】圆梦路上多楷模
  12. linux未找到make命令,linux中无make命令的问题(make: *** 没有指明目标并且找不到 makefile及make命令安装方法)...
  13. iOS开发学习之NSFetchedResultsController
  14. 服务器iis的作用,IIS是什么 IIS服务组件有什么作用
  15. 德语翻译-德语在线批量翻译软件
  16. mongodb查询某个字段数据
  17. 北邮C++——破解简单密码
  18. 基于handsome主题的一些美化修改
  19. 汇率兑换——小象学院知识点
  20. VBS 文本歌词粤语拼音翻译

热门文章

  1. ueditor如何设置上传图片的高度宽度_怎么设置天猫主图
  2. php判断数组下标,php判断json或者数组格式与给定格式是否一致
  3. python豆瓣历史评分_Python实战-爬取豆瓣top250评分高于指定值的电影信息
  4. android arp工具,GitHub - SummerSnow274/ARP_sed_rev: 在Android通过ARP询问实现获取同一网络所有设备的MAC地址,AP隔离的网络除外...
  5. 算法-排序-计数排序(包含对非负数和整数的排序)
  6. android封装好的Color类中的常量
  7. python3 beautifulsoup 表格,使用Python中的BeautifulSoup拉取特定的表数据
  8. 卸载chrome_Chrome 浏览器必备“扩展管理工具”,一键管理 Chrome 扩展
  9. shell(希尔排序)
  10. Identifiers in Java(Java标识符)