[JZOJ3743] 【TJOI2014】Alice and Bob
来源:互联网 发布:仓储数据库概念设计 编辑:程序博客网 时间:2024/06/10 01:27
Description
N<=10^5
Solution
显然,对于每一个
那么
因为我们要尽量让前面的
所以每一个
所以对于任意一个
那么
Code
#include <cstdio>#include <cstdlib>#include <cstring>#include <algorithm>#include <cmath>#include <iostream>#define fo(i,a,b) for(int i=a;i<=b;i++)#define fod(i,a,b) for(int i=a;i>=b;i--)#define N 100005#define LL long longusing namespace std;int n,m,a[N],l[N],d[N],lt[N],nt[N],dt[N],m1,x[N],v;void dfs(int k){ x[k]=v++; for(int i=lt[k];i;i=nt[i]) dfs(dt[i]);}void link(int x,int y) { nt[++m]=lt[x]; dt[lt[x]=m]=y;}int main(){ cin>>n; int m=0; LL ans=0; fo(i,1,n) { scanf("%d",&a[i]); link(l[a[i]-1],i); l[a[i]]=i; } dfs(0); memset(d,107,sizeof(d)); d[0]=0; fod(i,n,1) { int p=lower_bound(d,d+n+1,x[i])-d; ans+=(LL)p; d[p]=min(d[p],x[i]); } printf("%lld\n",ans);}
0 0
- [JZOJ3743] 【TJOI2014】Alice and Bob
- JZOJ3743. 【TJOI2014】Alice and Bob
- JZOJ3743. 【TJOI2014】Alice and Bob
- 【TJOI2014】Alice and Bob
- Alice and Bob
- 2683. Alice and Bob
- 1798. Alice and Bob
- hdu4268 Alice and Bob
- HDU4268 Alice and Bob
- Alice, Bob and Chocolate
- hdu4268 Alice and Bob
- A:Alice and Bob
- hdu4111 Alice and Bob
- Alice and Bob
- 1798[Bob and Alice]
- Alice and Bob 数学题
- Alice and Bob
- XTU_1168 Alice and Bob
- 这两天的学习内容
- Spark2.1集群环境搭建小结(2)
- 2017.3.25
- Linux中vim的配置,安装gcc/g++,gdb
- Android关于MediaPlayer中的prepare方法和prepareAsync方法的区别
- [JZOJ3743] 【TJOI2014】Alice and Bob
- java中封装 关键字 构造方法 等用法详解
- 微信消息管理之接收事件推送
- VS2015 小问题解决方法
- layer.js:2 Uncaught TypeError: n.on is not a function(…)
- 20170405
- class org.objectweb.asm.tree.ClassNode 报错解决
- SQL语句
- 链表划分