Problem:


Score : 600 points

Problem Statement

Given are two integer sequences of N elements each: A_1,...,A_N and B_1,...,B_N.
Determine if it is possible to do the following operation at most N-2 times (possibly zero) so that, for every integer i from 1 to N, A_i \leq B_i holds:

Choose two distinct integers x and y between 1 and N (inclusive), and swap the values of A_x and A_y.

Constraints

2 \leq N \leq 10^5

1 \leq A_i,B_i \leq 10^9

Input

Input is given from Standard Input in the following format:

N
A_1 A_2 ... A_N
B_1 B_2 ... B_N

Output

If the objective is achievable, print Yes; if it is not, print No.

Sample Input 1

3
1 3 2
1 2 3

Sample Output 1

Yes

We should swap the values of A_2 and A_3.

Sample Input 2

3
1 2 3
2 2 2

Sample Output 2

No

Sample Input 3

6
3 1 2 6 3 4
2 2 8 3 4 3

Sample Output 3

Yes



Sample input:
3
1 3 2
1 2 3


Sample output:
Yes

Submission status: Wrong Answer

Solution code:
import sys

sys.setrecursionlimit(10 ** 6)
input = sys.stdin.readline
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")

def main():
    n = int(input())
    aa = list(map(int, input().split()))
    bb = list(map(int, input().split()))
    aaii = []
    for i,a in enumerate(aa):
        aaii.append([a,i])
    aaii.sort()
    bb.sort()
    swap=False
    for i in range(n):
        if aaii[i][0]>bb[i]:
            print("No")
            exit()
        if swap:continue
        if i+1<n and aaii[i+1][0]<=bb[i]:
            swap=True
    if swap:
        print("Yes")
        exit()
    now=0
    cnt=0
    while 1:
        now=aaii[now][1]
        cnt+=1
        if now==0:
            if cnt<n:
                print("Yes")
            else:
                print("No")
            break

main()

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda :sys.stdin.readline().rstrip()
def resolve():
    n=int(input())
    A=list(map(int,input().split()))
    B=list(map(int,input().split()))
    C=sorted(A)
    D=sorted(B)

    # C[i]<=D[i] でなければ不可能
    if(any(C[i]>D[i] for i in range(n))):
        print("No")
        return

    # 1つでもC[i+1]<=D[i]があれば可能
    if(any(C[i+1]<=D[i] for i in range(n-1))):
        print("Yes")
        return

    # このどちらでもないとき、A のソートがn-1のサイクルになると不可能
    # B をソートさせて、それに対応するように A のソートを行う
    F=[(b,i) for i,b in enumerate(B)]
    F.sort()
    E=[0]*n
    for i in range(n):
        j=F[i][1]
        E[j]=(A[i],i)

    # 0から始めて、0に返ってくる最小回数を数える
    cnt=1
    j=E[0][1]
    while(j!=0):
        cnt+=1
        j=E[j][1]

    if(cnt<n-1):
        print("Yes")
    else:
        print("No")

resolve()

Submission status: Wrong Answer

Solution code:
n = int(input())
a = sorted(list(map(int,input().split())))
b = sorted(list(map(int,input().split())))

flag = 0
for i in range(n):
    if a[i] > b[i]:
        flag = 1

if flag == 1:
    print('No')
else:
    print('Yes')

Submission status: Wrong Answer

Solution code:
import sys

sys.setrecursionlimit(10 ** 6)
input = sys.stdin.readline
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")

def main():
    n = int(input())
    aa = list(map(int, input().split()))
    bb = list(map(int, input().split()))
    aaii = []
    for i,a in enumerate(aa):
        aaii.append([a,i])
    aaii.sort()
    bb.sort()
    flag=False
    for i in range(n):
        if aaii[i][0]>bb[i]:
            print("No")
            exit()
        if flag:continue
        if i+1<n and aaii[i+1][0]<=bb[i]:
            flag=True
    if flag:
        print("Yes")
        exit()
    now=0
    cnt=0
    while 1:
        now=aaii[now][1]
        cnt+=1
        if now==0:
            if cnt<n:
                print("Yes")
            else:
                print("No")
            break

main()

Submission status: Wrong Answer

Solution code:
import sys

sys.setrecursionlimit(10 ** 6)
input = sys.stdin.readline
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")

