結果

問題 No.2931 Shibuya 109
ユーザー urunea
提出日時 2026-11-12 02:21:00
言語 PyPy3
(8.0.1 + ACL)
コンパイル:
pypy3 -mpy_compile _filename_
実行:
pypy3 _filename_
結果
AC  
実行時間 471 ms / 4,000 ms
+ 341µs
コード長 894 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 83 ms
コンパイル使用メモリ 64,496 KB
実行使用メモリ 135,064 KB
最終ジャッジ日時 2026-11-12 02:21:21
合計ジャッジ時間 8,966 ms
ジャッジサーバーID
(参考情報)
judge1_0 / judge2_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 11
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

from itertools import accumulate

N, Q = (int(x) for x in input().split())
A = list(map(int, input().split()))
L1_num, L1_cnt, L9 = [], [], []
for num, i in enumerate(A):
    if i == 1:
        L1_num.append(N-num-1)
        L1_cnt.append(1)
        L9.append(0)
    elif i == 9:
        L1_num.append(0)
        L1_cnt.append(0)
        L9.append(1)
    else:
        L1_num.append(0)
        L1_cnt.append(0)
        L9.append(0)
L1_num, L1_cnt, L9 = list(accumulate(L1_num)), list(accumulate(L1_cnt)), list(accumulate(L9))
ans = []
for _ in range(Q):
    l, r = (int(x) for x in input().split())
    l, r = l-1, r-1
    res = 0
    if l == 0:
        res += L9[r]
    else:
        res += L9[r]-L9[l-1]
    if l == 0:
        res += L1_num[r] - L1_cnt[r]*(N-r-1)
    else:
        res += L1_num[r]-L1_num[l-1] - (L1_cnt[r]-L1_cnt[l-1])*(N-r-1)
    ans.append(res)

for i in ans:
    print(i)
0