根据题目,我们可以找最短的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. 算法进阶:0x01 位运算

    一.快速幂的模板代码 a^b%p: #include<iostream> using namespace std; int main() { int a,b,p; cin>>a ...

  2. 【PAT甲级】1082 Read Number in Chinese (25 分)

    题意: 输入一个九位整数,输出它的汉字读法(用拼音表示). trick: 字符串数组""其实会输出一个空格,而不是什么都不输出,导致测试点0和4格式错误. AAAAAccepted ...

  3. Windows下运行MapReduce程序出现Could not locate executable null\winutils.exe in the Hadoop binaries.

    运行环境:windows10 64位,虚拟机:Ubuntu Kylin 14.04,Hadoop2.7.1 错误信息: java.io.IOException: Could not locate ex ...

  4. SSIS部署后执行失败,无法将保护的XML节点解密

    将包属性中的 protectionLevel 设置成DontSaveSensitive 即可.

  5. 「JSOI2015」送礼物

    「JSOI2015」送礼物 传送门 看到这题首先想到分数规划. 我们发现对于当前区间,如果它的最大值和最小值不是分居区间的两个端点的话,那么我们显然可以把两端多出去的部分舍掉,因为,在区间最大值最小值 ...

  6. Python - 八大排序算法

    1.序言 本文使用Python实现了一些常用的排序方法.文章结构如下: 1.直接插入排序 2.希尔排序 3.冒泡排序 4.快速排序 5.简单选择排序 6.堆排序 7.归并排序 8.基数排序 上述所有的 ...

  7. Python爬虫:数据解析 之 xpath

    资料: W3C标准:https://www.w3.org/TR/xpath/all/ W3School:https://www.w3school.com.cn/xpath/index.asp 菜鸟教程 ...

  8. P3376 【模板】网络最大流 dinic详解

    dinic的核心在于分层和多路增广. 分层的意思是,对于图用bfs搜出每一层,避免出现dfs深度过深的情况. 多路增广,利用的是dfs的回溯性质,这样就可以在一个点增广出它的所有流量. #includ ...

  9. 一行代码解决 sql语句 in传入数组变字符串

    --数组 var arrs= ['test1','test2','test3'];--变字符串 var instring = "'"+arrs.join("','&quo ...

  10. python中的type和object详解

    关于这篇博客 这篇博客主要描述Python的新风格对象(new-style objects),如下: <type 'type'>和<type 'object'>分别是什么? 用 ...