def main():
    n = int(input())
    aa = list(map(int, input().split()))
    bb = list(map(int, input().split()))
    aaii = []
    for i,a in enumerate(aa):
        aaii.append([a,i])
    aaii.sort()
    bb.sort()
    for i in range(n):
        if aaii[i][0]>bb[i]:
            print("No")
            exit()
    now=0
    cnt=0
    while 1:
        now=aaii[now][1]
        cnt+=1
        if now==0:
            if cnt<n:
                print("Yes")
                exit()
            else:
                break
    for [a,i],b in zip(aaii[1:],bb):
        if a<=b:
            print("Yes")
            exit()
    print("No")

main()

Submission status: Wrong Answer

Solution code:
N = int(input())
A = [int(i) for i in input().split()]
B = [int(i) for i in input().split()]

A.sort()

ans = "Yes"
for i in range(N):
  if A[i] > B[i]:
    ans = "No"
    break

print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = [int(i) for i in input().split()]
B = [int(i) for i in input().split()]

A.sort()
B.sort()

ans = "Yes"
for i in range(N):
  if A[i] > B[i]:
    ans = "No"
    break

print(ans)

Submission status: Wrong Answer

Solution code:
import numpy as np
N=int(input())
A=np.array(list(map(int,input().split())))
B=np.array(list(map(int,input().split())))

AB=np.array([(A[i],B[i]) for i in range(N)])
AB=AB[np.argsort(AB[:,1])]

AI=np.array([[i,AB[i,0]] for i in range(N)])
AI=AI[np.argsort(AI[:,1])]

sigma=AI[:,0]
ASort=AI[:,1]
BSort=AB[:,1]

g=0
f=0
for i in range(N):
    if ASort[i]>BSort[i]:
        g=1
        break

counter=1
start=0
now=sigma[start]
while start!=now:
    now=sigma[now]
    counter+=1
    
if N==counter:
    f=1
    # for i in range(N-1):
    #     if BSort[i]>=ASort[i+1]:
    #         f=0
    #         break

if f==0 and g==0:
    print("Yes")
else:
    print("No")

Submission status: Wrong Answer

Solution code:
import numpy as np
N=int(input())
A=np.array(list(map(int,input().split())))
B=np.array(list(map(int,input().split())))

AB=np.array([(A[i],B[i]) for i in range(N)])
AB=AB[np.argsort(AB[:,1])]

AI=np.array([[i,AB[i,0]] for i in range(N)])
AI=AI[np.argsort(AI[:,1])]

sigma=AI[:,0]
ASort=AI[:,1]
BSort=AB[:,1]

g=0
f=0
for i in range(N):
    if ASort[i]>BSort[i]:
        g=1
        break

counter=0
start=0
now=sigma[start]
while start!=now:
    now=sigma[now]
    counter+=1
    
if N==counter:
    f=1
    for i in range(N-1):
        if BSort[i]>=ASort[i+1]:
            f=0
            break

if f==0 and g==0:
    print("Yes")
else:
    print("No")

Submission status: Wrong Answer

Solution code:
import numpy as np
N=int(input())
A=np.array(list(map(int,input().split())))
B=np.array(list(map(int,input().split())))

AB=np.array([(a,b) for a,b in zip(A,B)])
AB=AB[np.argsort(AB[:,1])]

AI=np.array([[i,AB[i,0]] for i in range(N)])
AI=AI[np.argsort(AI[:,1])]

sigma=AI[:,0]
ASort=AI[:,1]
BSort=AB[:,1]

g=0
f=0
for i in range(N):
    if ASort[i]>BSort[i]:
        g=1
        break

counter=0
start=0
now=sigma[start]
while start!=now:
    now=sigma[now]
    counter+=1
    
if N==counter:
    f=1
    for i in range(N-1):
        if BSort[i]>=ASort[i+1]:
            f=0
            break
if f==0 and g==0:
    print("Yes")
else:
    print("No")

Submission status: Wrong Answer

Solution code:
import numpy as np
N=int(input())
A=np.array(list(map(int,input().split())))
B=np.array(list(map(int,input().split())))

AB=np.array([(a,b) for a,b in zip(A,B)])
AB=AB[np.argsort(AB[:,1])]

AI=np.array([[i,AB[i,0]] for i in range(N)])
AI=AI[np.argsort(AI[:,1])]

sigma=AI[:,0]
ASort=AI[:,1]
BSort=AB[:,1]

