Cod sursa(job #503490)

Utilizator borsoszalanBorsos Zalan borsoszalan Data 23 noiembrie 2010 11:42:16
Problema Grendizer Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 1 kb
#include<stdio.h>
#include<algorithm>
using namespace std;
#define mp make_pair
#define fs first
#define sc second
#define pii pair<int,int>
#define N 100010
pii d1[N],d2[N];
int n,m;
inline void citire()
{
	scanf("%d%d",&n,&m);
	int x,y;
	for(int i=0; i<n; ++i)
	{
        	scanf("%d%d",&x,&y);
		d1[i]=mp(x+y,y);
		d2[i]=mp(x-y,y);
	}
	sort(d1,d1+n);
	sort(d2,d2+n);
}
int main()
{
	freopen("grendizer.in","r",stdin);
	freopen("grendizer.out","w",stdout);
        citire();
	int x,y,r;
	pii *it1,*it2;
	int rez;
	for(; m; --m)
	{
        	scanf("%d%d%d",&x,&y,&r);
		rez=0;
                
		it1=lower_bound(d1,d1+n,mp(x+y-r,y-r));
		it2=upper_bound(d1,d1+n,mp(x+y-r,y));
		rez+=it2-it1;

		it1=lower_bound(d1,d1+n,mp(x+y+r,y));
		it2=upper_bound(d1,d1+n,mp(x+y+r,y+r));
		rez+=it2-it1;

		it1=upper_bound(d2,d2+n,mp(x-y-r,y));
		it2=lower_bound(d2,d2+n,mp(x-y-r,y+r));
		rez+=it2-it1;

		it1=upper_bound(d2,d2+n,mp(x-y+r,y-r));
		it2=lower_bound(d2,d2+n,mp(x-y+r,y));
		rez+=it2-it1;

		printf("%d\n",rez);
	}
	return 0;
}