Submission
Status:
[P][P][P][PP][PP][PP][PP][PP][PP][PP]
Score: 100
User: hmmm
Problemset: ตัดกระดาษ
Language: cpp
Time: 0.096 second
Submitted On: 2025-04-18 14:38:00
#include<bits/stdc++.h>
using namespace std;
unordered_map<int,int> mp,mp2;
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);
mp[t]++;
for(int i=2;i<=n;i++){
cin >> x;
mp[x-t]++;
// p.push_back(x-t);
t=x;
}
mp[l-x]++;
// p.push_back(n-t);
cin >> t;
mp2[t]++;
for(int i=2;i<=m;i++){
cin >> x;
mp2[x-t]++;
t=x;
}
mp2[w-x]++;
while(q--){
cin >> x;
long long int ans=0;
int r=sqrt(x);
for(int i=1;i<=r;i++){
if(x%i==0){
ans+=mp[i]*mp2[x/i]+mp2[i]*mp[x/i];
}
}
if(r*r==x) ans-=mp2[r]*mp[x/r];
cout << ans << "\n";
}
}