g=0
f=0
for i in range(N):
    if ASort[i]>BSort[i]:
        g=1
        break

counter=0
start=0
now=sigma[start]
while start!=now:
    now=sigma[now]
    counter+=1
    
if N==counter:
    f=1
    for i in range(N-1):
        if BSort[i]>=ASort[i+1]:
            f=0
            break
if f==1 or g==1:
    print("No")
else:
    print("Yes")

Submission status: Wrong Answer

Solution code:
import numpy as np
N=int(input())
A=np.array(list(map(int,input().split())))
B=np.array(list(map(int,input().split())))

AB=np.array([(a,b) for a,b in zip(A,B)])
AB=AB[np.argsort(AB[:,1])]

AI=np.array([[i,AB[i,0]] for i in range(N)])
AI=AI[np.argsort(AI[:,1])]

sigma=AI[:,0]
ASort=AI[:,1]
BSort=AB[:,1]

g=0
f=0
for i in range(N):
    if ASort[i]>BSort[i]:
        g=1
        break

counter=0
if g==0:
    start=0
    now=sigma[start]
    while start!=now:
        now=sigma[now]
        counter+=1
    
    if N==counter:
        f=1
        for i in range(N-1):
            if BSort[i]>=ASort[i+1]:
                f=0
                break
if f==1 or g==1:
    print("No")
else:
    print("Yes")

Submission status: Wrong Answer

Solution code:
import numpy as np
N=int(input())
A=np.array(list(map(int,input().split())))
B=np.array(list(map(int,input().split())))

AB=np.array([(a,b) for a,b in zip(A,B)])
AB=AB[np.argsort(AB[:,1])]

AI=np.array([[i,AB[i,0]] for i in range(N)])
AI=AI[np.argsort(AI[:,1])]

sigma=AI[:,0]
ASort=AI[:,1]
BSort=AB[:,1]

g=0
f=0
for i in range(N):
    if ASort[i]>BSort[i]:
        g=1
        break

used=np.array([])
if g==0:
    start=0
    now=sigma[start]
    np.append(used,now)
    while start!=now:
        now=sigma[now]
        np.append(used,now)
    
    
    if N==len(used):
        f=1
        for i in range(N-1):
            if BSort[i]>=ASort[i+1]:
                f=0
                break
if f==1 or g==1:
    print("No")
else:
    print("Yes")

Submission status: Wrong Answer

Solution code:
import numpy as np
N=int(input())
A=np.array(list(map(int,input().split())))
B=np.array(list(map(int,input().split())))

AB=np.array([(a,b) for a,b in zip(A,B)])
AB=AB[np.argsort(AB[:,1])]

AI=np.array([[i,AB[i,0]] for i in range(N)])
AI=AI[np.argsort(AI[:,1])]

sigma=AI[:,0]
ASort=AI[:,1]
BSort=AB[:,1]

g=0
f=0
for i in range(N):
    if ASort[i]>BSort[i]:
        g=1
        break

used=np.array([])
if g==0:
    start=0
    now=sigma[start]
    np.append(used,now)
    while start!=now:
        now=sigma[now]
        np.append(used,now)
    
    used=np.unique(used)
    if N==len(used):
        f=1
        for i in range(N-1):
            if BSort[i]>=ASort[i+1]:
                f=0
                break
if f==1 or g==1:
    print("No")
else:
    print("Yes")

Submission status: Wrong Answer

Solution code:
import numpy as np
N=int(input())
A=np.array(list(map(int,input().split())))
B=np.array(list(map(int,input().split())))

AB=np.array([(a,b) for a,b in zip(A,B)])
AB=AB[np.argsort(AB[:,1])]

AI=np.array([[i,AB[i,0]] for i in range(N)])
AI=AI[np.argsort(AI[:,1])]

sigma=AI[:,0]
ASort=AI[:,1]
BSort=AB[:,1]

g=0
for i in range(N):
    if ASort[i]>BSort[i]:
        g=1
        break

used=np.array([])
if g==0:
    start=0
    now=sigma[start]
    np.append(used,now)
    while start!=now:
        now=sigma[now]
        np.append(used,now)
    
used=np.unique(used)
f=0
if N==len(used):
    f=1
    for i in range(N-1):
        if BSort[i]>=ASort[i+1]:
            f=0
            break
if f==1 or g==1:
    print("No")
