結果

問題 No.2359 A in S ?
ユーザー titiatitia
提出日時 2023-06-24 00:27:35
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,620 ms / 2,000 ms
コード長 913 bytes
コンパイル時間 744 ms
コンパイル使用メモリ 87,100 KB
実行使用メモリ 215,908 KB
最終ジャッジ日時 2023-09-13 19:38:24
合計ジャッジ時間 10,696 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 103 ms
78,220 KB
testcase_01 AC 103 ms
78,544 KB
testcase_02 AC 116 ms
79,136 KB
testcase_03 AC 106 ms
78,628 KB
testcase_04 AC 414 ms
124,964 KB
testcase_05 AC 393 ms
109,224 KB
testcase_06 AC 424 ms
125,076 KB
testcase_07 AC 218 ms
106,320 KB
testcase_08 AC 1,620 ms
215,908 KB
testcase_09 AC 330 ms
134,288 KB
testcase_10 AC 356 ms
118,116 KB
testcase_11 AC 381 ms
117,380 KB
testcase_12 AC 405 ms
123,108 KB
testcase_13 AC 393 ms
129,340 KB
testcase_14 AC 423 ms
125,080 KB
testcase_15 AC 330 ms
131,816 KB
testcase_16 AC 486 ms
123,692 KB
testcase_17 AC 456 ms
131,532 KB
testcase_18 AC 471 ms
131,048 KB
testcase_19 AC 476 ms
127,520 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = sys.stdin.readline

from collections import deque
from operator import itemgetter

N,M=map(int,input().split())
LRXY=[list(map(int,input().split())) for i in range(N)]
A=list(map(int,input().split()))

ANS=[0]*(10**5+1)

LIST=[[] for i in range(10**5+1)]

for l,r,x,y in LRXY:
    a=l//x*x+y-x

    while a<l:
        a+=x

    b=r//x*x+y-x

    while b<=r:
        b+=x

    if a<b:
        LIST[x].append([a,1])
        LIST[x].append([b,-1])

for x in range(10**5+1):
    if LIST[x]==[]:
        continue

    LIST[x].sort(key=itemgetter(0))

    Q=deque()

    for ind,com in LIST[x]:
        
        while Q and Q[0][0]<ind:
            a,b=Q.popleft()
            if b!=0:
                ANS[a]+=b
                Q.append([a+x,b])

        if Q and ind==Q[0][0]:
            Q[0][1]+=com
        else:
            Q.appendleft([ind,com])

for a in A:
    print(ANS[a])
        

    

0