第15届浙江省赛 E LIS

本文介绍了一个关于最长递增子序列(LIS)的问题,重点在于如何根据已知的辅助序列和范围序列来恢复原始序列。文章通过具体实例展示了问题的输入输出样例,并提供了一段C++代码实现解决方案。


LIS

Time Limit: 1 Second      Memory Limit: 65536 KB      Special Judge

DreamGrid is learning the LIS (Longest Increasing Subsequence) problem and he needs to find the longest increasing subsequence of a given sequence  of length .

Recall that

  • A subsequence  of length  is a sequence satisfying  and .

  • An increasing subsequence  is a subsequence satisfying .

DreamGrid defines the helper sequence  where  indicates the maximum length of the increasing subsequence which ends with . In case you don't know how to derive the helper sequence, he provides you with the following pseudo-code which calculates the helper sequence.

procedure lis_helper(: original sequence)
{Let  be the length of the original sequence,
 be the -th element in sequence , and 
be the -th element in sequence }
for  := 1 to 
     := 1
    for  := 1 to ( - 1)
        if  and 
             :=  + 1
return  { is the helper sequence}

DreamGrid has derived the helper sequence using the program, but the original sequence  is stolen by BaoBao and is lost! All DreamGrid has in hand now is the helper sequence and two range sequences  and  indicating that  for all .

Please help DreamGrid restore the original sequence which is compatible with the helper sequence and the two range sequences.

Input

There are multiple test cases. The first line of the input contains an integer , indicating the number of test cases. For each test case:

The first line contains an integer  (), indicating the length of the original sequence.

The second line contains  integers  () seperated by a space, indicating the helper sequence.

For the following  lines, the -th line contains two integers  and  (), indicating the range sequences.

It's guaranteed that the original sequence exists, and the sum of  of all test cases will not exceed .

Output

For each test case output one line containing  integers separated by a space, indicating the original sequence. If there are multiple valid answers, print any of them.

Please, DO NOT print extra spaces at the end of each line, or your solution may be considered incorrect!

Sample Input
4
6
1 2 3 2 4 3
0 5
2 4
3 3
1 2
3 5
1 5
5
1 2 1 3 1
100 200
200 300
200 400
400 500
100 500
7
1 2 3 1 1 4 2
0 3
0 3
0 3
0 3
0 3
0 3
0 3
2
1 1
1 2
2 3
Sample Output
1 2 3 2 5 3
200 300 200 500 200
0 1 2 0 0 3 1
2 2
题解:
若i位置有fi,ai,则之前若有j<i且fi==fj,则ai<=aj
若有fi==fj+1,则ai>aj
只需从后往前遍历一遍ai<=aj确定一个下限,然后
从前到后跑一边ai<aj更新下限即可
代码:

#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int maxn=1e5+7;
int a[maxn],d[maxn],L[maxn],pre[maxn];
int main()
{
    int T;scanf("%d",&T);
    while(T--)
    {
        memset(pre,-1,sizeof(pre));
        int n;scanf("%d",&n);
        for(int i=1;i<=n;i++)scanf("%d",&a[i]);
        for(int i=1;i<=n;i++)
        {
            int x;scanf("%d%d",&L[i],&x);
        }
        for(int i=n;i>=1;i--)
        {
            d[i]=L[i];
            if(pre[a[i]]!=-1)d[i]=max(d[pre[a[i]]],L[i]);
            pre[a[i]]=i;
        }
        memset(pre,-1,sizeof(pre));
        for(int i=1;i<=n;i++)
        {
            int x=pre[a[i]-1];
            if(x!=-1)d[i]=max(d[i],d[x]+1);
            pre[a[i]]=i;
        }
        for(int i=1;i<=n;i++)
        {
            printf("%d",d[i]);
            if(i!=n)printf(" ");
            else printf("\n");
        }
    }
    return 0;
}

LIS

Time Limit: 1 Second      Memory Limit: 65536 KB      Special Judge

DreamGrid is learning the LIS (Longest Increasing Subsequence) problem and he needs to find the longest increasing subsequence of a given sequence  of length .

Recall that

  • A subsequence  of length  is a sequence satisfying  and .

  • An increasing subsequence  is a subsequence satisfying .

DreamGrid defines the helper sequence  where  indicates the maximum length of the increasing subsequence which ends with . In case you don't know how to derive the helper sequence, he provides you with the following pseudo-code which calculates the helper sequence.

procedure lis_helper(: original sequence)
{Let  be the length of the original sequence,
 be the -th element in sequence , and 
be the -th element in sequence }
for  := 1 to 
     := 1
    for  := 1 to ( - 1)
        if  and 
             :=  + 1
return  { is the helper sequence}

DreamGrid has derived the helper sequence using the program, but the original sequence  is stolen by BaoBao and is lost! All DreamGrid has in hand now is the helper sequence and two range sequences  and  indicating that  for all .

Please help DreamGrid restore the original sequence which is compatible with the helper sequence and the two range sequences.

Input

There are multiple test cases. The first line of the input contains an integer , indicating the number of test cases. For each test case:

The first line contains an integer  (), indicating the length of the original sequence.

The second line contains  integers  () seperated by a space, indicating the helper sequence.

For the following  lines, the -th line contains two integers  and  (), indicating the range sequences.

It's guaranteed that the original sequence exists, and the sum of  of all test cases will not exceed .

Output

For each test case output one line containing  integers separated by a space, indicating the original sequence. If there are multiple valid answers, print any of them.

Please, DO NOT print extra spaces at the end of each line, or your solution may be considered incorrect!

Sample Input
4
6
1 2 3 2 4 3
0 5
2 4
3 3
1 2
3 5
1 5
5
1 2 1 3 1
100 200
200 300
200 400
400 500
100 500
7
1 2 3 1 1 4 2
0 3
0 3
0 3
0 3
0 3
0 3
0 3
2
1 1
1 2
2 3
Sample Output
1 2 3 2 5 3
200 300 200 500 200
0 1 2 0 0 3 1
2 2
### 第十五蓝桥杯嵌入式组比详情 #### 参资格与分组 对于参者的要求,通常面向在校大学生以及部分符合条件的社会人士开放。特别是针对电子信息专业的学生提供了参与机会[^1]。 #### 比结构 事分为两个主要阶段:首先是级选拔(即),用于筛选优秀选手进入全国总决。这种分级制度有助于更公平地选出最具实力的竞争者[^2]。 #### 报名流程 有意参加的学生需通过官方渠道完成注册手续,在指定时间段内访问官网提交必要信息并支付相应费用。一旦确认报名成功,则可以获取由主办方提供的备考资源和支持材料来辅助准备竞活动[^3]。 #### 学习资源和技术支持 为了帮助参人员更好地理解和掌握所需技能,组委会还提供了一系列的学习工具和文档,比如有关于如何使用特定硬件平台如LIS302DL传感器的教学指南及其配套源码示例等,这些都极大地促进了备效率提升[^4]。 ```python # 示例代码片段展示如何初始化LIS302DL加速度计 import smbus def init_LIS302DL(): bus = smbus.SMBus(1) address = 0x19 # 配置寄存器写入命令 config_register = 0x20 value_to_write = 0b0000_0001 # 设置正常模式 try: bus.write_byte_data(address, config_register, value_to_write) print("LIS302DL initialized successfully.") except Exception as e: print(f"Failed to initialize LIS302DL: {e}") init_LIS302DL() ```
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值