Queries to count points lying on or inside an isosceles Triangle with given length of equal sides | C ++ implementation of above approach ; Function to find answer of each query ; Stores the count of points with sum less than or equal to their indices ; Traverse the array ; If both x and y - coordinate < 0 ; Stores the sum of co - ordinates ; Increment count of sum by 1 ; Prefix array ; Perform queries ; Drivers Code
#include <bits/stdc++.h> NEW_LINE using namespace std ; int const MAX = 1e6 + 5 ; int query ( vector < vector < float > > arr , vector < int > Q ) { int pre [ MAX ] = { 0 } ; for ( int i = 0 ; i < arr . size ( ) ; i ++ ) { if ( arr [ i ] [ 0 ] < 0 arr [ i ] [ 1 ] < 0 ) continue ; int sum = ceil ( ( arr [ i ] [ 0 ] + arr [ i ] [ 1 ] ) ) ; pre [ sum ] ++ ; } for ( int i = 1 ; i < MAX ; i ++ ) pre [ i ] += pre [ i - 1 ] ; for ( int i = 0 ; i < Q . size ( ) ; i ++ ) { cout << pre [ Q [ i ] ] << " ▁ " ; } cout << endl ; } int main ( ) { vector < vector < float > > arr = { { 2.1 , 3.0 } , { 3.7 , 1.2 } , { 1.5 , 6.5 } , { 1.2 , 0.0 } } ; vector < int > Q = { 2 , 8 , 5 } ; int N = arr . size ( ) ; int M = Q . size ( ) ; query ( arr , Q ) ; }