fork download
  1. import math
  2. def ip():
  3. return map(int,input().split())
  4.  
  5. T=int(input())
  6. # T=1
  7. for __ in range(T):
  8. input()
  9. n,k=ip()
  10. a=list(ip())
  11. t=list(ip())
  12. a=[i-1 for i in a]
  13. lst=[]
  14.  
  15. for i in range(k):
  16. lst.append((a[i],t[i]))
  17. lst.sort()
  18. tmp=[float('inf') for i in range(n)]
  19.  
  20. j=0
  21. ct=0
  22. for i in range(lst[0][0],n):
  23. if i==lst[0][0]:
  24. ct=lst[0][1]
  25. tmp[i]=ct
  26. ct+=1
  27. continue
  28. if j+1<k and i==lst[j+1][0]:
  29. j+=1
  30. ct=min(ct+1,lst[j][1])
  31. tmp[i]=ct
  32. ct+=1
  33. else:
  34. tmp[i]=ct
  35. ct+=1
  36.  
  37. j=k-1
  38. ct=0
  39. for i in range(lst[-1][0],-1,-1):
  40. if i==lst[-1][0]:
  41. ct=lst[-1][1]
  42. tmp[i]=ct
  43. ct+=1
  44. continue
  45. if j-1>=0 and i==lst[j-1][0]:
  46. j-=1
  47. ct=min(ct+1,lst[j][1])
  48. tmp[i]=min(tmp[i],ct)
  49. ct+=1
  50. else:
  51. tmp[i]=min(tmp[i],ct)
  52. ct+=1
  53.  
  54. # print("wfddsf")
  55. print(*tmp)
  56.  
  57.  
  58.  
  59.  
  60.  
  61.  
  62.  
  63.  
  64.  
Success #stdin #stdout 0.11s 14132KB
stdin
5

6 2
2 5
14 16

10 1
7
30

5 5
3 1 4 2 5
3 1 4 2 5

7 1
1
1000000000

6 3
6 1 3
5 5 5
stdout
15 14 15 16 16 17
36 35 34 33 32 31 30 31 32 33
1 2 3 4 5
1000000000 1000000001 1000000002 1000000003 1000000004 1000000005 1000000006
5 6 5 6 6 5