Queries to count points lying on or inside an isosceles Triangle with given length of equal sides | Python3 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
MAX = 10 ** 6 + 5 NEW_LINE from math import ceil NEW_LINE def query ( arr , Q ) : NEW_LINE INDENT pre = [ 0 ] * ( MAX ) NEW_LINE for i in range ( len ( arr ) ) : NEW_LINE INDENT if ( arr [ i ] [ 0 ] < 0 or arr [ i ] [ 1 ] < 0 ) : NEW_LINE INDENT continue NEW_LINE DEDENT sum = ceil ( ( arr [ i ] [ 0 ] + arr [ i ] [ 1 ] ) ) ; NEW_LINE pre [ sum ] += 1 NEW_LINE DEDENT for i in range ( 1 , MAX ) : NEW_LINE INDENT pre [ i ] += pre [ i - 1 ] NEW_LINE DEDENT for i in range ( len ( Q ) ) : NEW_LINE INDENT print ( pre [ Q [ i ] ] , end = " ▁ " ) NEW_LINE DEDENT DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT arr = [ [ 2.1 , 3.0 ] , [ 3.7 , 1.2 ] , [ 1.5 , 6.5 ] , [ 1.2 , 0.0 ] ] NEW_LINE Q = [ 2 , 8 , 5 ] NEW_LINE N = len ( arr ) NEW_LINE M = len ( Q ) NEW_LINE query ( arr , Q ) NEW_LINE DEDENT