#include #include #include #include #include #include #include #include #include #include #include #include #include #define debug_value(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << #x << "=" << x << endl; #define debug(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << x << endl; template inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; } template inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; } using namespace std; typedef long long ll; template vector> vec2d(int n, int m, T v){ return vector>(n, vector(m, v)); } template vector>> vec3d(int n, int m, int k, T v){ return vector>>(n, vector>(m, vector(k, v))); } template void print_vector(vector v, char delimiter=' '){ if(v.empty()) { cout << endl; return; } for(int i = 0; i+1 < v.size(); i++) cout << v[i] << delimiter; cout << v.back() << endl; } const int N = 100000; const int M = 500; int cnt[N+1]; int ans[N+1]; int sum[M+1][N+1000]; int main(){ ios::sync_with_stdio(false); cin.tie(0); cout << setprecision(10) << fixed; int n, m; cin >> n >> m; vector l(n), r(n), x(n), y(n); for(int i = 0; i < n; i++){ cin >> l[i] >> r[i] >> x[i] >> y[i]; } vector a(m); for(int i = 0; i < m; i++){ cin >> a[i]; cnt[a[i]]++; } for(int i = 0; i < n; i++){ if(x[i] >= M){ for(int p = 0; p*x[i]+y[i] <= r[i]; p++){ int s = p*x[i]+y[i]; if(s >= l[i]){ ans[s]++; } } }else{ if(l[i]%x[i] <= y[i]){ l[i] += (y[i]-(l[i]%x[i])); }else{ l[i] += (y[i]+x[i]-(l[i]%x[i])); } if(r[i]%x[i] < y[i]){ r[i] -= (r[i]%x[i])-(x[i]-y[i]); }else{ r[i] -= (r[i]%x[i])-y[i]; } if(l[i] > r[i]) continue; sum[x[i]][l[i]]++; sum[x[i]][r[i]+x[i]]--; } } for(int d = 1; d <= M; d++){ for(int x = d; x <= N; x++){ sum[d][x] += sum[d][x-d]; } } for(int aa: a){ int out = ans[aa]; for(int x = 1; x <= M; x++){ out += sum[x][aa]; } cout << out << endl; } }