Codeforces Round #842 (Div. 2) C. Elemental Decompress
创始人
2024-05-07 03:29:48
0

翻译:

您将得到一个由𝑛个整数组成的数组𝑎。

找到两个排列组合𝑝长度和𝑞𝑛这样马克斯(𝑝𝑖,𝑞𝑖)=𝑎𝑖所有1≤𝑖≤𝑛或报告这样𝑝𝑞并不存在。

†一个长度为𝑛的排列是一个由𝑛个不同的整数组成的数组,从1到𝑛,顺序是任意的。例如,[2,3,1,5,4]是一个排列,但[1,2,2]不是一个排列(2在数组中出现了两次),[1,3,4]也不是一个排列(𝑛=3,但数组中有4)。

输入

第一行包含一个整数𝑡(1≤𝑡≤104)——测试用例的数量。测试用例的描述如下。

每个测试用例的第一行包含一个整数𝑛(1≤𝑛≤2⋅105)。

每个测试用例的第二行包含𝑛整数𝑎1𝑎2,…,𝑎𝑛(1≤𝑎𝑖≤𝑛)——𝑎数组。

可以保证𝑛对所有测试用例的总和不超过2⋅105。

输出

对于每个测试用例,如果不存在满足条件的𝑝和𝑞,则输出“NO”(不带引号)。

否则,输出“YES”(不带引号),然后输出2行。第一行应该包含𝑛整数𝑝1,𝑝2,…,𝑝𝑛,第二行应该包含𝑛整数𝑞1,𝑞2,…,𝑞𝑛。

如果有多个解决方案,则可以输出其中任何一个。

您可以在任何情况下输出“YES”和“NO”(例如,字符串“YES”,“YES”和“YES”将被识别为积极响应)。

例子

inputCopy

3.

1

1

5

5 3 4 2 5

2

1

outputCopy

是的

1

1

是的

1 3 4 2 5

5 2 3 1 4

没有

请注意

在第一个测试用例中,𝑝=𝑞=[1]。这是正确的,因为𝑎1=𝑚𝑎𝑥(𝑝1,𝑞1)=1。

在第二个测试用例,𝑝=(1、3、4、2、5)和𝑞=[5,2、3、1,4]。是正确的,因为:

𝑎1 = max(𝑝1𝑞1)= max(1、5)= 5,

𝑎2 = max(𝑝2𝑞2)= max (3 2) = 3,

𝑎3 = max(𝑝3𝑞3)= max (4,3) = 4,

𝑎4 = max(𝑝4𝑞4)= max (2, 1) = 2,

𝑎5 = max(𝑝5𝑞5)= max(5 4) = 5。

在第三个测试用例中,可以显示不存在𝑝和𝑞。

思路:利用STL,然后无脑暴力,先放可以放的,无法决定的存入优先队列里面,然后没有放的也排下序,为了尽量能放下肯定先放小的,所以能放就放,最后判断一下就好了。‘

代码:

