传送门

题意要你构造一个序列,使得该序列的每个位置上的最长上升子序列的长度能构成给定的序列。
构造序列的元素要求还要求满足给定的上下界

solution
我们可以把给出的最长上升子序列的长度按升序排列,长度相同的按下标降序排列。
排完序后第一个数可以贪心的取其下界,同一层(即长度相同)的下标小的取值应该大于等于下标较大的取值
同时取值应该大于前一层下标最大且小于该位置的数

#define IN_LB() freopen("F:\\in.txt","r",stdin)
#define IN_PC() freopen("C:\\Users\\hz\\Desktop\\in.txt","r",stdin)
#include <bits/stdc++.h> using namespace std;
const int maxn = 100005; struct node {
int ind,ceil,d,u;
int ans;
} nd[maxn]; bool cmp(node a,node b) {
if(a.ceil==b.ceil)return a.ind>b.ind;
return a.ceil<b.ceil;
} bool cmp1(node a,node b) {
return a.ind<b.ind;
} struct qnode{
int yuanind,xianind,ceil;
}; queue <qnode> que; int main() {
// IN_LB();
int T;
scanf("%d",&T);
while(T--) {
int n;
scanf("%d",&n);
for(int i=0; i<n; i++) {
nd[i].ind = i;
scanf("%d",&nd[i].ceil);
}
for(int i=0; i<n; i++) {
scanf("%d%d",&nd[i].d,&nd[i].u);
}
sort(nd,nd+n,cmp);
nd[0].ans = nd[0].d;
qnode seed;
seed.yuanind = nd[0].ind;
seed.xianind = 0;
seed.ceil = 1;
while(!que.empty())que.pop();
que.push(seed);
for(int i=1; i<n; i++) {
if(nd[i].ceil==nd[i-1].ceil) {
if(nd[i].ceil>1){
int exind;
while(!que.empty()) {
if(que.front().yuanind<nd[i].ind) {
exind = que.front().xianind;
break;
}
que.pop();
}
nd[i].ans = max(max(nd[exind].ans+1,nd[i-1].ans),nd[i].d);
}
else nd[i].ans = max(nd[i-1].ans,nd[i].d);
qnode cur;
cur.yuanind = nd[i].ind;
cur.xianind = i;
cur.ceil = nd[i].ceil;
que.push(cur);
} else {
int exind;
while(!que.empty()) {
if(que.front().ceil==nd[i].ceil-1&&que.front().yuanind<nd[i].ind) {
exind = que.front().xianind;
break;
}
que.pop();
}
nd[i].ans = max(nd[exind].ans+1,nd[i].d);
qnode cur;
cur.yuanind = nd[i].ind;
cur.xianind = i;
cur.ceil = nd[i].ceil;
que.push(cur);
}
}
sort(nd,nd+n,cmp1);
for(int i=0; i<n; i++) {
printf("%d%s",nd[i].ans,(i==n-1)?"\n":" ");
}
}
return 0;
}

