█████████ ████ ███░░░░░███ ░░███ ███ ░░░ ██████ ███████ ██████ ██████ ░███ ███░░███ ███░░███ ███░░███ ███░░███ ░███ ░███ ░███░███ ░███ ░███████ ░███ ░███ ░░███ ███░███ ░███░███ ░███ ░███░░░ ░███ ░███ ░░█████████ ░░██████ ░░████████░░██████ ░░██████ ░░░░░░░░░ ░░░░░░ ░░░░░░░░ ░░░░░░ ░░░░░░

Envío 3818

Problema 0x25 - Suma de un subarreglo grande

  • Autor: bryancalisto
  • Fecha: 2021-04-17 14:03:58 UTC (Hace alrededor de 3 años)
Caso # Resultado Tiempo Memoria
#1
Error de compilación
                      main.c:18:3: warning: implicitly declaring library function 'scanf' with type 'int (const char *restrict, ...)' [-Wimplicit-function-declaration]
  scanf("%d*[^\n]", &N);
  ^
main.c:18:3: note: include the header <stdio.h> or explicitly provide a declaration for 'scanf'
main.c:20:16: warning: implicitly declaring library function 'malloc' with type 'void *(unsigned long)' [-Wimplicit-function-declaration]
  arr = (int *)malloc(sizeof(int) * N);
               ^
main.c:20:16: note: include the header <stdlib.h> or explicitly provide a declaration for 'malloc'
main.c:22:19: warning: implicit declaration of function 'fscanf' is invalid in C99 [-Wimplicit-function-declaration]
  while (i < N && fscanf(stdin, "%d", &arr[i++]) == 1)
                  ^
main.c:22:19: warning: declaration of built-in function 'fscanf' requires inclusion of the header <stdio.h> [-Wbuiltin-requires-header]
main.c:22:26: error: use of undeclared identifier 'stdin'
  while (i < N && fscanf(stdin, "%d", &arr[i++]) == 1)
                         ^
main.c:33:28: error: use of undeclared identifier 'stdin'
    while (j < 2 && fscanf(stdin, "%d", &consultas[i + i * 2 + j++]) == 1)
                           ^
main.c:44:5: warning: implicitly declaring library function 'printf' with type 'int (const char *, ...)' [-Wimplicit-function-declaration]
    printf("%d\n", sumarDesdeHasta(arr, consultas[i + i * 2], consultas[i + i * 2 + 1]));
    ^
main.c:44:5: note: include the header <stdio.h> or explicitly provide a declaration for 'printf'
5 warnings and 2 errors generated.

                    
#2
Error de compilación
                      main.c:18:3: warning: implicitly declaring library function 'scanf' with type 'int (const char *restrict, ...)' [-Wimplicit-function-declaration]
  scanf("%d*[^\n]", &N);
  ^
main.c:18:3: note: include the header <stdio.h> or explicitly provide a declaration for 'scanf'
main.c:20:16: warning: implicitly declaring library function 'malloc' with type 'void *(unsigned long)' [-Wimplicit-function-declaration]
  arr = (int *)malloc(sizeof(int) * N);
               ^
main.c:20:16: note: include the header <stdlib.h> or explicitly provide a declaration for 'malloc'
main.c:22:19: warning: implicit declaration of function 'fscanf' is invalid in C99 [-Wimplicit-function-declaration]
  while (i < N && fscanf(stdin, "%d", &arr[i++]) == 1)
                  ^
main.c:22:19: warning: declaration of built-in function 'fscanf' requires inclusion of the header <stdio.h> [-Wbuiltin-requires-header]
main.c:22:26: error: use of undeclared identifier 'stdin'
  while (i < N && fscanf(stdin, "%d", &arr[i++]) == 1)
                         ^
main.c:33:28: error: use of undeclared identifier 'stdin'
    while (j < 2 && fscanf(stdin, "%d", &consultas[i + i * 2 + j++]) == 1)
                           ^
