根据题目,我们可以找最短的LIS和最长的LIS,找最短LIS时,可以将每一个increase序列分成一组,从左到右将最大的还未选择的数字填写进去,不同组之间一定不会存在s[i]<s[j]的情况,保证满足题意,找最长LIS,可以找补集,将每个decrease序列分成一组,找到后取反即可

#include<bits/stdc++.h>
using namespace std;
#define lowbit(x) ((x)&(-x))
typedef long long LL; vector<int> solve(int n, string s) {
vector<int> ans(n);
int cur = , i, x = n;
while(cur < n) {
i = cur;
while(i < n && s[i] == '<') i++;
for(int j = i; j >= cur; --j) ans[j] = x--;
cur = i+;
} return ans;
} void run_case() {
string s;
int n;
cin >> n >> s;
vector<int> a = solve(n, s);
for(auto &c : s)
c ^= '>'^'<';
vector<int> b = solve(n, s);
for(auto i : a) cout << i << " ";
cout << "\n";
for(auto i : b) cout << n-i+ << " ";
cout << "\n";
} int main() {
ios::sync_with_stdio(false), cin.tie();
//cout.setf(ios_base::showpoint);cout.precision(10);
int t; cin >> t;
while(t--)
run_case();
cout.flush();
return ;
}

Codeforces 1304D. Shortest and Longest LIS的更多相关文章

  1. Codeforces 1304D. Shortest and Longest LIS 代码(构造 贪心)

    https://codeforces.com/contest/1304/problem/D #include<bits/stdc++.h> using namespace std; voi ...

  2. Shortest and Longest LIS

    Codeforces Round #620 (Div. 2) D. Shortest and Longest LIS 题解: 贪心即可,对于最短序列,我们尽可能用可用的最大数字放入序列中,对于最长序列 ...

  3. [CF1304D] Shortest and Longest LIS - 贪心

    看样例,>><>><,要构造 LIS 最短的,我们需要找最小链划分的方案,即包含最少的下降列 很容易想到把连续 < 的看成一段,比如样例就是 .|.|. .| ...

  4. Codeforces1304D Shortest and Longest LIS

    前置扯淡 %%@\(wucstido\),思路是在是巧妙---link Description 给一个长度为\(n\)由 \(<\) 和 \(>\)组成的字符串,表示序列中相邻位置的数的大 ...

  5. [Codeforces 1205B]Shortest Cycle(最小环)

    [Codeforces 1205B]Shortest Cycle(最小环) 题面 给出n个正整数\(a_i\),若\(a_i \& a_j \neq 0\),则连边\((i,j)\)(注意i- ...

  6. 【Codeforces】Gym 101156E Longest Increasing Subsequences LIS+树状数组

    题意 给定$n$个数,求最长上升子序列的方案数 根据数据范围要求是$O(n\log n)$ 朴素的dp方程式$f_i=max(f_j+1),a_i>a_j$,所以记方案数为$v_i$,则$v_i ...

  7. Codeforces Educational Codeforces Round 5 D. Longest k-Good Segment 尺取法

    D. Longest k-Good Segment 题目连接: http://www.codeforces.com/contest/616/problem/D Description The arra ...

  8. Educational Codeforces Round 9 D. Longest Subsequence dp

    D. Longest Subsequence 题目连接: http://www.codeforces.com/contest/632/problem/D Description You are giv ...

  9. Codeforces Gym101246H:``North-East''(LIS+思维)

    http://codeforces.com/gym/101246/problem/H 题意:在二维平面上有n个点,从最左下角的点出发,每次走只能走在当前的点的右上角的点(xj > xi, yj ...

随机推荐

  1. JAVA基础学习(5)之数组

    5数组 5.1数组 5.1.1初识数组 // 输出大于平均数的所有数 Scanner in = new Scanner(System.in); int n; int[] a = new int[100 ...

  2. java篇 之 集合

    集合   链接:https://blog.csdn.net/weixin_42504145/article/details/83119088 数组: java的数组既可以存储基本数据类型,也可以存储引 ...

  3. Hack the box邀请码和注册问题总结

    注意下,有3个坑, 1. 解码方式是随机的,记得看DATA下面提示用哪种 2. post时候可以直接用f12里的console,命令是: $.post('https://www.hackthebox. ...

  4. WLC开机卡在launching....(变砖)

    1.出现故障的原因:A.通过手动更换镜像导致Boot Loader Menu Run primary image (7.0.220.0) - ActiveRun backup image (7.0.2 ...

  5. MSE-初始化MSE

    MSE(Mobility Services Engine) Cisco MSE可以配合无线实现很多功能,MSE的功能简单概括有: 1.基本位置服务捕获并聚合关键网络信息,例如设备位置,RF频谱详细信息 ...

  6. 软件版本 Alpha、Beta、Rc

    软件版本的周期 α.β.γ 表示软件测试中的三个阶段 α :第一阶段,内部测试使用 β: 第二阶段,消除了大部分不完善的地方,仍可能存在漏洞,一般提供给特定的用户使用 γ: 第三阶段,产品成熟,个别地 ...

  7. pandas读取文件的read_csv()方法

    import pandas as pd pd.read_csv(filepath_or_buffer,header,parse_dates,index_col) 返回数据类型:DataFrame:二维 ...

  8. dp-简单迷宫捡金币

    链接:https://ac.nowcoder.com/acm/challenge/terminal 吃货LP参加了珠海美食节,每见一家摊位都会大吃一顿,但是如果不加收敛,接下来的日子就只能吃土了,所以 ...

  9. 【PAT甲级】1051 Pop Sequence (25 分)(栈的模拟)

    题意: 输入三个正整数M,N,K(<=1000),分别代表栈的容量,序列长度和输入序列的组数.接着输入K组出栈序列,输出是否可能以该序列的顺序出栈.数字1~N按照顺序随机入栈(入栈时机随机,未知 ...

  10. class A<T>where T:new()是什么意思

    这是C#泛型类声明的语法class A<T> 表示 A类接受某一种类型,泛型类型为T,需要运行时传入where表明了对类型变量T的约束关系.where T:new()指明了创建T的实例时应 ...