else:
    print("Yes")

Submission status: Wrong Answer

Solution code:
import numpy as np
N=int(input())
A=np.array(list(map(int,input().split())))
B=np.array(list(map(int,input().split())))
AB=np.array([(a,b) for a,b in zip(A,B)])
AB=AB[np.argsort(AB[:,1])]
AI=np.array([[i,AB[i,0]] for i in range(N)])
AI=AI[np.argsort(AI[:,1])]
sigma=AI[:,0]
ASort=AI[:,1]
BSort=AB[:,1]
g=0
for i in range(N):
    if ASort[i]>BSort[i]:
        g=1
        break

used=np.array([])
if g==0:
    start=0
    now=sigma[start]
    np.append(used,now)
    while start!=now:
        now=sigma[now]
        np.append(used,now)
    
used=np.unique(used)
if N==len(used) or g==1:
    print("No")
else:
    print("Yes")

Submission status: Wrong Answer

Solution code:
import numpy as np
N=int(input())
A=np.array(list(map(int,input().split())))
B=np.array(list(map(int,input().split())))
AB=np.array([(a,b) for a,b in zip(A,B)])
AB=AB[np.argsort(AB[:,1])]
AI=np.array([[i,AB[i,0]] for i in range(N)])
AI=AI[np.argsort(AI[:,1])]
sigma=AI[:,0]
ASort=AI[:,1]
BSort=AB[:,1]
g=0
for i in range(N):
    if ASort[i]>BSort[i]:
        g=1
        break
    
used=np.array([])
if g==0:
    start=0
    now=sigma[start]
    np.append(used,now)
    while start!=now:
        now=sigma[now]
        np.append(used,now)
    
if N==len(used) or g==1:
    print("No")
else:
    print("Yes")

Submission status: Wrong Answer

Solution code:
import numpy as np
N=int(input())
A=np.array(list(map(int,input().split())))
B=np.array(list(map(int,input().split())))
AB=np.array([(a,b) for a,b in zip(A,B)])
AB=AB[np.argsort(AB[:,1])]
AI=np.array([[i,AB[i,0]] for i in range(N)])
AI=AI[np.argsort(AI[:,1])]
sigma=AI[:,0]
ASort=AI[:,1]
BSort=AB[:,1]
g=0
for i in range(N):
    if ASort[i]>BSort[i]:
        g=1
        break
counter=0
if g==0:
    used=np.array([])
    for i in range(N):
        if not(i in used):
            counter+=1
            if counter==2:
                break
            start=i
            np.append(used,i)
            now=sigma[start]
            np.append(used,now)
            while start!=now:
                now=sigma[now]
                np.append(used,now)
if counter<2 or g==1:
    print("No")
else:
    print("Yes")

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline

N=int(input())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
SA=sorted(A)
SB=sorted(B)
D=dict()
for i,j in zip(SA,SB):
    if i>j:
        print("No")
        exit()
    if j not in D:D[j]=i

for i,j in zip(A,B):
    if D[j]<=i<=j:
        print("Yes")
        exit()
else:
    print("No")

Submission status: Wrong Answer

Solution code:
import numpy as np
N=int(input())
A=np.array(list(map(int,input().split())))
B=np.array(list(map(int,input().split())))
AB=np.array([(a,b) for a,b in zip(A,B)])
AB=AB[np.argsort(AB[:,1])]
AI=np.array([[i,AB[i,0]] for i in range(N)])
AI=AI[np.argsort(AI[:,1])]
sigma=AI[:,0]
ASort=AI[:,1]
BSort=AB[:,1]
g=0
for i in range(N):
    if ASort[i]>BSort[i]:
        g=1
        break
counter=0
if g==0:
    used=np.array([])
    for i in range(N):
        if not(i in used):
            counter+=1
            if counter==2:
                break
            start=i
            np.append(used,i)
            now=sigma[start]
            np.append(used,now)
            while start!=now:
                now=sigma[now]
                np.append(used,now)
if counter==1 or g==1:
    print("No")
else:
    print("Yes")

Submission status: Wrong Answer

Solution code:
import numpy as np
N=int(input())
A=np.array(list(map(int,input().split())))
B=np.array(list(map(int,input().split())))
AB=np.array([(a,b) for a,b in zip(A,B)])
AB=AB[np.argsort(AB[:,1])]
AI=np.array([[i,AB[i,0]] for i in range(N)])
AI=AI[np.argsort(AI[:,1])]
sigma=AI[:,0]
ASort=AI[:,1]
BSort=AB[:,1]
g=0
for i in range(N):
    if ASort[i]>BSort[i]:
        g=1
        break
