## https://yukicoder.me/problems/no/2359 import math def main(): N, M = map(int, input().split()) lrxy = [] for _ in range(N): l, r, x, y = map(int, input().split()) lrxy.append((l,r,x,y)) A = list(map(int, input().split())) # イベント in_events = {} out_events = {} max_r = 0 for i in range(N): l, r, x, y = lrxy[i] if l not in in_events: in_events[l] = [] in_events[l].append((i, x, y)) if r not in out_events: out_events[r] = [] out_events[r].append((i, x, y)) max_r = max(r, max_r) sqrt_max_r = int(math.sqrt(max_r)) counts_map = [[0] * max(1, x) for x in range(sqrt_max_r + 1)] all_map = [0] * (max_r + 1) answer_map = {} for j in range(M): if A[j] not in answer_map: answer_map[A[j]] = [] answer_map[A[j]].append(j) answers = [0] * M for i in range(1, max_r + 1): if i in in_events: for _, x, y in in_events[i]: if x <= sqrt_max_r: counts_map[x][y] += 1 else: z = y while z <= max_r: all_map[z] += 1 z += x if i in answer_map: ans = all_map[i] for z in range(1, sqrt_max_r + 1): ans += counts_map[z][i % z] for j in answer_map[i]: answers[j] = ans if i in out_events: for _, x, y in out_events[i]: if x <= sqrt_max_r: counts_map[x][y] -= 1 else: z = y while z <= max_r: all_map[z] -= 1 z += x for j in range(M): print(answers[j]) if __name__ == "__main__": main()