結果

問題 No.2961 Shiny Monster Master
ユーザー のーと
提出日時 2024-11-16 15:54:51
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 698 bytes
コンパイル時間 681 ms
コンパイル使用メモリ 82,304 KB
実行使用メモリ 216,440 KB
最終ジャッジ日時 2024-11-16 15:56:01
合計ジャッジ時間 52,060 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 54 WA * 13 TLE * 10
権限があれば一括ダウンロードができます

ソースコード

diff #

R,N=map(int,input().split())
A=set(list(map(int,input().split())))
B=[0]*R
for a in A:
	B[a]=1
A=B

#print(A)

Q=int(input())
from itertools import accumulate
S=list(accumulate(A)) #あるリストAの累積和リスト #S[i]=A[0]+A[1]+...+A[i]
def add(S,l,r):#累積和Sに対して a[l]+...+a[r] を返す(半開区間にしたほうがいいのか...?)
  if l==0:
    return S[r]
  else:
    return S[r]-S[l-1]
 
#print(S)
    
def f1(a,b):#a以下で最大のbの倍数
  return (a//b)*b

def g1(a,b):
  return ((a+b-1)//b)*b


for i in range(Q):
	l,r=map(int,input().split())
	g=g1(l,R)
	f=f1(r,R)
	if f<g:
		print(add(S,l%R,r%R))
		continue
	print(add(S,l%R,R-1)+add(S,0,r%R)+sum(A)*(f-g)//R)
0