counter=0
if g==0:
    used=np.array([])
    for i in range(N):
        if not(i in used):
            counter+=1
            if counter==2:
                break
            start=i
            np.append(used,i)
            now=sigma[start]
            np.append(used,now)
            while start!=now:
                now=sigma[now]
                np.append(used,now)
if counter!=2 or g==1:
    print("No")
else:
    print("Yes")

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
import sys
import numpy as np
from bisect import bisect_left

N = int(input())
A = np.array(list(map(int, input().split())))
B = np.array(list(map(int, input().split())))

a = np.sort(A)
b = np.sort(B)

if np.any(a > b):
    print("No")
    sys.exit()

an = np.argsort(A)
count = 0
p = 0
while True:
    p = an[p]
    count += 1
    if p == 0 and count != N:
        print("Yes")
        sys.exit()       
    if count == N:
        break
    
        
for i in range(N):
    if A[i] <= B[i]:
        l = bisect_left(b,B[i])
        r = bisect_left(b,B[i]+1) - 1 
        if a[l] <= A[i] <= a[r]:
            print("Yes")
            sys.exit()

print("No")

Submission status: Wrong Answer

Solution code:
import numpy as np
N=int(input())
A=np.array(list(map(int,input().split())))
B=np.array(list(map(int,input().split())))
AB=np.array([(a,b) for a,b in zip(A,B)])
AB=AB[np.argsort(AB[:, 1])]
AI=np.array([(i,AB[i,0]) for i in range(N)])
AI=AI[np.argsort(AI[:, 1])]
sigma=np.array([AI[i,0] for i in range(N)])
ASort=np.array([AI[i,1] for i in range(N)])
BSort=np.array([AB[i,1] for i in range(N)])
g=0
for i in range(N):
    if ASort[i]>BSort[i]:
        g=1
        break
counter=0
if g==0:
    used=np.array([])
    for i in range(N):
        if not(i in used):
            counter+=1
            if counter==2:
                break
            start=i
            np.append(used,i)
            now=sigma[start]
            np.append(used,now)
            while start!=now:
                now=sigma[now]
                np.append(used,now)
if counter!=2 or g==1:
    print("No")
else:
    print("Yes")

Submission status: Wrong Answer

Solution code:
import sys
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
A=sorted(a)
B=sorted(b)
for i in range(n):
  if A[i]>B[i]:
    print('No')
    sys.exit()

c=[]
for i in range(n):
  c.append([b[i],a[i]])
c.sort()

for i in range(1,n):
  if c[i]>=c[i-1]:
    print('Yes')
    sys.exit()
print('No')

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
import sys
import numpy as np

N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

a = np.sort(A)
b = np.sort(B)

if np.any(a > b):
    print("No")
    sys.exit()

an = np.argsort(A)
count = 0
p = 0
while True:
    p = an[p]
    count += 1
    if p == 0 and count != N:
        print("Yes")
        sys.exit()       
    if count == N:
        break
    
if np.any(a[1:] <= b[:-1]):
    print("Yes")
    sys.exit()

print("No")

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
import sys
import numpy as np

N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

a = np.sort(A)
b = np.sort(B)

if np.any(a > b):
    print("No")
    sys.exit()

an = np.argsort(A)
count = 0
p = 0
while True:
    p = an[p]
    count += 1
    if p == 0 and count != N:
        print("Yes")
        sys.exit()       
    if count == N:
        break
    
if np.any(a[1:] <= B[:-1]):
    print("Yes")
    sys.exit()

print("No")

Submission status: Wrong Answer

Solution code:
N=int(input())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
AB=[(a,b) for a,b in zip(A,B)]
AB.sort(key=lambda x:x[1])
AI=[(i,AB[i][0]) for i in range(N)]
AI.sort(key=lambda x:x[1])
sigma=[AI[i][0] for i in range(N)]
ASort=sorted(A)
BSort=sorted(B)
g=0
for i in range(N):
    if ASort[i]>BSort[i]:
        g=1
        break
