結果

問題 No.2359 A in S ?
ユーザー lam6er
提出日時 2025-04-15 21:07:32
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,312 bytes
コンパイル時間 274 ms
コンパイル使用メモリ 82,644 KB
実行使用メモリ 138,576 KB
最終ジャッジ日時 2025-04-15 21:13:27
合計ジャッジ時間 4,472 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 1 WA * 1 TLE * 1 -- * 15
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
from collections import defaultdict

def main():
    input = sys.stdin.read().split()
    ptr = 0
    N = int(input[ptr])
    ptr += 1
    M = int(input[ptr])
    ptr += 1

    B = int(10**5 ** 0.5)  # Approximately 316

    small_groups = defaultdict(list)
    large_groups = defaultdict(list)

    for _ in range(N):
        L = int(input[ptr])
        ptr += 1
        R = int(input[ptr])
        ptr += 1
        X = int(input[ptr])
        ptr += 1
        Y = int(input[ptr])
        ptr += 1
        if X <= B:
            key = (X, Y)
            small_groups[key].append((L, R))
        else:
            key = Y
            large_groups[key].append((X, L, R))

    A = list(map(int, input[ptr:ptr+M]))
    ptr += M

    for a in A:
        count = 0
        # Check small X groups
        for X in range(1, B + 1):
            Y_val = a % X
            key = (X, Y_val)
            if key in small_groups:
                for (L, R) in small_groups[key]:
                    if L <= a <= R:
                        count += 1
        # Check large X groups
        Y_val = a
        if Y_val in large_groups:
            for (X, L, R) in large_groups[Y_val]:
                if X > B and L <= a <= R:
                    count += 1
        print(count)

if __name__ == "__main__":
    main()
0