【贪心】LIS @The 15th Zhejiang Provincial Collegiate Programming Contest E的更多相关文章

  1. 2018浙江省赛(ACM) The 15th Zhejiang Provincial Collegiate Programming Contest Sponsored by TuSimple

    我是铁牌选手 这次比赛非常得爆炸,可以说体验极差,是这辈子自己最脑残的事情之一. 天时,地利,人和一样没有,而且自己早早地就想好了甩锅的套路. 按理说不开K就不会这么惨了啊,而且自己也是毒,不知道段错 ...

  2. The 15th Zhejiang Provincial Collegiate Programming Contest Sponsored by TuSimple - L Doki Doki Literature Club

    Doki Doki Literature Club Time Limit: 1 Second      Memory Limit: 65536 KB Doki Doki Literature Club ...

  3. The 15th Zhejiang Provincial Collegiate Programming Contest(部分题解)

    ZOJ 4024 Peak 题意 给出n和n个数,判断该数列是否是凸形的. 解题思路 从前往后第一对逆序数,和从后往前第一队逆序数,如果都非零而且相邻,证明该数组是凸形的. 代码 #include & ...

  4. The 15th Zhejiang Provincial Collegiate Programming Contest Sponsored by TuSimple - M Lucky 7

    Lucky 7 Time Limit: 1 Second      Memory Limit: 65536 KB BaoBao has just found a positive integer se ...

  5. The 15th Zhejiang Provincial Collegiate Programming Contest Sponsored by TuSimple - J CONTINUE...?

    CONTINUE...? Time Limit: 1 Second      Memory Limit: 65536 KB      Special Judge DreamGrid has  clas ...

  6. The 15th Zhejiang Provincial Collegiate Programming Contest Sponsored by TuSimple - B King of Karaoke

    King of Karaoke Time Limit: 1 Second      Memory Limit: 65536 KB It's Karaoke time! DreamGrid is per ...

  7. The 15th Zhejiang Provincial Collegiate Programming Contest Sponsored by TuSimple -A Peak

    Peak Time Limit: 1 Second      Memory Limit: 65536 KB A sequence of  integers  is called a peak, if ...

  8. ZOJ 4033 CONTINUE...?(The 15th Zhejiang Provincial Collegiate Programming Contest Sponsored by TuSimple)

    #include <iostream> #include <algorithm> using namespace std; ; int a[maxn]; int main(){ ...

  9. zoj The 12th Zhejiang Provincial Collegiate Programming Contest Capture the Flag

    http://acm.zju.edu.cn/onlinejudge/showContestProblem.do?problemId=5503 The 12th Zhejiang Provincial ...

随机推荐

  1. POJ 2987 Firing【最大权闭合图-最小割】

    题意:给出一个有向图,选择一个点,则要选择它的可以到达的所有节点.选择每个点有各自的利益或损失.求最大化的利益,以及此时选择人数的最小值. 算法:构造源点s汇点t,从s到每个正数点建边,容量为利益.每 ...

  2. python之多线程 threading.Lock() 和 threading.RLock()

    0.目录 2. threading.Lock() 的必要性3.观察block4.threading.RLock() 的应用场景 1.参考 Thread Synchronization Mechanis ...

  3. ubuntu系统更新源

    问题引入:在ubuntu上安装libmysqlclient-dev一直提示Connecting to mirrirs.cqu.edu.cn

  4. Python 携程

    一.协程 1.又称微线程,纤程.英文名Coroutine.一句话说明什么是协程:协程是一种用户态的轻量级线程(相当于操作系统不知道它的存在,是用户控制的). 2.协程拥有自己的寄存器上下文和栈(代码的 ...

  5. Linux 配置最新的epel源

    一.Centos6 yum install https://dl.fedoraproject.org/pub/epel/epel-release-latest-6.noarch.rpm 二.Cento ...

  6. Codeforces 316G3 Good Substrings 字符串 SAM

    原文链接http://www.cnblogs.com/zhouzhendong/p/9010851.html 题目传送门 - Codeforces 316G3 题意 给定一个母串$s$,问母串$s$有 ...

  7. CF552 E. Two Teams

    题意:给出一串n个数   为1-n的乱序 一共有两个教练   教练一的队伍是1队  二是二队 教练一选择 当前队列中剩余人数的最大序号   将其和左边k个人 和右边k个人 变为一队 如此反复直到所有人 ...

  8. 安卓开发中SpannableString之富文本显示效果

    SpannableString其实和String一样,都是一种字符串类型,SpannableString可以直接作为TextView的显示文本,不同的是SpannableString可以通过使用其方法 ...

  9. 不利用C语言库函数,实现字符串相关函数

    #include<stdio.h> int strLength(char* s)//求字符长度 { ; while(s[i]!=NULL) { i++; } return i; } int ...

  10. Android XML shape 标签使用详解(apk瘦身,减少内存好帮手)

    Android XML shape 标签使用详解   一个android开发者肯定懂得使用 xml 定义一个 Drawable,比如定义一个 rect 或者 circle 作为一个 View 的背景. ...