main.c:44:5: warning: implicitly declaring library function 'printf' with type 'int (const char *, ...)' [-Wimplicit-function-declaration]
    printf("%d\n", sumarDesdeHasta(arr, consultas[i + i * 2], consultas[i + i * 2 + 1]));
    ^
main.c:44:5: note: include the header <stdio.h> or explicitly provide a declaration for 'printf'
5 warnings and 2 errors generated.

                    
#3
Error de compilación
                      main.c:18:3: warning: implicitly declaring library function 'scanf' with type 'int (const char *restrict, ...)' [-Wimplicit-function-declaration]
  scanf("%d*[^\n]", &N);
  ^
main.c:18:3: note: include the header <stdio.h> or explicitly provide a declaration for 'scanf'
main.c:20:16: warning: implicitly declaring library function 'malloc' with type 'void *(unsigned long)' [-Wimplicit-function-declaration]
  arr = (int *)malloc(sizeof(int) * N);
               ^
main.c:20:16: note: include the header <stdlib.h> or explicitly provide a declaration for 'malloc'
main.c:22:19: warning: implicit declaration of function 'fscanf' is invalid in C99 [-Wimplicit-function-declaration]
  while (i < N && fscanf(stdin, "%d", &arr[i++]) == 1)
                  ^
main.c:22:19: warning: declaration of built-in function 'fscanf' requires inclusion of the header <stdio.h> [-Wbuiltin-requires-header]
main.c:22:26: error: use of undeclared identifier 'stdin'
  while (i < N && fscanf(stdin, "%d", &arr[i++]) == 1)
                         ^
main.c:33:28: error: use of undeclared identifier 'stdin'
    while (j < 2 && fscanf(stdin, "%d", &consultas[i + i * 2 + j++]) == 1)
                           ^
main.c:44:5: warning: implicitly declaring library function 'printf' with type 'int (const char *, ...)' [-Wimplicit-function-declaration]
    printf("%d\n", sumarDesdeHasta(arr, consultas[i + i * 2], consultas[i + i * 2 + 1]));
    ^
main.c:44:5: note: include the header <stdio.h> or explicitly provide a declaration for 'printf'
5 warnings and 2 errors generated.

                    
#4
Error de compilación
                      main.c:18:3: warning: implicitly declaring library function 'scanf' with type 'int (const char *restrict, ...)' [-Wimplicit-function-declaration]
  scanf("%d*[^\n]", &N);
  ^
main.c:18:3: note: include the header <stdio.h> or explicitly provide a declaration for 'scanf'
main.c:20:16: warning: implicitly declaring library function 'malloc' with type 'void *(unsigned long)' [-Wimplicit-function-declaration]
  arr = (int *)malloc(sizeof(int) * N);
               ^
main.c:20:16: note: include the header <stdlib.h> or explicitly provide a declaration for 'malloc'
main.c:22:19: warning: implicit declaration of function 'fscanf' is invalid in C99 [-Wimplicit-function-declaration]
  while (i < N && fscanf(stdin, "%d", &arr[i++]) == 1)
                  ^
main.c:22:19: warning: declaration of built-in function 'fscanf' requires inclusion of the header <stdio.h> [-Wbuiltin-requires-header]
main.c:22:26: error: use of undeclared identifier 'stdin'
  while (i < N && fscanf(stdin, "%d", &arr[i++]) == 1)
                         ^
main.c:33:28: error: use of undeclared identifier 'stdin'
    while (j < 2 && fscanf(stdin, "%d", &consultas[i + i * 2 + j++]) == 1)
                           ^
main.c:44:5: warning: implicitly declaring library function 'printf' with type 'int (const char *, ...)' [-Wimplicit-function-declaration]
    printf("%d\n", sumarDesdeHasta(arr, consultas[i + i * 2], consultas[i + i * 2 + 1]));
    ^
