Queries to count points lying on or inside an isosceles Triangle with given length of equal sides | Java 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
import java . util . * ; class GFG { static int MAX = ( int ) ( 1e6 + 5 ) ; static void query ( double [ ] [ ] arr , int [ ] Q ) { int pre [ ] = new int [ MAX ] ; for ( int i = 0 ; i < arr . length ; i ++ ) { if ( arr [ i ] [ 0 ] < 0 arr [ i ] [ 1 ] < 0 ) continue ; int sum = ( int ) Math . 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 . length ; i ++ ) { System . out . print ( pre [ Q [ i ] ] + " ▁ " ) ; } System . out . println ( ) ; } public static void main ( String [ ] args ) { double [ ] [ ] arr = { { 2.1 , 3.0 } , { 3.7 , 1.2 } , { 1.5 , 6.5 } , { 1.2 , 0.0 } } ; int [ ] Q = { 2 , 8 , 5 } ; int N = arr . length ; int M = Q . length ; query ( arr , Q ) ; } }