#include #include #include using namespace std; int main() { cin.tie(nullptr), ios::sync_with_stdio(false); constexpr int B = 300; int N, M; cin >> N >> M; vector>> events(201010); while (N--) { int l, r, x, y; cin >> l >> r >> x >> y; events.at(l).emplace_back(0, x, y); events.at(r + 1).emplace_back(2, x, y); } for (int m = 0; m < M; ++m) { int a; cin >> a; events.at(a).emplace_back(1, m, a); } vector cntlo(B, vector(B)); vector cnthi(101010); vector ret(M); for (const auto &vec : events) { for (auto [tp, x, y] : vec) { if (tp == 1) { ret.at(x) += cnthi.at(y); for (int b = 1; b < B; ++b) ret.at(x) += cntlo.at(b).at(y % b); } else { if (x >= B) { for (int i = y % x; i < int(cnthi.size()); i += x) { cnthi.at(i) += tp == 0 ? 1 : -1; } } else { cntlo.at(x).at(y) += tp == 0 ? 1 : -1; } } } } for (auto x : ret) cout << x << '\n'; }