main.c:44:5: note: include the header <stdio.h> or explicitly provide a declaration for 'printf'
5 warnings and 2 errors generated.

                    
#5
Error de compilación
                      main.c:18:3: warning: implicitly declaring library function 'scanf' with type 'int (const char *restrict, ...)' [-Wimplicit-function-declaration]
  scanf("%d*[^\n]", &N);
  ^
main.c:18:3: note: include the header <stdio.h> or explicitly provide a declaration for 'scanf'
main.c:20:16: warning: implicitly declaring library function 'malloc' with type 'void *(unsigned long)' [-Wimplicit-function-declaration]
  arr = (int *)malloc(sizeof(int) * N);
               ^
main.c:20:16: note: include the header <stdlib.h> or explicitly provide a declaration for 'malloc'
main.c:22:19: warning: implicit declaration of function 'fscanf' is invalid in C99 [-Wimplicit-function-declaration]
  while (i < N && fscanf(stdin, "%d", &arr[i++]) == 1)
                  ^
main.c:22:19: warning: declaration of built-in function 'fscanf' requires inclusion of the header <stdio.h> [-Wbuiltin-requires-header]
main.c:22:26: error: use of undeclared identifier 'stdin'
  while (i < N && fscanf(stdin, "%d", &arr[i++]) == 1)
                         ^
main.c:33:28: error: use of undeclared identifier 'stdin'
    while (j < 2 && fscanf(stdin, "%d", &consultas[i + i * 2 + j++]) == 1)
                           ^
main.c:44:5: warning: implicitly declaring library function 'printf' with type 'int (const char *, ...)' [-Wimplicit-function-declaration]
    printf("%d\n", sumarDesdeHasta(arr, consultas[i + i * 2], consultas[i + i * 2 + 1]));
    ^
main.c:44:5: note: include the header <stdio.h> or explicitly provide a declaration for 'printf'
5 warnings and 2 errors generated.

                    
#6
Error de compilación
                      main.c:18:3: warning: implicitly declaring library function 'scanf' with type 'int (const char *restrict, ...)' [-Wimplicit-function-declaration]
  scanf("%d*[^\n]", &N);
  ^
main.c:18:3: note: include the header <stdio.h> or explicitly provide a declaration for 'scanf'
main.c:20:16: warning: implicitly declaring library function 'malloc' with type 'void *(unsigned long)' [-Wimplicit-function-declaration]
  arr = (int *)malloc(sizeof(int) * N);
               ^
main.c:20:16: note: include the header <stdlib.h> or explicitly provide a declaration for 'malloc'
main.c:22:19: warning: implicit declaration of function 'fscanf' is invalid in C99 [-Wimplicit-function-declaration]
  while (i < N && fscanf(stdin, "%d", &arr[i++]) == 1)
                  ^
main.c:22:19: warning: declaration of built-in function 'fscanf' requires inclusion of the header <stdio.h> [-Wbuiltin-requires-header]
main.c:22:26: error: use of undeclared identifier 'stdin'
  while (i < N && fscanf(stdin, "%d", &arr[i++]) == 1)
                         ^
main.c:33:28: error: use of undeclared identifier 'stdin'
    while (j < 2 && fscanf(stdin, "%d", &consultas[i + i * 2 + j++]) == 1)
                           ^
main.c:44:5: warning: implicitly declaring library function 'printf' with type 'int (const char *, ...)' [-Wimplicit-function-declaration]
    printf("%d\n", sumarDesdeHasta(arr, consultas[i + i * 2], consultas[i + i * 2 + 1]));
    ^
main.c:44:5: note: include the header <stdio.h> or explicitly provide a declaration for 'printf'
5 warnings and 2 errors generated.

                    
#7
Error de compilación
                      main.c:18:3: warning: implicitly declaring library function 'scanf' with type 'int (const char *restrict, ...)' [-Wimplicit-function-declaration]
  scanf("%d*[^\n]", &N);
  ^
