fork download
  1. # your code goes here
  2. import sys
  3.  
  4. def solve():
  5. input = sys.stdin.read
  6. data = input().split()
  7.  
  8. if not data:
  9. return
  10.  
  11. N = int(data[0])
  12. numbers = [int(x) for x in data[1:N+1]]
  13.  
  14.  
  15. Q = int(data[N+1])
  16.  
  17.  
  18. pref = [0] * N
  19. pref[0] = numbers[0]
  20. for k in range(1, N):
  21. pref[k] = pref[k-1] + numbers[k]
  22.  
  23.  
  24. query_idx = N + 2
  25. output = []
  26.  
  27. for _ in range(Q):
  28. i = int(data[query_idx])
  29. j = int(data[query_idx+1])
  30. query_idx += 2
  31.  
  32. if i > j:
  33. i, j = j, i
  34.  
  35.  
  36. if i == 0:
  37. output.append(str(pref[j]))
  38. else:
  39. output.append(str(pref[j] - pref[i-1]))
  40.  
  41.  
  42. print('\n'.join(output) + '\n')
  43.  
  44. solve()
  45.  
Success #stdin #stdout 0.07s 14024KB
stdin
Standard input is empty
stdout
Standard output is empty