Codeforces Round #842 (Div. 2)补题

C Elemental Decompress

  • 题意在这里插入图片描述
    就是给一个数组a, 1 ≤ a [ i ] ≤ n 1\le a[i] \le n 1a[i]n。问你能否找到两个全排列,使得 m a x { p [ i ] , q [ i ] } = a [ i ] max\{p[i],q[i]\}=a[i] max{p[i],q[i]}=a[i]
  • 思路

一个数出现三次肯定不行,1出现两次肯定不行,剩下的用构造

  • 代码
#include <bits/stdc++.h>

using namespace std;

const int maxn = 1e6+7;
typedef long long ll;
const int mod = 1e9+9;
int n,m,x;
int a[maxn],b[maxn];
int hsha[maxn],hshb[maxn];
int hsh[maxn];

int main()
{
    // set<int> test ;
    // test.insert(1);
    // auto item = test.lower_bound(0);
    // if (item==test.begin())cout<<1<<endl;
    // else cout<<2<<endl;
    ios::sync_with_stdio(false);
    int t;cin>>t;
    while (t --) {
        int n;cin>>n;int flag = false;
        for (int i = 1;i <= n; ++i) {
            hsh[i] = 0;hsha[i] = 0;hshb[i] = 0;
        }
        for (int i = 1;i <= n; i++) {
            cin>>a[i];hsh[a[i]] ++;
            if (hsh[a[i]]>=3) flag = true;
        }
        if (hsh[1]>=2) flag = true;
        vector<int> ansa(n+1,0),ansb(n+1,0);
        for (int i = 1;i <= n;i ++) {
            if (!hsha[a[i]]){
                ansa[i] = a[i];hsha[a[i]] = 1;
            } else {
                if (!hshb[a[i]]) {
                    ansb[i] = a[i];hshb[a[i]] = 1;
                } else {
                    flag = true;break;
                }
            }
        }
        //cout<<":0 "<<flag<<endl;
        set<int> sa,sb;
        for (int i = 1;i <= n;i ++) {
            if (!hsha[i]) sa.insert(i);
            if (!hshb[i]) sb.insert(i);
        }
        //for (auto item:sa)cout<<item<<endl;
        //for (auto item:sb)cout<<item<<endl;
        //cout<<":1 "<<flag<<endl;
        for (int i = 1;i <= n;i ++) {
            
            if (!ansa[i]) {
                auto item = sa.upper_bound(ansb[i]);
                
                if (*sa.begin()>ansb[i]) {flag = true;break;}
                item --;ansa[i] = *item;sa.erase(*item);
            }
            if (!ansb[i]) {
                auto item = sb.upper_bound(ansa[i]);
                //cout<<(*sb.end())<<endl;
                
                if (*sb.begin()>ansa[i]){ flag = true;break;}
                item--;ansb[i] = *item;sb.erase(*item);
                
            }
        }
        for (int i = 1;i <= n;i ++) {
            if (max(ansa[i],ansb[i])!=a[i]) {
                flag = true;break;
            }
        }
        if (flag) {cout<<"NO"<<endl;continue;}
        
        cout<<"YES"<<endl;
        for (int i = 1;i <= n;i ++) {
            cout<<ansa[i]<<" ";
        }cout<<endl;
        for (int i = 1;i <= n;i ++) {
            cout<<ansb[i]<<" ";
        }cout<<endl;
    }
    return 0;
}

D. Lucky Permutation

  • 题意
    在这里插入图片描述
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

疯狂的码泰君

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值