main.c:18:3: note: include the header <stdio.h> or explicitly provide a declaration for 'scanf'
main.c:20:16: warning: implicitly declaring library function 'malloc' with type 'void *(unsigned long)' [-Wimplicit-function-declaration]
  arr = (int *)malloc(sizeof(int) * N);
               ^
main.c:20:16: note: include the header <stdlib.h> or explicitly provide a declaration for 'malloc'
main.c:22:19: warning: implicit declaration of function 'fscanf' is invalid in C99 [-Wimplicit-function-declaration]
  while (i < N && fscanf(stdin, "%d", &arr[i++]) == 1)
                  ^
main.c:22:19: warning: declaration of built-in function 'fscanf' requires inclusion of the header <stdio.h> [-Wbuiltin-requires-header]
main.c:22:26: error: use of undeclared identifier 'stdin'
  while (i < N && fscanf(stdin, "%d", &arr[i++]) == 1)
                         ^
main.c:33:28: error: use of undeclared identifier 'stdin'
    while (j < 2 && fscanf(stdin, "%d", &consultas[i + i * 2 + j++]) == 1)
                           ^
main.c:44:5: warning: implicitly declaring library function 'printf' with type 'int (const char *, ...)' [-Wimplicit-function-declaration]
    printf("%d\n", sumarDesdeHasta(arr, consultas[i + i * 2], consultas[i + i * 2 + 1]));
    ^
main.c:44:5: note: include the header <stdio.h> or explicitly provide a declaration for 'printf'
5 warnings and 2 errors generated.

                    
#8
Error de compilación
                      main.c:18:3: warning: implicitly declaring library function 'scanf' with type 'int (const char *restrict, ...)' [-Wimplicit-function-declaration]
  scanf("%d*[^\n]", &N);
  ^
main.c:18:3: note: include the header <stdio.h> or explicitly provide a declaration for 'scanf'
main.c:20:16: warning: implicitly declaring library function 'malloc' with type 'void *(unsigned long)' [-Wimplicit-function-declaration]
  arr = (int *)malloc(sizeof(int) * N);
               ^
main.c:20:16: note: include the header <stdlib.h> or explicitly provide a declaration for 'malloc'
main.c:22:19: warning: implicit declaration of function 'fscanf' is invalid in C99 [-Wimplicit-function-declaration]
  while (i < N && fscanf(stdin, "%d", &arr[i++]) == 1)
                  ^
main.c:22:19: warning: declaration of built-in function 'fscanf' requires inclusion of the header <stdio.h> [-Wbuiltin-requires-header]
main.c:22:26: error: use of undeclared identifier 'stdin'
  while (i < N && fscanf(stdin, "%d", &arr[i++]) == 1)
                         ^
main.c:33:28: error: use of undeclared identifier 'stdin'
    while (j < 2 && fscanf(stdin, "%d", &consultas[i + i * 2 + j++]) == 1)
                           ^
main.c:44:5: warning: implicitly declaring library function 'printf' with type 'int (const char *, ...)' [-Wimplicit-function-declaration]
    printf("%d\n", sumarDesdeHasta(arr, consultas[i + i * 2], consultas[i + i * 2 + 1]));
    ^
main.c:44:5: note: include the header <stdio.h> or explicitly provide a declaration for 'printf'
5 warnings and 2 errors generated.

                    
#9
Error de compilación
                      main.c:18:3: warning: implicitly declaring library function 'scanf' with type 'int (const char *restrict, ...)' [-Wimplicit-function-declaration]
  scanf("%d*[^\n]", &N);
  ^
main.c:18:3: note: include the header <stdio.h> or explicitly provide a declaration for 'scanf'
main.c:20:16: warning: implicitly declaring library function 'malloc' with type 'void *(unsigned long)' [-Wimplicit-function-declaration]
  arr = (int *)malloc(sizeof(int) * N);
               ^
