Iam_Sandeep

no of pairs x^y greater than y^x

Nov 13th, 2021
1,288
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.57 KB | None | 0 0
  1. link="https://practice.geeksforgeeks.org/problems/number-of-pairs-1587115620/1#"
  2. def countPairs(self,a,b,M,N):
  3.         d=[0]*5
  4.         for i in b:
  5.             if i<5:d[i]+=1
  6.         b=sorted(b)
  7.         ans=0
  8.         for i in a:
  9.             if i==0:continue
  10.             elif i==1:ans+=(d[0])
  11.             else:
  12.                 idx=bisect.bisect_right(b,i)
  13.                 ans+=(len(b)-idx)
  14.                 ans+=(d[0]+d[1])
  15.                 if i==2:
  16.                     ans-=(d[3]+d[4])
  17.                 elif i==3 :
  18.                     ans+=(d[2])
  19.         return ans
  20.    
Advertisement
Add Comment
Please, Sign In to add comment