传送门

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

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. CDOJ1927 爱吃瓜的伊卡洛斯(2) 【并查集】启发式合并+set

    伊卡洛斯很爱吃西瓜.一次,他来到一个西瓜摊旁,发现水果摊有N个西瓜,西瓜有红色.黄色.绿色.蓝色……等等数不清的颜色. 伊卡洛斯很想知道知道一些信息,便于老板交谈了起来. 当老板的话的第一个字符为”A ...

  2. jxoi2017

    题解: 并不知道题目顺序就按照难度排序了 [JXOI2017]加法 这是一道很简单的贪心 最小值最大二分答案 然后我们可以从左向右考虑每一个位置 如果他还需要+A 我们就从能覆盖它的区间中挑一个最右的 ...

  3. .net core 中的 DependencyInjection - IOC

    概要:因为不知道写啥,所以随便找个东西乱说几句,嗯,就这样,就是这个目的. 1.IOC是啥呢? IOC - Inversion of Control,即控制反转的意思,这里要搞明白的就是,它是一种思想 ...

  4. H.265:网络视频的高清时代

    去年八月,爱立信公司推出了首款H.265编解码器,而在仅仅六个月之后,国际电联(ITU)就正式批准通过了HEVC/H.265标准,标准全称为高效视频编码(High Efficiency Video C ...

  5. JMeter高并发场景下存在请求无数据

  6. net core体系-web应用程序-4asp.net core2.0 项目实战(1)-1目录

    Asp.Net Core 2.0 项目实战(1) NCMVC开源下载了 Asp.Net Core 2.0 项目实战(2)NCMVC一个基于Net Core2.0搭建的角色权限管理开发框架 Asp.Ne ...

  7. ELK 环境搭建4-Kafka + zookeeper

    一.安装前准备 1.节点 192.168.30.41 192.168.30.42 192.168.30.43 2.操作系统: Centos7.5 3.安装包 a.java8: jdk-8u181-li ...

  8. IDEA控制台问题:At least one JAR was scanned for TLDs yet contained no TLD

    参考连接: https://www.cnblogs.com/interdrp/p/7763040.html 1.调整Tomcat对应类的log级别 2.观察Tomcat日志打印信息 3.调整${tom ...

  9. webpack的build的时候时间长处理方案

    观察第一次build的时间比较长,之后的编译时间较短,可以通过webpack -watch 监测性能 1, 将webpack升级到4.0,build 的速度提升很多 2,用webpack -watch ...

  10. HDU 3829 Cat VS Dog (最大独立集)【二分图匹配】

    <题目链接> 题目大意: 动物园有n条狗.m头猫.p个小孩,每一个小孩有一个喜欢的动物和讨厌的动物.如今动物园要转移一些动物.假设一个小孩喜欢的动物在,不喜欢的动物不在,他就会happy. ...