main.c:20:16: note: include the header <stdlib.h> or explicitly provide a declaration for 'malloc'
main.c:22:19: warning: implicit declaration of function 'fscanf' is invalid in C99 [-Wimplicit-function-declaration]
  while (i < N && fscanf(stdin, "%d", &arr[i++]) == 1)
                  ^
main.c:22:19: warning: declaration of built-in function 'fscanf' requires inclusion of the header <stdio.h> [-Wbuiltin-requires-header]
main.c:22:26: error: use of undeclared identifier 'stdin'
  while (i < N && fscanf(stdin, "%d", &arr[i++]) == 1)
                         ^
main.c:33:28: error: use of undeclared identifier 'stdin'
    while (j < 2 && fscanf(stdin, "%d", &consultas[i + i * 2 + j++]) == 1)
                           ^
main.c:44:5: warning: implicitly declaring library function 'printf' with type 'int (const char *, ...)' [-Wimplicit-function-declaration]
    printf("%d\n", sumarDesdeHasta(arr, consultas[i + i * 2], consultas[i + i * 2 + 1]));
    ^
main.c:44:5: note: include the header <stdio.h> or explicitly provide a declaration for 'printf'
5 warnings and 2 errors generated.

                    
#10
Error de compilación
                      main.c:18:3: warning: implicitly declaring library function 'scanf' with type 'int (const char *restrict, ...)' [-Wimplicit-function-declaration]
  scanf("%d*[^\n]", &N);
  ^
main.c:18:3: note: include the header <stdio.h> or explicitly provide a declaration for 'scanf'
main.c:20:16: warning: implicitly declaring library function 'malloc' with type 'void *(unsigned long)' [-Wimplicit-function-declaration]
  arr = (int *)malloc(sizeof(int) * N);
               ^
main.c:20:16: note: include the header <stdlib.h> or explicitly provide a declaration for 'malloc'
main.c:22:19: warning: implicit declaration of function 'fscanf' is invalid in C99 [-Wimplicit-function-declaration]
  while (i < N && fscanf(stdin, "%d", &arr[i++]) == 1)
                  ^
main.c:22:19: warning: declaration of built-in function 'fscanf' requires inclusion of the header <stdio.h> [-Wbuiltin-requires-header]
main.c:22:26: error: use of undeclared identifier 'stdin'
  while (i < N && fscanf(stdin, "%d", &arr[i++]) == 1)
                         ^
main.c:33:28: error: use of undeclared identifier 'stdin'
    while (j < 2 && fscanf(stdin, "%d", &consultas[i + i * 2 + j++]) == 1)
                           ^
main.c:44:5: warning: implicitly declaring library function 'printf' with type 'int (const char *, ...)' [-Wimplicit-function-declaration]
    printf("%d\n", sumarDesdeHasta(arr, consultas[i + i * 2], consultas[i + i * 2 + 1]));
    ^
main.c:44:5: note: include the header <stdio.h> or explicitly provide a declaration for 'printf'
5 warnings and 2 errors generated.

                    
#11
Error de compilación
                      main.c:18:3: warning: implicitly declaring library function 'scanf' with type 'int (const char *restrict, ...)' [-Wimplicit-function-declaration]
  scanf("%d*[^\n]", &N);
  ^
main.c:18:3: note: include the header <stdio.h> or explicitly provide a declaration for 'scanf'
main.c:20:16: warning: implicitly declaring library function 'malloc' with type 'void *(unsigned long)' [-Wimplicit-function-declaration]
  arr = (int *)malloc(sizeof(int) * N);
               ^
main.c:20:16: note: include the header <stdlib.h> or explicitly provide a declaration for 'malloc'
main.c:22:19: warning: implicit declaration of function 'fscanf' is invalid in C99 [-Wimplicit-function-declaration]
  while (i < N && fscanf(stdin, "%d", &arr[i++]) == 1)
                  ^