counter=0
if g==0:
    index=list(range(N))
    used=[]
    for i in index:
        if not(i in used):
            start=i
            used.append(i)
            now=sigma[start]
            used.append(now)
            counter+=1
            if counter==2:
                break
            while start!=now:
                now=sigma[now]
                used.append(now)
if counter!=2 or g==1:
    print("No")
else:
    print("Yes")

Submission status: Wrong Answer

Solution code:
# coding: utf-8
import numpy as np


def solve(*args: str) -> str:
    n = int(args[0])
    A = np.array(list(map(int, args[1].split())))
    B = np.array(list(map(int, args[2].split())))

    ret = False

    sA = np.sort(A)
    sB = np.sort(B)

    if any(sA[1:] <= sB[:-1]):
        ret = True

    elif all(sA <= sB):
        nA = np.argsort(A)
        nB = np.argsort(B)
        P = dict(zip(nA, nB))

        count = 0
        x = P[0]
        while x != 0:
            x = P[x]
            count += 1

        ret = count < n-1

    return 'Yes' if ret else 'No'


if __name__ == "__main__":
    print(solve(*(open(0).read().splitlines())))

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
import sys

N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

a = sorted(A)
b = sorted(B)

for i in range(N):
    if a[i] > b[i]:
        print("No")
        sys.exit()
    
d = a[0]
count = 0
while count != N:
    for i in range(N):
        if d == A[0] and count != N-1:
                print("Yes")
                sys.exit()
        if d == A[i]:
            d = a[i]
            break
    count += 1 
       
for i in range(N-1):
    if a[i+1] <= B[i]:
        print("Yes")
        sys.exit()

print("No")

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline

N=int(input())
A=list(map(int,input().split()))
B=list(map(int,input().split()))

compression_dict={a: ind+1 for ind, a in enumerate(sorted(set(A)|set(B)))}

SA=sorted(A)
SB=sorted(B)

for i in range(N):
    if SA[i]>SB[i]:
        print("No")
        sys.exit()

for i in range(N-1):
    if SB[i]>=SA[i+1]:
        print("Yes")
        sys.exit()

AB=[(B[i],A[i]) for i in range(N)]
AB.sort()

DICT={a:ind for ind,a  in enumerate(A)}

Group=[i for i in range(N)]# グループ分け.Group[i]=jのときiとjは同じグループ

def find(x):# find(a)=find(b)のとき同じグループ
    while Group[x] != x:
        x=Group[x]
    return x

def Union(x,y):  # xとyが同じグループになるよう更新
    if find(x) != find(y):
        Group[find(y)]=Group[find(x)]=min(find(y),find(x))

for i in range(N):
    _,a=AB[i]

    Union(DICT[a],i)

if len(set([find(i) for i in range(N)]))==1:
    print("No")
else:
    print("Yes")

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
import sys
from bisect import bisect_left
import numpy as np

N = int(input())
A = np.array(list(map(int, input().split())))
B = np.array(list(map(int, input().split())))

a = np.sort(A)
b = np.sort(B)
aa = np.argsort(A)

if np.any(a > b):
    print("No")
    sys.exit()
    
d = a[0]
count = 0
while count != N:
    for i in range(N):
        if d == A[0] and count != N-1:
                print("Yes")
                sys.exit()
        if d == A[i]:
            d = a[i]
            break
    count += 1        
        
for i in range(N):
    if A[i] <= B[i]:
        l = bisect_left(b,B[i])
        r = bisect_left(b,B[i]+1) - 1
        if r == -1:
            r = 0
        if a[l] <= A[i] <= a[r]:
            print("Yes")
            sys.exit()

print("No")

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline

N=int(input())
A=list(map(int,input().split()))
B=list(map(int,input().split()))

compression_dict={a: ind+1 for ind, a in enumerate(sorted(set(A)|set(B)))}

SA=sorted(A)
SB=sorted(B)

for i in range(N):
    if SA[i]>SB[i]:
        print("No")
        sys.exit()

for i in range(N-1):
    if SB[i]>SA[i+1]:
        print("Yes")
        sys.exit()

AB=[(B[i],A[i]) for i in range(N)]
AB.sort()

DICT={a:ind for ind,a  in enumerate(A)}

Group=[i for i in range(N)]# グループ分け.Group[i]=jのときiとjは同じグループ

def find(x):# find(a)=find(b)のとき同じグループ
    while Group[x] != x:
        x=Group[x]
    return x

