結果

問題 No.2710 How many more?
ユーザー maccha
提出日時 2024-03-31 15:25:07
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
AC  
実行時間 1,414 ms / 2,000 ms
コード長 766 bytes
コンパイル時間 147 ms
コンパイル使用メモリ 12,672 KB
実行使用メモリ 62,864 KB
最終ジャッジ日時 2024-10-01 04:35:12
合計ジャッジ時間 16,040 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 17
権限があれば一括ダウンロードができます

ソースコード

diff #

a,b=map(int,input().split())
x=list(map(int,input().split()))
z=sorted(list(set(x)))
w=[set([]) for i in range(len(z))]
W=[[] for i in range(len(z))]
p={}
d=[0 for i in range(a)]
for i in range(len(z)):
    p[z[i]]=i
s=0 
for i in range(a):
    w[p[x[i]]].add(i)
    d[i]=p[x[i]]
for i in range(len(w)):
    s+=len(w[i])
    W[i]=s
#print(x)
#print(z)
#print(p)
#print("集団",w)
#print(W)
#print("どこの集団であるか",d)
for i in range(b):
    c=list(map(int,input().split()))
    c[0]-=1;c[1]-=1
    #print(d[c[0]],d[c[1]])
    if abs(d[c[0]]-d[c[1]])==1:
        print(0)
    else:
        if len(w[d[c[0]]])>1:
            print(max(W[d[c[0]]]-W[d[c[1]]]-(len(w[d[c[0]]])),0))
        else:
            print(max(W[d[c[0]]]-W[d[c[1]]]-1,0))
    #print()
0