結果

問題 No.2359 A in S ?
ユーザー mkawa2
提出日時 2023-06-23 22:24:09
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 1,587 bytes
コンパイル時間 155 ms
コンパイル使用メモリ 82,056 KB
実行使用メモリ 116,668 KB
最終ジャッジ日時 2024-07-01 02:07:38
合計ジャッジ時間 16,202 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 17 TLE * 1
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys

# sys.setrecursionlimit(200005)
# sys.set_int_max_str_digits(1000005)
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 << 63)-1
md = 10**9+7
# md = 998244353

from heapq import *
from collections import defaultdict, Counter

mx = 100000
sq = 316

n, m = LI()
lrxy = LLI(n)
aa = LI()

ja = sorted(enumerate(aa), key=lambda x: x[1])
lrxy.sort(key=lambda x: -x[0])

ans = [0]*m
xtoy = defaultdict(Counter)
cnt = [0]*(mx+1)
hp = []
for j, a in ja:
    while lrxy and lrxy[-1][0] <= a:
        l, r, x, y = lrxy.pop()
        if x < sq:
            xtoy[x][y] += 1
        else:
            for i in range(y, mx+1, x): cnt[i] += 1
        heappush(hp, (r, x, y))
    while hp and hp[0][0] < a:
        r, x, y = heappop(hp)
        if x < sq:
            xtoy[x][y] -= 1
            if xtoy[x][y] == 0: del xtoy[x][y]
        else:
            for i in range(y, mx+1, x): cnt[i] -= 1

    ans[j] = cnt[a]
    for x in xtoy:
        b = a%x
        if b in xtoy[x]: ans[j] += xtoy[x][b]

print(*ans,sep="\n")
0