Submission

Status:
[P][P][P][PP][PP][PP][PP][PP][PP][PP]

Score: 100

User: hmmm

Problemset: ตัดกระดาษ

Language: cpp

Time: 0.078 second

Submitted On: 2025-04-18 14:58:10

#include<bits/stdc++.h>
using namespace std;
const int N=1e5;
int mp2[N+5],mp[N+5];
// unordered_map<int,int> mp;
vector<int> p;


int main(){
	ios::sync_with_stdio(0); cin.tie(0);
  int l,w,n,m,q;
  cin >> l >> w >> n >> m >> q;
  int t,x;
  cin >> t;
  // p.push_back(t);
  if(t<=N) mp[t]++,p.push_back(t);
  for(int i=2;i<=n;i++){
    cin >> x;
    if(x-t<=N) mp[x-t]++,p.push_back(x-t);
    // p.push_back(x-t);
    t=x;
  }
  if(l-x<=N) mp[l-x]++,p.push_back(l-x);
  // p.push_back(n-t);
  t=0;
  sort(p.begin(),p.end());
  p.resize(unique(p.begin(),p.end())-p.begin());
  for(int i=1;i<=m;i++){
    cin >> x;
    for(auto e:p){
      if(1ll*(x-t)*e<=N) mp2[(x-t)*e]+=mp[e];
      else break;
    }
    t=x;
  }
  for(auto e:p){
    if(1ll*(w-x)*e<=N) mp2[(w-x)*e]+=mp[e];
    else break;
  }
  while(q--){
    cin >> x;
    cout << mp2[x] << "\n";
  }
}