main.c:22:19: warning: declaration of built-in function 'fscanf' requires inclusion of the header <stdio.h> [-Wbuiltin-requires-header]
main.c:22:26: error: use of undeclared identifier 'stdin'
  while (i < N && fscanf(stdin, "%d", &arr[i++]) == 1)
                         ^
main.c:33:28: error: use of undeclared identifier 'stdin'
    while (j < 2 && fscanf(stdin, "%d", &consultas[i + i * 2 + j++]) == 1)
                           ^
main.c:44:5: warning: implicitly declaring library function 'printf' with type 'int (const char *, ...)' [-Wimplicit-function-declaration]
    printf("%d\n", sumarDesdeHasta(arr, consultas[i + i * 2], consultas[i + i * 2 + 1]));
    ^
main.c:44:5: note: include the header <stdio.h> or explicitly provide a declaration for 'printf'
5 warnings and 2 errors generated.

                    
#12
Error de compilación
                      main.c:18:3: warning: implicitly declaring library function 'scanf' with type 'int (const char *restrict, ...)' [-Wimplicit-function-declaration]
  scanf("%d*[^\n]", &N);
  ^
main.c:18:3: note: include the header <stdio.h> or explicitly provide a declaration for 'scanf'
main.c:20:16: warning: implicitly declaring library function 'malloc' with type 'void *(unsigned long)' [-Wimplicit-function-declaration]
  arr = (int *)malloc(sizeof(int) * N);
               ^
main.c:20:16: note: include the header <stdlib.h> or explicitly provide a declaration for 'malloc'
main.c:22:19: warning: implicit declaration of function 'fscanf' is invalid in C99 [-Wimplicit-function-declaration]
  while (i < N && fscanf(stdin, "%d", &arr[i++]) == 1)
                  ^
main.c:22:19: warning: declaration of built-in function 'fscanf' requires inclusion of the header <stdio.h> [-Wbuiltin-requires-header]
main.c:22:26: error: use of undeclared identifier 'stdin'
  while (i < N && fscanf(stdin, "%d", &arr[i++]) == 1)
                         ^
main.c:33:28: error: use of undeclared identifier 'stdin'
    while (j < 2 && fscanf(stdin, "%d", &consultas[i + i * 2 + j++]) == 1)
                           ^
main.c:44:5: warning: implicitly declaring library function 'printf' with type 'int (const char *, ...)' [-Wimplicit-function-declaration]
    printf("%d\n", sumarDesdeHasta(arr, consultas[i + i * 2], consultas[i + i * 2 + 1]));
    ^
main.c:44:5: note: include the header <stdio.h> or explicitly provide a declaration for 'printf'
5 warnings and 2 errors generated.

                    
#13
Error de compilación
                      main.c:18:3: warning: implicitly declaring library function 'scanf' with type 'int (const char *restrict, ...)' [-Wimplicit-function-declaration]
  scanf("%d*[^\n]", &N);
  ^
main.c:18:3: note: include the header <stdio.h> or explicitly provide a declaration for 'scanf'
main.c:20:16: warning: implicitly declaring library function 'malloc' with type 'void *(unsigned long)' [-Wimplicit-function-declaration]
  arr = (int *)malloc(sizeof(int) * N);
               ^
main.c:20:16: note: include the header <stdlib.h> or explicitly provide a declaration for 'malloc'
main.c:22:19: warning: implicit declaration of function 'fscanf' is invalid in C99 [-Wimplicit-function-declaration]
  while (i < N && fscanf(stdin, "%d", &arr[i++]) == 1)
                  ^
main.c:22:19: warning: declaration of built-in function 'fscanf' requires inclusion of the header <stdio.h> [-Wbuiltin-requires-header]
main.c:22:26: error: use of undeclared identifier 'stdin'
  while (i < N && fscanf(stdin, "%d", &arr[i++]) == 1)
                         ^
