fork download
  1. #include<stdio.h>
  2.  
  3. typedef long long LL;
  4. LL node[1000001 * 3];
  5.  
  6. LL update(int target, int value, int _idx, int L, int R)
  7. {
  8. if (target<L || target>R) return node[_idx];
  9. if (L == R) return node[_idx] = value;
  10. int mid = (L + R) / 2;
  11. return node[_idx] = update(target, value, _idx * 2, L, mid) +
  12. update(target, value, _idx * 2 + 1, mid + 1, R);
  13. }
  14.  
  15. LL sum(int s_L, int s_R, int _idx, int L, int R)
  16. {
  17. if (s_L > R || s_R < L) return 0;
  18. if (s_L <= L && R <= s_R) return node[_idx];
  19. int mid = (L + R) / 2;
  20. return sum(s_L, s_R, _idx * 2, L, mid) +
  21. sum(s_L, s_R, _idx * 2 + 1, mid + 1, R);
  22. }
  23.  
  24. int main(void)
  25. {
  26. int N, M, K, T;
  27. scanf("%d %d %d", &N, &M, &K);
  28. for (int i = 1; i <= N; i++) {
  29. scanf("%d", &T);
  30. update(i, T, 1, 1, N);
  31. }
  32.  
  33. int n1, n2;
  34. for (int i = 0; i < M + K; i++) {
  35. scanf("%d %d %d", &T, &n1, &n2);
  36. if (T == 2) printf("%lld\n", sum(n1, n2, 1, 1, N));
  37. else update(n1, n2, 1, 1, N);
  38. }
  39. }
Success #stdin #stdout 0s 4256KB
stdin
2 1 1

1

2

1 2 11111111111

2 1 2
stdout
-1773790776