結果

問題 No.1201 お菓子配り-4
ユーザー 草苺奶昔
提出日時 2023-02-15 21:28:02
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 1,075 bytes
コンパイル時間 156 ms
コンパイル使用メモリ 82,304 KB
実行使用メモリ 77,220 KB
最終ジャッジ日時 2024-07-18 04:46:41
合計ジャッジ時間 41,643 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 28 TLE * 3 -- * 5
権限があれば一括ダウンロードができます

ソースコード

diff #

from math import ceil


def floor_sum_of_linear(L: int, R: int, a: int, b: int, mod: int) -> int:
    """
    ```
    sum((x * a + b) // mod for x in range(L, R))
    ```
    """
    if L >= R:
        return 0
    res = 0
    b += L * a
    n = R - L

    if b < 0:
        k = ceil(-b / mod)
        b += k * mod
        res -= n * k

    while n:
        q, a = a // mod, a % mod
        res = res + n * (n - 1) // 2 * q
        res %= 1 << 128
        if b >= mod:
            q, b = b // mod, b % mod
            res = res + n * q
            res %= 1 << 128
        n, b = (a * n + b) // mod, (a * n + b) % mod
        a, mod = mod, a

    return res


if __name__ == "__main__":
    import sys

    sys.setrecursionlimit(int(1e9))
    input = lambda: sys.stdin.readline().rstrip("\r\n")

    N = int(input())
    M = int(input())
    A = list(map(int, input().split()))
    B = list(map(int, input().split()))
    ans = 0
    for a in A:
        for b in B:
            ans += floor_sum_of_linear(1, b + 1, a, 0, b)
    ans *= 2
    ans %= int(1e9 + 7)
    print(ans)
0