main.c:33:28: error: use of undeclared identifier 'stdin'
    while (j < 2 && fscanf(stdin, "%d", &consultas[i + i * 2 + j++]) == 1)
                           ^
main.c:44:5: warning: implicitly declaring library function 'printf' with type 'int (const char *, ...)' [-Wimplicit-function-declaration]
    printf("%d\n", sumarDesdeHasta(arr, consultas[i + i * 2], consultas[i + i * 2 + 1]));
    ^
main.c:44:5: note: include the header <stdio.h> or explicitly provide a declaration for 'printf'
5 warnings and 2 errors generated.

                    
#14
Error de compilación
                      main.c:18:3: warning: implicitly declaring library function 'scanf' with type 'int (const char *restrict, ...)' [-Wimplicit-function-declaration]
  scanf("%d*[^\n]", &N);
  ^
main.c:18:3: note: include the header <stdio.h> or explicitly provide a declaration for 'scanf'
main.c:20:16: warning: implicitly declaring library function 'malloc' with type 'void *(unsigned long)' [-Wimplicit-function-declaration]
  arr = (int *)malloc(sizeof(int) * N);
               ^
main.c:20:16: note: include the header <stdlib.h> or explicitly provide a declaration for 'malloc'
main.c:22:19: warning: implicit declaration of function 'fscanf' is invalid in C99 [-Wimplicit-function-declaration]
  while (i < N && fscanf(stdin, "%d", &arr[i++]) == 1)
                  ^
main.c:22:19: warning: declaration of built-in function 'fscanf' requires inclusion of the header <stdio.h> [-Wbuiltin-requires-header]
main.c:22:26: error: use of undeclared identifier 'stdin'
  while (i < N && fscanf(stdin, "%d", &arr[i++]) == 1)
                         ^
main.c:33:28: error: use of undeclared identifier 'stdin'
    while (j < 2 && fscanf(stdin, "%d", &consultas[i + i * 2 + j++]) == 1)
                           ^
main.c:44:5: warning: implicitly declaring library function 'printf' with type 'int (const char *, ...)' [-Wimplicit-function-declaration]
    printf("%d\n", sumarDesdeHasta(arr, consultas[i + i * 2], consultas[i + i * 2 + 1]));
    ^
main.c:44:5: note: include the header <stdio.h> or explicitly provide a declaration for 'printf'
5 warnings and 2 errors generated.

                    
Puntos totales: 0 / 100

Código

int sumarDesdeHasta(int *arr, int p, int q)
{
  int res = 0;
  // printf("p: %d / q: %d\n", p, q);
  for (int i = p; i <= q; i++)
  {
    // printf("%d + %d = %d\n", res, arr[i], res + arr[i]);
    res += arr[i];
  }

  return res;
}

int main()
{
  int N, c, i = 0, j, *arr, *consultas;

  scanf("%d*[^\n]", &N);

  arr = (int *)malloc(sizeof(int) * N);

  while (i < N && fscanf(stdin, "%d", &arr[i++]) == 1)
    ;

  scanf("%d*[^\n]", &c);

  consultas = (int *)malloc(sizeof(int) * c * 2);

  // leer cada consulta
  for (i = 0; i < c; i++)
  {
    j = 0;
    while (j < 2 && fscanf(stdin, "%d", &consultas[i + i * 2 + j++]) == 1)
      ;
  }

  // for (i = 0; i < c; i++) {
  //   printf("%d %d\n", consultas[i + i * 2], consultas[i + i * 2 + 1]);
  // }

  // Ejecutar cada consulta
  for (i = 0; i < c; i++)
  {
    printf("%d\n", sumarDesdeHasta(arr, consultas[i + i * 2], consultas[i + i * 2 + 1]));
    // printf("%d", consultas[i][j]);
  }

  return 0;
}