Pagini recente » Cod sursa (job #855090) | Cod sursa (job #796083) | Cod sursa (job #217806) | Cod sursa (job #2871392) | Cod sursa (job #2900909)
#include <fstream>
#include <algorithm>
using namespace std;
ifstream in("ograzi.in");
ofstream out("ograzi.out");
const int nmax=50000;
int n,m,w,h,x,y,sol=0;
pair<int,int>v[nmax+3],v1[nmax+3];
int binxl(int st,int dr,int x) {
int mid,last=-1;
while(st<=dr) {
mid=(st+dr)/2;
if(v[mid].first>=x) {
last=mid;
dr=mid-1;
} else if(v[mid].first<x)
st=mid+1;
}
return last;
}
int binyl(int st,int dr,int x) {
int mid,last=-1;
while(st<=dr) {
mid=(st+dr)/2;
if(v1[mid].first>=x) {
last=mid;
dr=mid-1;
} else if(v1[mid].first<x)
st=mid+1;
}
return last;
}
void query(int x,int y) {
int lx=binxl(0,n,x+1),ly=binyl(0,n,y+1);
lx--;
ly--;
if(v[lx].first<=x&&v[lx].first+w>=x&&v[lx].second<=y&&v[lx].second+h>=y){
sol++;
return;
}
if(v1[ly].first<=y&&v1[ly].first+h>=y&&v1[ly].second<=x&&v1[ly].second+w>=x)
sol++;
}
int main() {
in>>n>>m>>w>>h;
for(int i=1; i<=n; i++) {
in>>v[i].second>>v[i].first;
v1[i].first=v[i].second;
v1[i].second=v[i].first;
}
sort(v+1,v+n+1);
sort(v1+1,v1+n+1);
//for(int i=1; i<=n; i++)
//cerr<<v[i].first<<" "<<v[i].second<<", "<<v1[i].first<<" "<<v1[i].second<<'\n';
for(int i=1; i<=m; i++) {
in>>y>>x;
query(x,y);
}
out<<sol;
return 0;
}