SHARE
TWEET

bum ass nigga

a guest Sep 22nd, 2019 78 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. count = 0
  2.  
  3. def do_damages(A, a=0, b= None):
  4.     global count        
  5.     if count == 0:
  6.         for n in range(len(A)):
  7.             A[n] = [A[n], 1, n] #[value, damage, index]
  8.             count += 1
  9.            
  10.     if b is None:
  11.         b = len(A)
  12.     if 1 < b - a:
  13.         c = (a + b + 1) // 2
  14.         do_damages(A,a,c)
  15.         do_damages(A,c,b)
  16.         #merge_sort(A,a,c)
  17.         #merge_sort(A,c,b)
  18.         L,R = A[a:c], A[c:b]
  19.         i, j = 0, 0
  20.         damage = 0
  21.  
  22.         if len(L) + len(R) <= 2:
  23.             if L[0][0] > R[0][0]:
  24.                 L[0][1] += 1
  25.                 A[a] = R[0]
  26.                 A[a+1] = L[0]
  27.         else:
  28.             while a < b:
  29.                 if (j >= len(R)) or (i < len(L) and L[i][0] <= R[j][0]):
  30.                     try:
  31.                         L[i+1][1] += damage
  32.                     except:
  33.                         pass
  34.                     A[a] = L[i]
  35.                     i = i + 1
  36.                 else:
  37.                     try:
  38.                         L[i][1] += 1
  39.                     except:
  40.                         pass
  41.                     damage += 1
  42.                     A[a] = R[j]
  43.                     j = j + 1
  44.                 a = a + 1
  45.             return A
  46.            
  47.  
  48. def get_damages(H):
  49.     '''
  50.    Input:  H | list of bricks per house from west to east
  51.    Output: D | list of damage per house from west to east
  52.    '''
  53.     h = do_damages(H)
  54.     damagedict = {}
  55.     damagelist = [0] * len(H)
  56.     for house in h:
  57.         damagedict[house[2]] = house[1]
  58.     for index in damagedict:
  59.         damagelist[index] = damagedict[index]
  60.     return damagelist
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top