def Union(x,y):  # xとyが同じグループになるよう更新
    if find(x) != find(y):
        Group[find(y)]=Group[find(x)]=min(find(y),find(x))

for i in range(N):
    _,a=AB[i]

    Union(DICT[a],i)

if len(set([find(i) for i in range(N)]))==1:
    print("No")
else:
    print("Yes")

Submission status: Wrong Answer

Solution code:
import sys
import numpy as np
input = sys.stdin.readline

_n = int(input())
_alist = list(map(int, input().split()))
_blist = list(map(int, input().split()))


def chker(n, A, B):
    ba = list(zip(B, A))
    ba.sort()
    ba = np.array(ba)
    A, B = ba[:, 1], ba[:, 0]
    Ap = np.array(sorted([(a, index) for index, a in enumerate(A)]))

    for a, b in zip(Ap[:, 0], B):
        if a > b:
            print('No')
            return

    stt, cnt = 0, 0
    Apc, index = Ap[:, 1], stt
    while True:
        if Apc[index] == stt:
            if cnt < n - 1:
                print('Yes')
                return
            else:
                break
        else:
            cnt += 1
            index = Apc[index]

    for a, b in zip(A[1:], B[:-1]):
        if a <= b:
            print('Yes')
            return

    print('No')


chker(_n, _alist, _blist)

Submission status: Wrong Answer

Solution code:
import sys
from operator import itemgetter
sys.setrecursionlimit(10**9)
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))

a = [[a[i], i] for i in range(n)]
a.sort()
b.sort()

for i in range(n):
    if a[i][0] > b[i]:
        print('No')
        sys.exit()

c = 0
num = a[0][1]
while c < n and num != 0:
    num = a[num][1]
    c += 1
if num == 0 and c < n-1:
    print('Yes')
    sys.exit()

for i in range(1, n):
    if a[i][0] <= b[i-1]:
        print('Yes')
        sys.exit()
print('No')

Submission status: Wrong Answer

Solution code:
import sys
from operator import itemgetter
sys.setrecursionlimit(10**9)
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))

a = [[a[i], i] for i in range(n)]
a.sort()
b.sort()

for i in range(n):
    if a[i][0] > b[i]:
        print('No')
        sys.exit()

c = 0
num = a[0][1]
while c < n and num != 0:
    num = a[num][1]
    c += 1
if num == 0 and c < n:
    print('Yes')
    sys.exit()

for i in range(1, n):
    if a[i][0] <= b[i-1]:
        print('Yes')
        sys.exit()
print('No')

Submission status: Wrong Answer

Solution code:
import sys
from operator import itemgetter
sys.setrecursionlimit(10**9)
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))

a = [[a[i], i] for i in range(n)]
a.sort()
b.sort()

for i in range(n):
    if a[i][0] > b[i]:
        print('No')
        sys.exit()

c = 0
num = a[0][1]
while c < n and num != 0:
    num = a[num][1]
    c += 1
if num == 0:
    print('Yes')
    sys.exit()

for i in range(1, n):
    if a[i][0] <= b[i-1]:
        print('Yes')
        sys.exit()
print('No')

Submission status: Wrong Answer

Solution code:
import sys
from operator import itemgetter
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))

a = [[a[i], b[i]] for i in range(n)]
a.sort(key=itemgetter(1))
a = [[a[i][0], a[i][1], i] for i in range(n)]
b.sort()
a.sort(key=itemgetter(0))

for i in range(n):
    if a[i][0] > b[i]:
        print('No')
        sys.exit()
c = 0
num = a[0][2]
while c < n-1 and num != 0:
    num = a[num][2]
    c += 1
if num == 0:
    print('Yes')
    sys.exit()

for i in range(1, n):
    if a[i] <= b[i-1]:
        print('Yes')
        sys.exit()
print('No')

Submission status: Wrong Answer

