結果

問題 No.2581 [Cherry Anniversary 3] 28輪の桜のブーケ
ユーザー mkawa2mkawa2
提出日時 2023-12-09 02:02:31
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,524 ms / 3,000 ms
コード長 1,636 bytes
コンパイル時間 182 ms
コンパイル使用メモリ 81,700 KB
実行使用メモリ 79,340 KB
最終ジャッジ日時 2023-12-09 02:02:57
合計ジャッジ時間 23,649 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 107 ms
76,804 KB
testcase_01 AC 127 ms
77,844 KB
testcase_02 AC 185 ms
78,456 KB
testcase_03 AC 635 ms
78,512 KB
testcase_04 AC 459 ms
78,108 KB
testcase_05 AC 177 ms
78,504 KB
testcase_06 AC 566 ms
78,500 KB
testcase_07 AC 599 ms
78,232 KB
testcase_08 AC 220 ms
78,072 KB
testcase_09 AC 403 ms
77,496 KB
testcase_10 AC 534 ms
77,472 KB
testcase_11 AC 216 ms
78,600 KB
testcase_12 AC 736 ms
78,400 KB
testcase_13 AC 733 ms
78,256 KB
testcase_14 AC 640 ms
76,948 KB
testcase_15 AC 732 ms
78,628 KB
testcase_16 AC 742 ms
77,668 KB
testcase_17 AC 635 ms
78,396 KB
testcase_18 AC 754 ms
77,460 KB
testcase_19 AC 752 ms
78,400 KB
testcase_20 AC 872 ms
78,472 KB
testcase_21 AC 767 ms
77,600 KB
testcase_22 AC 1,473 ms
78,096 KB
testcase_23 AC 1,499 ms
77,932 KB
testcase_24 AC 1,504 ms
78,352 KB
testcase_25 AC 1,316 ms
78,500 KB
testcase_26 AC 1,524 ms
77,924 KB
testcase_27 AC 59 ms
66,268 KB
testcase_28 AC 184 ms
77,416 KB
testcase_29 AC 1,398 ms
79,340 KB
testcase_30 AC 798 ms
77,404 KB
testcase_31 AC 698 ms
78,660 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys

# sys.setrecursionlimit(1000005)
# sys.set_int_max_str_digits(200005)
int1 = lambda x: int(x)-1
pDB = lambda *x: print(*x, end="\n", file=sys.stderr)
p2D = lambda x: print(*x, sep="\n", end="\n\n", file=sys.stderr)
def II(): return int(sys.stdin.readline())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def LI1(): return list(map(int1, sys.stdin.readline().split()))
def LLI1(rows_number): return [LI1() for _ in range(rows_number)]
def SI(): return sys.stdin.readline().rstrip()

dij = [(0, 1), (-1, 0), (0, -1), (1, 0)]
# dij = [(0, 1), (-1, 0), (0, -1), (1, 0), (1, 1), (1, -1), (-1, 1), (-1, -1)]
# inf = -1-(-1 << 31)
inf = -1-(-1 << 63)
# md = 10**9+7
md = 998244353

from bisect import bisect_left
from collections import defaultdict
pc = [0]
for _ in range(14): pc += [c+1 for c in pc]

def f(si):
    res=defaultdict(list)
    dp=[0]*(1<<14)
    dp[0]=sum(hh[si:si+14])%m
    res[0].append(dp[0])
    for s in range(1,1<<14):
        j=(s&-s).bit_length()-1
        dp[s]=(dp[s^1<<j]-hh[si+j]+gg[si+j])%m
        res[pc[s]].append(dp[s])
    return res

m=II()
gg=LI()
hh=LI()

pre=f(0)
pos=f(14)

for p in range(14):
    pre[p].sort()
    pos[p].sort()

for _ in range(II()):
    k,x=LI()
    ans=0
    for p in range(k+1):
        q=k-p
        for s in pre[p]:
            # x-s<=t<m-s
            l=bisect_left(pos[q],x-s)
            r=bisect_left(pos[q],m-s)
            ans+=r-l
            # x+m-s<=t<2m-s
            l=bisect_left(pos[q],x+m-s)
            r=bisect_left(pos[q],m+m-s)
            ans+=r-l

    print(ans)



0