# N<10**5だから毎回すべてをチェックすれば二重ループで間に合わない # 逆に各クエリから見て、適合するAiを探すのであればbisectも使えるのでどうか # bisectは数のリストに対してのみ使える、リストのリストには使えない N, M = map(int, input().split()) LRXY = [] for i in range(N): l, r, x, y = map(int, input().split()) LRXY.append((l, r, x, y)) A = list(map(int, input().split())) A_with_idx = [] for i in range(M): A_with_idx.append((A[i], i)) A_with_idx.sort() A_order = [] idx_order = [] for a, i in A_with_idx: idx_order.append(i) A_order.append(a) from bisect import * ans_count = [0]*M for l, r, x, y in LRXY: idx = bisect_left(A_order, l) while idx < M and A_order[idx] <= r: if A_order[idx]%x == y: ans_count[idx_order[idx]] += 1 idx += 1 #print(ans_count) for a in ans_count: print(a)