Solution code:
def main():
    n = int(input())
    a = list(map(int, input().split()))
    b = list(map(int, input().split()))
    ab = sorted([[a[i], b[i]] for i in range(n)], key=lambda x: x[1])

    num=1
    while num < n:
        num *= 2
    num-=1
    inf=10**9+1

    m=num+n
    segtree=[inf]*m
    for i in range(num,m):
        segtree[i] = ab[i - num][0]
    for i in range(num-1,-1,-1):
        j=2*i+1
        if j>=m:
            segtree[i]=inf
        elif j+1>=m:
            segtree[i]=segtree[j]
        else:
            segtree[i] = min(segtree[j], segtree[j + 1])
    print(segtree)
    #探す
    def search(i, s):
        if i >= num:
            return i - num
        k = 2 * i + 1
        if k+2<=m:
            if segtree[k+1] <= s:
                return search(k+1, s)
        if 2*i+2<=m:
            if segtree[k] <= s:
                return search(k, s)
        return -1
    
    #更新
    def update_good(i, s):
        if segtree[i] > s:
            segtree[i] = s
            update_good((i - 1) // 2, s)
    
    def update_bad(i):
        k=(i - 1) // 2
        if i % 2 == 1:
            if m > i + 1:
                temp=min(segtree[i+1],segtree[i])
                if segtree[k]<temp:
                    segtree[k] = temp
                    update_bad(k)
            else:
                segtree[k] = segtree[i]
                update_bad(k)
        else:
            if i != 0:
                temp=min(segtree[i-1],segtree[i])
                if segtree[k]<temp:
                    segtree[k] = temp
                    update_bad(k)

    cnt = 0
    for i in range(n):
        a,b=ab[i][0],ab[i][1]
        if a > b:
            t = search(0, b)
            if t <= i:
                print("No")
                return 0
            update_good(num + i, a)
            segtree[num + t] = a
            update_bad(num + t)
            ab[i][0], ab[t][0] = ab[t][0], a
            cnt+=1
    if cnt <= n - 2:
        print("Yes")
    else:
        print("No")
    
main()

Submission status: Wrong Answer

Solution code:
# coding: utf-8
import numpy as np


def solve(*args: str) -> str:
    n = int(args[0])
    A = np.array(list(map(int, args[1].split())))
    B = np.array(list(map(int, args[2].split())))

    sA = np.sort(A)
    sB = np.sort(B)

    ret = False

    if all(sA <= sB):
        nA = np.argsort(A)
        nB = np.argsort(B)
        P = dict(zip(nA, nB))

        count = 0
        x = P[0]
        while x != 0:
            x = P[x]
            count += 1

        ret = count < n-1

    return 'Yes' if ret else 'No'


if __name__ == "__main__":
    print(solve(*(open(0).read().splitlines())))

Submission status: Wrong Answer

Solution code:
def main():
    n = int(input())
    a = list(map(int, input().split()))
    b = list(map(int, input().split()))
    ab = sorted([[a[i], b[i]] for i in range(n)], key=lambda x: x[1])

    num=1
    while num < n - 1:
        num *= 2
        
    m=num+n
    segtree=[10**9+1]*m
    for i in range(num,m):
        segtree[i] = ab[i - num][0]
    for i in range(num-1,-1,-1):
        j=2*i+1
        if j>=m:
            segtree[i]=10**9+1
        elif j+1>=m:
            segtree[i]=segtree[j]
        else:
            segtree[i] = min(segtree[j], segtree[j + 1])

    #探す
    def search(i, s):
        if i >= num:
            return i - num
        k = 2 * i + 1
        if k+2<=m:
            if segtree[k+1] <= s:
                return search(k+1, s)
        if 2*i+2<=m:
            if segtree[k] <= s:
                return search(k, s)
        return -1
    
    #更新
    def update_good(i, s):
        if segtree[i] > s:
            segtree[i] = s
            update_good((i - 1) // 2, s)
    
    def update_bad(i):
        k=(i - 1) // 2
        if i % 2 == 1:
            if m > i + 1:
                temp=min(segtree[i+1],segtree[i])
                if segtree[k]<temp:
                    segtree[k] = temp
                    update_bad(k)
            else:
                segtree[k] = segtree[i]
                update_bad(k)
        else:
            if i != 0:
                temp=min(segtree[i-1],segtree[i])
                if segtree[k]<temp:
                    segtree[k] = temp
                    update_bad(k)

    cnt = 0
    for i in range(n):
        a,b=ab[i][0],ab[i][1]
        if a > b:
            t = search(0, b)
            if t <= i:
                print("No")
                return 0
            update_good(num + i, a)
            segtree[num + t] = a
            update_bad(num + t)
            ab[i][0], ab[t][0] = ab[t][0], a
            cnt+=1
    if cnt <= n - 2:
        print("Yes")
    else:
        print("No")
    
main()