#include using namespace std; int gcd(int a, int b) { return (a ? gcd(a, b % a) : b); } int main () { int N, M; cin >> N >> M; std::vector> X; vector cnt1(100010, 0); const int H = 300; vector>>> cnt2(H, vector>>(H)); for (int i = 0; i < N; i ++) { int l, r, x, y; cin >> l >> r >> x >> y; if (x < H) { cnt2[x][y].emplace_back(l, 1); cnt2[x][y].emplace_back(r + 1, -1); } else { for (int j = 0; j * x + y <= r; j ++) { if (j * x + y >= l) cnt1[j * x + y] ++; } } } for (int i = 1; i < H; i ++) { for (int j = 0; j < i; j ++) { auto& a = cnt2[i][j]; a.emplace_back(-1, 0); sort(a.begin(), a.end()); for (int k = 1; k < a.size(); k ++) { a[k].second += a[k].second; } } } while (M --) { int a; cin >> a; int ans = cnt1[a]; for (int i = 1; i < H; i ++) { auto pt = lower_bound(cnt2[i][a % i].begin(), cnt2[i][a % i].end(), make_pair(a + 1, -1)); ans += prev(pt) -> second; } cout << ans << endl; } }