D. Shortest and Longest LIS(思维,模拟,构造)

原题链接

Gildong recently learned how to find the longest increasing subsequence (LIS) in O(nlogn)O(nlog⁡n) time for a sequence of length nn. He wants to test himself if he can implement it correctly, but he couldn't find any online judges that would do it (even though there are actually many of them). So instead he's going to make a quiz for you about making permutations of nn distinct integers between 11 and nn, inclusive, to test his code with your output.

The quiz is as follows.

Gildong provides a string of length n−1n−1, consisting of characters '<' and '>' only. The ii-th (1-indexed) character is the comparison result between the ii-th element and the i+1i+1-st element of the sequence. If the ii-th character of the string is '<', then the ii-th element of the sequence is less than the i+1i+1-st element. If the ii-th character of the string is '>', then the ii-th element of the sequence is greater than the i+1i+1-st element.

He wants you to find two possible sequences (not necessarily distinct) consisting of nn distinct integers between 11 and nn, inclusive, each satisfying the comparison results, where the length of the LIS of the first sequence is minimum possible, and the length of the LIS of the second sequence is maximum possible.

Input

Each test contains one or more test cases. The first line contains the number of test cases tt (1≤t≤1041≤t≤104).

Each test case contains exactly one line, consisting of an integer and a string consisting of characters '<' and '>' only. The integer is nn (2≤n≤2⋅1052≤n≤2⋅105), the length of the permutation you need to find. The string is the comparison results explained in the description. The length of the string is n−1n−1.

It is guaranteed that the sum of all nn in all test cases doesn't exceed 2⋅1052⋅105.

Output

For each test case, print two lines with nn integers each. The first line is the sequence with the minimum length of the LIS, and the second line is the sequence with the maximum length of the LIS. If there are multiple answers, print any one of them. Each sequence should contain all integers between 11 and nn, inclusive, and should satisfy the comparison results.

It can be shown that at least one answer always exists.

Example

input

Copy

3
3 <<
7 >><>><
5 >>><

output

Copy

1 2 3
1 2 3
5 4 3 7 2 1 6
4 3 1 7 5 2 6
4 3 2 1 5
5 4 2 1 3

Note

In the first case, 11 22 33 is the only possible answer.

In the second case, the shortest length of the LIS is 22, and the longest length of the LIS is 33. In the example of the maximum LIS sequence, 44 '33' 11 77 '55' 22 '66' can be one of the possible LIS.

思路:

参考:

只是用到了lis的定义,

最小lis,让元素从大到小排,‘《’一定是上升序列,所以不用考虑

最大lis,让元素从小到大排,‘》‘逆向是仍然是从小到大排

代码:

#include<bits/stdc++.h>
using namespace std;
// #define int long long
#define vec vector<int>
#define pii pair<int,int>
#define pi 3.1415926
#define rep(i,l,r) for(int i=l;i<=r;++i)
#pragma GCC optimize(2)//
#pragma GCC optimize(3,"Ofast","inline")//
const int maxj=2e5+100,mod=1e9+7,inf=0x3f3f3f3f;
int a[maxj];

void init(int x){
    for(int i=0;i<=x+10;++i){
        a[i]=0;
    }
}
void solve(){//只是lis定义上的运用
    int n;cin>>n;
    // cin>>s+1;
    string s;
    cin>>s;
    s=" "+s;
    // s[n]='#';
    s+='#';
    init(n);
    int m=n;
    // cout<<s<<'\n';
    for(int i=1;i<=n;++i){//模拟整个过程,元素在符合题意的情况下,尽量从大到小,最短的lis
        if((s[i]=='>'&&!a[i])||s[i]=='#'){//填过了,不可以重复填
            a[i]=m;
            m--;
        }else if(s[i]=='<'&&!a[i]){
            int pos=i;
            while(s[i]=='<'&&!a[i])i++;
            for(int j=i;j>=pos;--j){
                a[j]=m;m--;
            }
        }
    }
    for(int i=1;i<=n;++i){
        cout<<a[i]<<' ';
    }cout<<'\n';
    init(n);
    m=1;
    for(int i=1;i<=n;++i){//模拟过程,从小到大,最长lis
        if(s[i]=='<'&&!a[i]||s[i]=='#'){//
            a[i]=m;
            m++;
        }
        else if(s[i]=='>'&&!a[i]){
            int pos=i;
            while(s[i]=='>'&&!a[i]){
                i++;
            }
            for(int j=i;j>=pos;--j){
                a[j]=m;
                m++;
            }
        }
    }for(int i=1;i<=n;++i){
        cout<<a[i]<<' ';
    }cout<<endl;
}
signed main(){
    int t;
    t=1;
    cin>>t;
    while(t--)solve();
    return 0;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值