結果

問題 No.2710 How many more?
ユーザー macchamaccha
提出日時 2024-03-31 15:25:07
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 1,247 ms / 2,000 ms
コード長 766 bytes
コンパイル時間 274 ms
コンパイル使用メモリ 11,904 KB
実行使用メモリ 62,288 KB
最終ジャッジ日時 2024-04-07 17:00:33
合計ジャッジ時間 14,787 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 28 ms
9,984 KB
testcase_01 AC 28 ms
9,984 KB
testcase_02 AC 949 ms
39,900 KB
testcase_03 AC 610 ms
41,432 KB
testcase_04 AC 589 ms
59,604 KB
testcase_05 AC 365 ms
34,744 KB
testcase_06 AC 461 ms
48,788 KB
testcase_07 AC 373 ms
12,972 KB
testcase_08 AC 309 ms
20,260 KB
testcase_09 AC 846 ms
47,008 KB
testcase_10 AC 475 ms
29,652 KB
testcase_11 AC 734 ms
26,460 KB
testcase_12 AC 1,145 ms
58,536 KB
testcase_13 AC 1,246 ms
62,288 KB
testcase_14 AC 1,196 ms
62,288 KB
testcase_15 AC 1,179 ms
62,288 KB
testcase_16 AC 1,184 ms
62,288 KB
testcase_17 AC 1,247 ms
62,288 KB
testcase_18 AC 29 ms
9,984 KB
権限があれば一括ダウンロードができます

ソースコード

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