#include #define THR 100 int main() { int i, N, M, L[100001], R[100001], X[100001], Y[100001], A[100001]; scanf("%d %d", &N, &M); for (i = 1; i <= N; i++) scanf("%d %d %d %d", &(L[i]), &(R[i]), &(X[i]), &(Y[i])); for (i = 1; i <= M; i++) scanf("%d", &(A[i])); int j, ans[100001] = {}; static int imos[THR + 1][100001] = {}, tmp[THR + 1]; for (i = 1; i <= N; i++) { if (X[i] > THR) { for (j = (L[i] - Y[i] + X[i] - 1) / X[i] * X[i] + Y[i]; j <= R[i]; j += X[i]) ans[j]++; } else { j = (L[i] - Y[i] + X[i] - 1) / X[i] * X[i] + Y[i]; imos[X[i]][j]++; j = (R[i] - Y[i] + X[i]) / X[i] * X[i] + Y[i]; if (j <= 100000) imos[X[i]][j]--; } } for (i = 1; i <= THR; i++) { for (j = 0; j < i; j++) tmp[j] = 0; for (j = 1; j <= 100000; j++) { tmp[j%i] += imos[i][j]; ans[j] += tmp[j%i]; } } for (i = 1; i <= M; i++) printf("%d\n", ans[A[i]]); fflush(stdout); return 0; }