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

Envío 4736

Problema 0x25 - Suma de un subarreglo grande

  • Autor: Ikerlb
  • Fecha: 2021-08-13 04:39:39 UTC (Hace más de 2 años)
Caso # Resultado Tiempo Memoria
#1
Error de compilación
                      main.c:1:1: error: unknown type name 'def'
def construct_prefix_sum(arr):
^
main.c:1:30: error: expected function body after function declarator
def construct_prefix_sum(arr):
                             ^
main.c:7:3: error: invalid preprocessing directive
# ps is prefix sum!
  ^
3 errors generated.

                    
#2
Error de compilación
                      main.c:1:1: error: unknown type name 'def'
def construct_prefix_sum(arr):
^
main.c:1:30: error: expected function body after function declarator
def construct_prefix_sum(arr):
                             ^
main.c:7:3: error: invalid preprocessing directive
# ps is prefix sum!
  ^
3 errors generated.

                    
#3
Error de compilación
                      main.c:1:1: error: unknown type name 'def'
def construct_prefix_sum(arr):
^
main.c:1:30: error: expected function body after function declarator
def construct_prefix_sum(arr):
                             ^
main.c:7:3: error: invalid preprocessing directive
# ps is prefix sum!
  ^
3 errors generated.

                    
#4
Error de compilación
                      main.c:1:1: error: unknown type name 'def'
def construct_prefix_sum(arr):
^
main.c:1:30: error: expected function body after function declarator
def construct_prefix_sum(arr):
                             ^
main.c:7:3: error: invalid preprocessing directive
# ps is prefix sum!
  ^
3 errors generated.

                    
#5
Error de compilación
                      main.c:1:1: error: unknown type name 'def'
def construct_prefix_sum(arr):
^
main.c:1:30: error: expected function body after function declarator
def construct_prefix_sum(arr):
                             ^
main.c:7:3: error: invalid preprocessing directive
# ps is prefix sum!
  ^
3 errors generated.

                    
#6
Error de compilación
                      main.c:1:1: error: unknown type name 'def'
def construct_prefix_sum(arr):
^
main.c:1:30: error: expected function body after function declarator
def construct_prefix_sum(arr):
                             ^
main.c:7:3: error: invalid preprocessing directive
# ps is prefix sum!
  ^
3 errors generated.

                    
#7
Error de compilación
                      main.c:1:1: error: unknown type name 'def'
def construct_prefix_sum(arr):
^
main.c:1:30: error: expected function body after function declarator
def construct_prefix_sum(arr):
                             ^
main.c:7:3: error: invalid preprocessing directive
# ps is prefix sum!
  ^
3 errors generated.

                    
#8
Error de compilación
                      main.c:1:1: error: unknown type name 'def'
def construct_prefix_sum(arr):
^
main.c:1:30: error: expected function body after function declarator
def construct_prefix_sum(arr):
                             ^
main.c:7:3: error: invalid preprocessing directive
# ps is prefix sum!
  ^
3 errors generated.

                    
#9
Error de compilación
                      main.c:1:1: error: unknown type name 'def'
def construct_prefix_sum(arr):
^
main.c:1:30: error: expected function body after function declarator
def construct_prefix_sum(arr):
                             ^
main.c:7:3: error: invalid preprocessing directive
# ps is prefix sum!
  ^
3 errors generated.

                    
#10
Error de compilación
                      main.c:1:1: error: unknown type name 'def'
def construct_prefix_sum(arr):
^
main.c:1:30: error: expected function body after function declarator
def construct_prefix_sum(arr):
                             ^
main.c:7:3: error: invalid preprocessing directive
# ps is prefix sum!
  ^
3 errors generated.

                    
#11
Error de compilación
                      main.c:1:1: error: unknown type name 'def'
def construct_prefix_sum(arr):
^
main.c:1:30: error: expected function body after function declarator
def construct_prefix_sum(arr):
                             ^
main.c:7:3: error: invalid preprocessing directive
# ps is prefix sum!
  ^
3 errors generated.

                    
#12
Error de compilación
                      main.c:1:1: error: unknown type name 'def'
def construct_prefix_sum(arr):
^
main.c:1:30: error: expected function body after function declarator
def construct_prefix_sum(arr):
                             ^
main.c:7:3: error: invalid preprocessing directive
# ps is prefix sum!
  ^
3 errors generated.

                    
#13
Error de compilación
                      main.c:1:1: error: unknown type name 'def'
def construct_prefix_sum(arr):
^
main.c:1:30: error: expected function body after function declarator
def construct_prefix_sum(arr):
                             ^
main.c:7:3: error: invalid preprocessing directive
# ps is prefix sum!
  ^
3 errors generated.

                    
#14
Error de compilación
                      main.c:1:1: error: unknown type name 'def'
def construct_prefix_sum(arr):
^
main.c:1:30: error: expected function body after function declarator
def construct_prefix_sum(arr):
                             ^
main.c:7:3: error: invalid preprocessing directive
# ps is prefix sum!
  ^
3 errors generated.

                    
Puntos totales: 0 / 100

Código

def construct_prefix_sum(arr):
    p = [0]
    for n in arr:
        p.append(p[-1] + n)
    return p

# ps is prefix sum!
def query(ps, l, r):
    return ps[r] - ps[l - 1]    
    
if __name__ == "__main__":
    N = int(input())
    arr = list(map(int, input().split(" ")))
    p = construct_prefix_sum(arr)
    q = int(input())
    for _ in range(q):
        l, r = map(int, input().split(" "))
        print(query(p, l, r))