fork download
  1. import math
  2. from functools import cmp_to_key, partial
  3.  
  4. def compare(a1,a2):
  5. # SORTING QUERIES
  6. global BLOCK_SIZE, data
  7. print(a1, a2)
  8. print(data[a1])
  9. if data[a1][0]//BLOCK_SIZE != data[a2][0]//BLOCK_SIZE:
  10. return data[a1][0]//BLOCK_SIZE < data[a2][0]//BLOCK_SIZE
  11.  
  12. return data[a1][1] < data[a2][1]
  13.  
  14. a = [1, 1, 2, 1, 3, 4, 5, 2, 8]
  15. BLOCK_SIZE = math.ceil(math.sqrt(len(a)))
  16. # QUERIES
  17. data = [(0, 4), (1, 3), (2, 4)]
  18. print(data)
  19. data.sort(key=lambda t: (t[0] // BLOCK_SIZE, t[1]))
  20. # res = sorted(data, key=cmp_to_key(compare))
  21. print(res)
  22. # print(data)
Runtime error #stdin #stdout #stderr 0.13s 23456KB
stdin
Standard input is empty
stdout
[(0, 4), (1, 3), (2, 4)]
stderr
Traceback (most recent call last):
  File "./prog.py", line 21, in <module>
NameError: name 'res' is not defined