結果

問題 No.2359 A in S ?
ユーザー gew1fw
提出日時 2025-06-12 15:14:55
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 1,088 bytes
コンパイル時間 196 ms
コンパイル使用メモリ 82,424 KB
実行使用メモリ 141,468 KB
最終ジャッジ日時 2025-06-12 15:15:06
合計ジャッジ時間 4,239 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 2 TLE * 1 -- * 15
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys

def main():
    input = sys.stdin.read
    data = input().split()
    idx = 0
    N = int(data[idx])
    M = int(data[idx+1])
    idx += 2
    
    max_A = 10**5
    freq = [0] * (max_A + 1)
    
    for _ in range(N):
        L = int(data[idx])
        R = int(data[idx+1])
        X = int(data[idx+2])
        Y = int(data[idx+3])
        idx += 4
        
        if X == 0:
            continue
        
        a_start = Y
        while a_start < L:
            a_start += X
        
        if a_start > R:
            continue
        
        a_end = Y
        quotient = (R - Y) // X
        a_end = Y + quotient * X
        
        if a_end < a_start:
            continue
        
        k = 0
        current = a_start
        while current <= a_end and current <= max_A:
            if current >= L and current <= R:
                if current <= max_A:
                    freq[current] += 1
            current += X
    
    queries = list(map(int, data[idx:idx+M]))
    
    for A in queries:
        print(freq[A])
    
if __name__ == '__main__':
    main()
0