Submission #44110836


Source Code Expand

// LUOGU_RID: 118164649
#include<cstdio>
#include<cstring>
using namespace std;
#define Ls(i,l,r) for(int i=l;i<r;++i)
#define Rs(i,l,r) for(int i=l;i>r;--i)
#define Le(i,l,r) for(int i=l;i<=r;++i)
#define Re(i,l,r) for(int i=l;i>=r;--i)
#define L(i,l) for(int i=0;i<l;++i)
#define E(i,l) for(int i=1;i<=l;++i)
#define W(t) while(t--)
// #define add(a,b) (a+=b)>=mod&&(a-=mod)
#define sub(a,b) (a-=b)<0&&(a+=mod)
namespace IO{
	const char fg=' ';
	int len=0;
	char ibuf[(1<<20)+1],*iS,*iT,out[(1<<25)+1],ar[50];
	#define gh()\
	(iS==iT?iT=(iS=ibuf)+fread(ibuf,1,(1<<20)+1,stdin),\
	(iS==iT?EOF:*iS++):*iS++)
	#define putc(ch) out[len++]=ch
	void read(){}
	template<typename Type,typename...Types>
	void read(Type&x,Types&...xs){
		x=0;
		char ch=gh();
		char t=0;
		while(ch<'0'||ch>'9')t|=ch=='-',ch=gh();
		while(ch>='0'&&ch<='9')x=x*10+(ch^48),ch=gh();
		x=t?-x:x;
		read(xs...);
	}
	template<typename Type>
	void write(Type x){
		int tot=0;
		if(!x)putc('0');
		if(x<0)putc('-'),x=-x;
		while(x)ar[++tot]=x%10+'0',x/=10;
		for(int i=tot;i;--i)putc(ar[i]);
		putc(fg);
	}
	void flush(){
		fwrite(out,1,len,stdout);
		len=0;
	}
}
typedef long long ll;
using namespace IO;
const int N=200010;
int n,a[N],b[N],c[N],cnt[N];
bool cf;
ll ans;
void add(int x,int v=1){
	for(;x<=n;x+=x&-x)c[x]+=v;
}
int sum(int x){
	int res=0;
	for(;x;x-=x&-x)res+=c[x];
	return res;
}
int main(){
	#ifndef ONLINE_JUDGE
	freopen("1.in","r",stdin);
	// freopen("1.out","w",stdout);
	#endif
	// Insert Code Here
	// ios::sync_with_stdio(0);
	// cin.tie(0);
	// cout.tie(0);
	read(n);
	E(i, n)read(a[i]),++cnt[a[i]],cf|=cnt[a[i]]>1;
	E(i, n)read(b[i]),--cnt[b[i]];
	E(i, n)
		if(cnt[i])return puts("No"),0;
	if(cf)return puts("Yes"),0;
	Re(i, n, 1){
		ans+=sum(n)-sum(a[i]);
		add(a[i]);
	}
	memset(c,0,n*4+4);
	Re(i, n, 1){
		ans+=sum(n)-sum(b[i]);
		add(b[i]);
	}
	puts(ans&1?"No":"Yes");
	return 0;
}

Submission Info

Submission Time
Task F - Simultaneous Swap
User WUSICHENG
Language C++ (GCC 9.2.1)
Score 500
Code Size 1964 Byte
Status AC
Exec Time 37 ms
Memory 5636 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 500 / 500
Status
AC × 4
AC × 48
Set Name Test Cases
Sample example_00.txt, example_01.txt, example_02.txt, example_03.txt
All example_00.txt, example_01.txt, example_02.txt, example_03.txt, hand_00.txt, hand_01.txt, hand_02.txt, hand_03.txt, hand_04.txt, hand_05.txt, hand_06.txt, hand_07.txt, hand_08.txt, overlap_00.txt, overlap_01.txt, overlap_02.txt, overlap_03.txt, overlap_04.txt, overlap_05.txt, overlap_06.txt, overlap_07.txt, overlap_08.txt, overlap_09.txt, overlap_10.txt, overlap_11.txt, overlap_12.txt, overlap_13.txt, overlap_14.txt, random_00.txt, random_01.txt, random_02.txt, random_03.txt, random_04.txt, random_05.txt, random_06.txt, random_07.txt, random_08.txt, random_09.txt, random_10.txt, random_11.txt, random_12.txt, random_13.txt, random_14.txt, random_15.txt, random_16.txt, random_17.txt, random_18.txt, random_19.txt
Case Name Status Exec Time Memory
example_00.txt AC 7 ms 1412 KiB
example_01.txt AC 1 ms 1436 KiB
example_02.txt AC 1 ms 1504 KiB
example_03.txt AC 1 ms 1552 KiB
hand_00.txt AC 27 ms 5588 KiB
hand_01.txt AC 26 ms 5548 KiB
hand_02.txt AC 33 ms 5632 KiB
hand_03.txt AC 34 ms 5552 KiB
hand_04.txt AC 8 ms 3748 KiB
hand_05.txt AC 11 ms 3828 KiB
hand_06.txt AC 13 ms 4912 KiB
hand_07.txt AC 13 ms 4860 KiB
hand_08.txt AC 13 ms 4828 KiB
overlap_00.txt AC 16 ms 4912 KiB
overlap_01.txt AC 21 ms 4868 KiB
overlap_02.txt AC 18 ms 4908 KiB
overlap_03.txt AC 17 ms 4748 KiB
overlap_04.txt AC 21 ms 4756 KiB
overlap_05.txt AC 16 ms 4812 KiB
overlap_06.txt AC 22 ms 4852 KiB
overlap_07.txt AC 19 ms 4768 KiB
overlap_08.txt AC 21 ms 4856 KiB
overlap_09.txt AC 21 ms 4764 KiB
overlap_10.txt AC 17 ms 4752 KiB
overlap_11.txt AC 19 ms 4760 KiB
overlap_12.txt AC 18 ms 4912 KiB
overlap_13.txt AC 16 ms 4812 KiB
overlap_14.txt AC 23 ms 4800 KiB
random_00.txt AC 33 ms 5632 KiB
random_01.txt AC 35 ms 5628 KiB
random_02.txt AC 34 ms 5636 KiB
random_03.txt AC 37 ms 5568 KiB
random_04.txt AC 36 ms 5584 KiB
random_05.txt AC 34 ms 5624 KiB
random_06.txt AC 33 ms 5536 KiB
random_07.txt AC 33 ms 5548 KiB
random_08.txt AC 34 ms 5632 KiB
random_09.txt AC 35 ms 5552 KiB
random_10.txt AC 34 ms 5628 KiB
random_11.txt AC 33 ms 5624 KiB
random_12.txt AC 33 ms 5632 KiB
random_13.txt AC 36 ms 5548 KiB
random_14.txt AC 33 ms 5632 KiB
random_15.txt AC 33 ms 5536 KiB
random_16.txt AC 33 ms 5544 KiB
random_17.txt AC 33 ms 5632 KiB
random_18.txt AC 33 ms 5632 KiB
random_19.txt AC 35 ms 5528 KiB