/*Looking! The blitz loop this planet to search wayOnly my RAILGUN can shoot it 今すぐ身体中を  光の速さで駆け巡った確かな予感掴め! 望むものなら残さず輝ける自分らしさで信じてるよ  あの日の誓いをこの瞳に光る涙それさえも  強さになるから*/
#include 
#include 
#include 
#include 
#include 
#include 
#include
#include
#include
#include
#include
#include
#include
using namespace::std;
typedef long long  ll;
inline __int128 read(){__int128 x = 0, f = 1;char ch = getchar();while(ch < '0' || ch > '9'){if(ch == '-')f = -1;ch = getchar();}while(ch >= '0' && ch <= '9'){x = x * 10 + ch - '0';ch = getchar();}return x * f;
}
inline void print(__int128 x){if(x < 0){putchar('-');x = -x;}if(x > 9)print(x / 10);putchar(x % 10 + '0');
}namespace simpler{
template
class modint{
protected:int64_t _val;typedef modint<_Mod> _mint;friend inline _mint__construct(_mint&& _res,int64_t _x){_res._val=_x;return _res;}templatefriend _mint__quickly_power(_mint _a,_Tp _b){if(_b<=0)return 1;_mint _res=1;for(;(bool)_b;_b>>=1,_a*=_a)if(_b&1)_res*=_a;return _res;}
public:modint():_val(0){}templatemodint(_Tp _x){_val=((int64_t)_x%_Mod+_Mod)%_Mod;}templateexplicit inline operator _Tp(){return (_Tp)_val;}friend _mint operator+(const _mint& _a,const _mint& _b){if(_a._val+_b._val>=_Mod)return __construct(_mint(),_a._val+_b._val-_Mod);return __construct(_mint(),_a._val+_b._val);}inline _mint& operator+=(const _mint& _b){return *this=*this+_b;}inline _mint& operator++(){return *this=*this+__construct(_mint(),1);}inline _mint& operator++(int){_mint _res=*this;*this=*this+__construct(_mint(),1);return _res;}//plusfriend _mint operator-(const _mint& _a,const _mint& _b){if(_a._val-_b._val<0)return __construct(_mint(),_a._val-_b._val+_Mod);return __construct(_mint(),_a._val-_b._val);}inline _mint& operator-=(const _mint& _b){return *this=*this-_b;}inline _mint& operator--(){return *this=*this-__construct(_mint(),1);}inline _mint& operator--(int){_mint _res=*this;*this=*this-__construct(_mint(),1);return _res;}//minusfriend inline _mintoperator*(const _mint& _a,const _mint& _b){return __construct(_mint(),_a._val*_b._val%_Mod);}inline _mint& operator*=(const _mint& _b){return *this=*this*_b;}//multiplies_mint operator-(){return __construct(_mint(),_val?_Mod-_val:_val);}//negativefriend inline _mintoperator%(const _mint& _a,const _mint& _b){return __construct(_mint(),_a._val%_b._val);}inline _mint& operator%=(const _mint& _b){return *this=*this%_b;}//modulusfriend inline booloperator==(const _mint& _a,const _mint& _b){return _a._val==_b._val;}friend inline booloperator!=(const _mint& _a,const _mint& _b){return _a._val!=_b._val;}friend inline booloperator<(const _mint& _a,const _mint& _b){return _a._val<_b._val;}friend inline booloperator>(const _mint& _a,const _mint& _b){return _a._val>_b._val;}friend inline booloperator<=(const _mint& _a,const _mint& _b){return _a._val<=_b._val;}friend inline booloperator>=(const _mint& _a,const _mint& _b){return _a._val>=_b._val;}friend inline _mintoperator&(const _mint& _a,const _mint& _b){return _a._val&_b._val;}inline _mint& operator&=(const _mint& _b){return *this=*this&_b;}friend inline _mintoperator|(const _mint& _a,const _mint& _b){return _a._val|_b._val;}inline _mint& operator|=(const _mint& _b){return *this=*this|_b;}friend inline _mintoperator^(const _mint& _a,const _mint& _b){return _a._val^_b._val;}inline _mint& operator^=(const _mint& _b){return *this=*this^_b;}friend inline _mintoperator<<(const _mint& _a,const _mint& _b){return _a._val<<_b._val;}inline _mint& operator<<=(const _mint& _b){return *this=*this<<_b;}friend inline _mintoperator>>(const _mint& _a,const _mint& _b){return _a._val>>_b._val;}inline _mint& operator>>=(const _mint& _b){return *this=*this>>_b;}inline _mint operator~()const{return __construct(_mint(),~_val);}inline bool  operator!()const{return !_val;}friend inline std::istream&operator>>(std::istream& _is,_mint& _b){return _is>>_b._val;}friend inline std::ostream&operator<<(std::ostream& _os,const _mint& _b){return _os<<_b._val;}template_mintpower(_Tp _n)const{return __quickly_power(*this,_n);}inline _mint inv()const{return __quickly_power(*this,_Mod-2);}friend inline _mintoperator/(const _mint& _a,const _mint& _b){return __construct(_mint(),_a._val*_b.inv()._val%_Mod);}inline _mint& operator/=(const _mint& _b){return *this=*this/_b;}
};//modint 2.0
}
using mint=simpler::modint<998244353>;
const int Maxn=2e5+5;
//definition
//mint a[Maxn];
//mint f[2][Maxn];
int n,t;
int a[200005];
struct we{int x,y;
}p[200005],q[200005];
int an1[200005],an2[200005];
bool cmp(we a,we b){return a.x>n;mapff;bool bj=0;for (int i =1; i<=n; i++) {cin>>a[i];p[i].x=-1;q[i].x=-1;an1[i]=an2[i]=-9999;ff[a[i]]++;if (ff[a[i]]>2) {bj=1;}}if (bj||ff[1]>=2) {printf("NO\n");return;}setf1,f2;for (int i =1; i<=n; i++) {if (ff[a[i]]==1) {ff[a[i]]--;p[i].x=a[i];an1[i]=a[i];f1.insert(a[i]);}else if(ff[a[i]]==2){ff[a[i]]--;q[i].x=a[i];an2[i]=a[i];f2.insert(a[i]);}p[i].y=q[i].y=i;}priority_queue,greater>d1,d2;for (int i =1; i<=n; i++) {if (!f1.count(i)) {d1.push(i);}if (!f2.count(i)) {d2.push(i);}}sort(p+1, p+1+n, cmp);sort(q+1, q+1+n, cmp);for (int i =1; i<=n; i++) {if (q[i].x==-1) {continue;}if (d1.top()<=q[i].x) {an1[q[i].y]=d1.top();d1.pop();}
//        else{
//            printf("NO\n");return;
//        }}for (int i =1; i<=n; i++) {if (p[i].x==-1) {continue;}if (d2.top()<=p[i].x) {an2[p[i].y]=d2.top();d2.pop();}
//        else{
//            printf("NO\n");return;
//        }}
//    sort(p+1, p+1+n, cmp2);
//    sort(q+1, q+1+n, cmp2);if (*min_element(an1+1, an1+1+n)==-9999||*min_element(an2+1, an2+1+n)==-9999) {printf("NO\n");return;}printf("YES\n");for (int i =1; i<=n; i++) {printf("%d ",an1[i]);}printf("\n");for (int i =1; i<=n; i++) {printf("%d ",an2[i]);}printf("\n");
}
int main(){ios::sync_with_stdio(false);cin.tie(); cout.tie();cin>>t;while (t--) {wanyurukong();}//wanyurukongreturn 0;
}

相关内容

热门资讯

安卓系统8.0镜像下载,轻松打... 你有没有想过,想要给你的安卓手机升级到最新的系统,却不知道从哪里下载那个神秘的安卓系统8.0镜像呢?...
安卓系统修改大全,全方位修改大... 你有没有想过,你的安卓手机其实是个大宝藏,里面藏着无数可以让你手机焕然一新的秘密?没错,今天就要来个...
安卓刷miui系统教程,安卓刷... 你有没有想过给你的安卓手机换换口味?别看它现在用得挺顺手的,偶尔来点新鲜感也是不错的。今天,就让我来...
超星学系统安卓版,便捷学习新体... 你有没有发现,学习生活越来越离不开电子设备了?手机、平板,这些小玩意儿简直就是我们的学习小助手。今天...
安卓平板6.0系统安装,轻松上... 你有没有想过,你的安卓平板6.0系统是不是该升级一下了呢?别看它现在看起来还挺精神的,但谁知道背后隐...
安卓系统屏幕显示文字,探索个性... 你有没有发现,手机屏幕上的文字有时候会变得模糊不清,或者颜色暗淡,让人看得很费劲?这可真是让人头疼的...
快递扫描系统下载安卓,便捷物流... 你有没有想过,每次快递员来送快递,他们是怎么快速找到你的包裹的呢?是不是觉得他们有超能力?其实,这背...
安卓系统能打开zip,操作指南... 你有没有想过,你的安卓手机里那些神秘的zip文件到底怎么打开呢?别急,今天就来给你揭秘这个小小的技术...
塞班怎么查找安卓系统,塞班系统... 你有没有想过,你的塞班手机里竟然也能装上安卓系统?听起来是不是有点神奇?别急,今天我就来手把手教你如...
安卓系统短消息提醒,安卓系统短... 你有没有发现,手机里的短消息提醒功能有时候就像一个贴心的管家,有时候又像个爱闹腾的小孩子?今天,咱们...
安卓系统如何跳过密码,安卓系统... 你是不是也和我一样,有时候手机锁屏密码设置得太复杂,每次解锁都要费好大一番力气?别急,今天就来教你怎...
鸿蒙系统功能与安卓,功能对比与... 你知道吗?最近手机圈里可是热闹非凡呢!华为的新操作系统鸿蒙系统(HarmonyOS)一经推出,就引发...
安卓系统卡苹果系统不卡,揭秘两... 你有没有发现,身边的朋友都在争论安卓系统和苹果系统哪个更好?其实,这个问题就像是在问谁家的孩子更聪明...
安卓系统卡解决了吗,安卓系统卡... 你有没有遇到过安卓手机卡顿的问题?是不是每次打开应用都感觉像蜗牛爬行?别急,今天就来聊聊这个让人头疼...
华为安卓系统下载软件,畅享海量... 你有没有想过,手机里的系统就像是我们的大脑,而下载的软件就像是大脑里的各种功能?今天,就让我带你一起...
平板安卓7系统好吗,体验流畅与... 你有没有想过,你的平板电脑的安卓7系统到底怎么样呢?是不是觉得它既熟悉又有点陌生?别急,今天咱们就来...
鸿蒙系统和安卓10,跨时代操作... 你知道吗?最近科技圈可是炸开了锅,因为华为的新操作系统鸿蒙系统横空出世,而且它竟然和安卓10杠上了!...
苹果安卓和鸿蒙系统,三大操作系... 你有没有发现,现在的手机市场就像是一场精彩纷呈的武林大会,各路英雄齐聚一堂,各显神通?没错,说的就是...
鸿蒙怎么还原安卓系统,系统还原... 你是不是也和我一样,对鸿蒙系统里的安卓应用情有独钟呢?最近,不少小伙伴都在问,鸿蒙怎么还原安卓系统?...
荣耀10改回安卓系统,重拾纯净... 你有没有想过,你的荣耀10手机,曾经那般风光无限,如今却想要改回安卓系统呢?这可不是一件小事,得好好...