結果
| 問題 |
No.2961 Shiny Monster Master
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2024-11-18 02:38:10 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
AC
|
| 実行時間 | 207 ms / 1,777 ms |
| コード長 | 805 bytes |
| コンパイル時間 | 495 ms |
| コンパイル使用メモリ | 82,468 KB |
| 実行使用メモリ | 141,696 KB |
| 最終ジャッジ日時 | 2024-11-18 02:38:23 |
| 合計ジャッジ時間 | 13,107 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 77 |
ソースコード
R,N=map(int,input().split())
A=sorted(list(map(int,input().split())))
B=[0]*R
for a in A:
B[a]=1
#print(A)
Q=int(input())
from itertools import accumulate
S=list(accumulate(B)) #あるリスト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):#a以上で最小のbの倍数
return ((a+b-1)//b)*b
#SA=sum(A)
for i in range(Q):
l,r=map(int,input().split())
g=g1(l,R)
f=f1(r,R)
#print(f,g)
if g-f==R:#もしlとrが同一区間におさまるなら→
print(add(S,l%R,r%R))
else:
print(add(S,l%R,R-1)+add(S,0,r%R)+N*(r//R-l//R-1))