Pagini recente » Cod sursa (job #2955006) | Cod sursa (job #391273) | Cod sursa (job #1843252) | Cod sursa (job #2952248) | Cod sursa (job #1938728)
#include <bits/stdc++.h>
using namespace std;
fstream in ( "grendizer.in" , ios::in );
fstream out( "grendizer.out", ios::out );
const int DIM = 1e5 + 5;
pair<int, int> pts1[DIM], pts2[DIM];
int main( void ) {
ios::sync_with_stdio( false );
int n, m;
in >> n >> m;
for( int i = 1; i <= n; i ++ ) {
int x, y;
in >> x >> y;
pts1[i] = make_pair( x - y, y );
pts2[i] = make_pair( x + y, y );
}
sort( pts1 + 1, pts1 + n + 1 );
sort( pts2 + 1, pts2 + n + 1 );
for( int i = 1; i <= m; i ++ ) {
int x, y, z, ans = 0;
in >> x >> y >> z;
ans += lower_bound( pts1 + 1, pts1 + n + 1, make_pair( x - y - z, y + z ) ) -
lower_bound( pts1 + 1, pts1 + n + 1, make_pair( x - y - z, y ) );
ans += upper_bound( pts1 + 1, pts1 + n + 1, make_pair( x - y + z, y ) ) -
upper_bound( pts1 + 1, pts1 + n + 1, make_pair( x - y + z, y - z ) );
ans += lower_bound( pts2 + 1, pts2 + n + 1, make_pair( x + y - z, y ) ) -
lower_bound( pts2 + 1, pts2 + n + 1, make_pair( x + y - z, y - z ) );
ans += upper_bound( pts2 + 1, pts2 + n + 1, make_pair( x + y + z, y + z ) ) -
upper_bound( pts2 + 1, pts2 + n + 1, make_pair( x + y + z, y ) );
out << ans << "\n";
}
return 0;
}