HDU 5324 Boring Class CDQ分治
题目要求一个3维偏序点的最长子序列,并且字典序最小。
题解:
这种题目出现的次数特别多了。如果不需要保证字典序的话直接cdq就好了。
这里需要维护字典序的话,我们从后往前配对就好了,因为越前面的点权重越大。(对于字典序来说)
代码:
#include<bits/stdc++.h>
using namespace std;
#define Fopen freopen("_in.txt","r",stdin); freopen("_out.txt","w",stdout);
#define LL long long
#define ULL unsigned LL
#define fi first
#define se second
#define pb push_back
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define lch(x) tr[x].son[0]
#define rch(x) tr[x].son[1]
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
typedef pair<int,int> pll;
const int inf = 0x3f3f3f3f;
const LL INF = 0x3f3f3f3f3f3f3f3f;
const LL mod = (int)1e9+;
const int N = 1e5 + ;
int ans[N];
int pre[N];
struct Node{
int l, r, id;
bool operator<(const Node x) const{
if(r != x.r) return r > x.r;
return id > x.id;
}
}A[N], tmp[N];
int ll[N], lsz;
int tree[N][];
void add(int x, int len, int id){
for(int i = x; i < N; i+=i&(-i)){
if(len > tree[i][]){
tree[i][] = len;
tree[i][] = id;
}
else if(len == tree[i][]) tree[i][] = min(tree[i][], id);
}
}
pll query(int x){
int len = , ret = ;
for(int i = x; i > ; i -= i &(-i)){
if(len == tree[i][]) ret = min(ret, tree[i][]);
else if(len < tree[i][]){
len = tree[i][];
ret = tree[i][];
}
}
return pll(len, ret);
}
void clear(int x){
for(int i = x; i < N; i += i&(-i))
tree[i][] = tree[i][] = ;
}
void cdq(int l, int r){
if(l == r) return ;
int m = l+r >> ;
cdq(m+,r);
for(int i = l; i <= r; i++)
tmp[i] = A[i];
sort(tmp+l, tmp+r+);
for(int i = l; i <= r; i++){
//cout << tmp[i].id << " " << tmp[i].l << " " << tmp[i].r << endl;
int id = tmp[i].id;
if(id > m) add(tmp[i].l, ans[id], id);
else {
pll p = query(tmp[i].l);
int len = p.fi, iid = p.se;
if(len == ) continue;
if(len+ > ans[id]){
ans[id] = len+;
pre[id] = iid;
}
else if(len + == ans[id])
pre[id] = min(pre[id], iid);
}
}
for(int i = l; i <= r; i++){
if(tmp[i].id > m) clear(tmp[i].l);
}
cdq(l,m);
}
int main(){
int n;
lsz = ;
while(~scanf("%d", &n)){
for(int i = ; i <= n; i++){
ans[i] = , pre[i] = i;
A[i].id = i;
scanf("%d", &A[i].l);
ll[i] = A[i].l;
}
sort(ll+, ll++n);
lsz = unique(ll+,ll++n) - ll - ;
for(int i = ; i <= n; i++){
scanf("%d", &A[i].r);
A[i].l = lower_bound(ll+, ll++lsz, A[i].l) - ll;
}
cdq(,n);
int fans = , fid = ;
for(int i = ; i <= n; i++){
if(fans < ans[i]){
fans = ans[i];
fid = i;
}
}
printf("%d\n", fans);
for(int i = ; i <= fans; i++){
printf("%d%c", fid, " \n"[i==fans]);
fid = pre[fid];
} }
return ;
}
HDU 5324 Boring Class CDQ分治的更多相关文章
- hdu 3842 Machine Works(cdq分治维护凸壳)
题目链接:hdu 3842 Machine Works 详细题解: HDU 3842 Machine Works cdq分治 斜率优化 细节比较多,好好体会一下. 在维护斜率的时候要考虑x1与x2是否 ...
- HDU 5324 Boring Class【cdq分治】
这就是一个三维排序的问题,一维递减,两维递增,这样的问题用裸的CDQ分治恰好能够解决. 如同HDU 4742(三维排序,一个三维都是递增的) 由于最小字典序比較麻烦,所以要从后面往前面做分治.每一个点 ...
- 2015 Multi-University Training Contest 3 hdu 5324 Boring Class
Boring Class Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Tota ...
- HDU 5730 Shell Necklace cdq分治+FFT
题意:一段长为 i 的项链有 a[i] 种装饰方式,问长度为n的相连共有多少种装饰方式 分析:采用dp做法,dp[i]=∑dp[j]*a[i-j]+a[i],(1<=j<=i-1) 然后对 ...
- HDU 6183 Color it cdq分治 + 线段树 + 状态压缩
Color it Time Limit: 20000/10000 MS (Java/Others) Memory Limit: 132768/132768 K (Java/Others) Pro ...
- Boring Class HDU - 5324 (CDQ分治)
Mr. Zstu and Mr. Hdu are taking a boring class , Mr. Zstu comes up with a problem to kill time, Mr. ...
- HDU - 5324:Boring Class (CDQ分治&树状数组&最小字典序)
题意:给定N个组合,每个组合有a和b,现在求最长序列,满足a不升,b不降. 思路:三位偏序,CDQ分治. 但是没想到怎么输出最小字典序,我好菜啊. 最小字典序: 我们倒序CDQ分治,ans[i]表 ...
- HDU 3507 Print Article(CDQ分治+分治DP)
[题目链接] http://acm.hdu.edu.cn/showproblem.php?pid=3507 [题目大意] 将长度为n的数列分段,最小化每段和的平方和. [题解] 根据题目很容易得到dp ...
- HDU 5730 Shell Necklace(CDQ分治+FFT)
[题目链接] http://acm.hdu.edu.cn/showproblem.php?pid=5730 [题目大意] 给出一个数组w,表示不同长度的字段的权值,比如w[3]=5表示如果字段长度为3 ...
随机推荐
- angular6组件通信
此文章是用markdown书写,赋值全部到vscode打开即可. # Angular组件通信 ## .父组件传递数据到子组件 - `@Input`:属性绑定,父组件向子组件传递数据 ```js // ...
- ipad pro 为什么不行
TalkingData公布的数据显示,iPad Pro在中国发行首月的销量仅为49 300台,而此前iPad Air 2发行首月后销量曾高达55.7万台.那么到底是什么原因,让这个被寄予厚望的iPad ...
- WPF后台设置颜色字体等
Button TempButton = new Button(); TempButton.Tag = “按 ...
- hive分桶表bucketed table分桶字段选择与个数确定
为什么分桶 (1)获得更高的查询处理效率.桶为表加上了额外的结构,Hive 在处理有些查询时能利用这个结构.具体而言,连接两个在(包含连接列的)相同列上划分了桶的表,可以使用 Map 端连接 (Map ...
- axios配置请求头content-type
现在前端开发中需要通过Ajax发送请求获取后端数据是很普遍的一件事情了,鉴于我平时在撸码中用的是vue技术栈,今天这里来谈谈我们常用的发Ajax请求的一个插件—axios.> 现在网上可能发送A ...
- Window.open使用总结
前言 今天在项目中,突然看到window.open的使用,感觉还是很神奇,突然心血来潮查看了window.open的用法. 用途 主要用于在打开网站时弹出的其他窗口.用于通知广告一类的. 用法 win ...
- DataPipeline丨DataOps的组织架构与挑战
作者:DataPipeline CEO 陈诚 前两周,我们分别探讨了“数据的资产负债表与现状”及“DataOps理念与设计原则”.接下来,本文会在前两篇文章的基础上继续探讨由DataOps设计原则衍生 ...
- 强烈推荐优秀的Vue UI组件库
Vue 是一个轻巧.高性能.可组件化的MVVM库,API简洁明了,上手快.从Vue推出以来,得到众多Web开发者的认可.在公司的Web前端项目开发中,多个项目采用基于Vue的UI组件框架开发,并投入正 ...
- 从IDEA角度来看懂UML图
前言 我们目前已经学习了设计模式的7种设计原则.下面本该是直接进入具体的设计模式系列文章. 但是呢在我们学习设计模式之前我们还是有必要了解一下uml图.因为后续的设计模式文章不出意外应该会很多地方使用 ...
- 使用webpack---安装webpack和webpack-dev-server
1.先确保安装了最新版的Node.js和NPM,并已经了解NPM的基本用法 (以下使用cmd命令行进行) 2.安装webpack (1)全局安装 $ npm install webpack -g ...