Cod sursa(job #1938728)

Utilizator StarGold2Emanuel Nrx StarGold2 Data 25 martie 2017 09:46:43
Problema Grendizer Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.35 kb
#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;
}