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

Envío 943

Problema 0x25 - Suma de un subarreglo grande

  • Autor: fermed
  • Fecha: 2020-10-03 20:41:17 UTC (Hace más de 3 años)
Caso # Resultado Tiempo Memoria
#1
Error en tiempo de ejecución (NZEC)
Exited with error status 1
Traceback (most recent call last):
  File "script.py", line 22, in <module>
    print(sub_array_sum(p, q))
  File "script.py", line 14, in sub_array_sum
    assert(q <= len(arr))
NameError: name 'arr' is not defined
0.02 s 3 KBi
#2
Error en tiempo de ejecución (NZEC)
Exited with error status 1
Traceback (most recent call last):
  File "script.py", line 22, in <module>
    print(sub_array_sum(p, q))
  File "script.py", line 14, in sub_array_sum
    assert(q <= len(arr))
NameError: name 'arr' is not defined
0.022 s 3 KBi
#3
Error en tiempo de ejecución (NZEC)
Exited with error status 1
Traceback (most recent call last):
  File "script.py", line 22, in <module>
    print(sub_array_sum(p, q))
  File "script.py", line 14, in sub_array_sum
    assert(q <= len(arr))
NameError: name 'arr' is not defined
0.023 s 3 KBi
#4
Error en tiempo de ejecución (NZEC)
Exited with error status 1
Traceback (most recent call last):
  File "script.py", line 22, in <module>
    print(sub_array_sum(p, q))
  File "script.py", line 14, in sub_array_sum
    assert(q <= len(arr))
NameError: name 'arr' is not defined
0.026 s 4 KBi
#5
Error en tiempo de ejecución (NZEC)
Exited with error status 1
Traceback (most recent call last):
  File "script.py", line 22, in <module>
    print(sub_array_sum(p, q))
  File "script.py", line 14, in sub_array_sum
    assert(q <= len(arr))
NameError: name 'arr' is not defined
0.023 s 3 KBi
#6
Error en tiempo de ejecución (NZEC)
Exited with error status 1
Traceback (most recent call last):
  File "script.py", line 22, in <module>
    print(sub_array_sum(p, q))
  File "script.py", line 14, in sub_array_sum
    assert(q <= len(arr))
NameError: name 'arr' is not defined
0.025 s 4 KBi
#7
Error en tiempo de ejecución (NZEC)
Exited with error status 1
Traceback (most recent call last):
  File "script.py", line 22, in <module>
    print(sub_array_sum(p, q))
  File "script.py", line 14, in sub_array_sum
    assert(q <= len(arr))
NameError: name 'arr' is not defined
0.022 s 3 KBi
#8
Error en tiempo de ejecución (NZEC)
Exited with error status 1
Traceback (most recent call last):
  File "script.py", line 22, in <module>
    print(sub_array_sum(p, q))
  File "script.py", line 14, in sub_array_sum
    assert(q <= len(arr))
NameError: name 'arr' is not defined
0.062 s 5 KBi
#9
Error en tiempo de ejecución (NZEC)
Exited with error status 1
Traceback (most recent call last):
  File "script.py", line 22, in <module>
    print(sub_array_sum(p, q))
  File "script.py", line 14, in sub_array_sum
    assert(q <= len(arr))
NameError: name 'arr' is not defined
0.207 s 14 KBi
#10
Error en tiempo de ejecución (NZEC)
Exited with error status 1
Traceback (most recent call last):
  File "script.py", line 22, in <module>
    print(sub_array_sum(p, q))
  File "script.py", line 14, in sub_array_sum
    assert(q <= len(arr))
NameError: name 'arr' is not defined
0.203 s 14 KBi
#11
Error en tiempo de ejecución (NZEC)
Exited with error status 1
Traceback (most recent call last):
  File "script.py", line 22, in <module>
    print(sub_array_sum(p, q))
  File "script.py", line 14, in sub_array_sum
    assert(q <= len(arr))
NameError: name 'arr' is not defined
0.213 s 14 KBi
#12
Error en tiempo de ejecución (NZEC)
Exited with error status 1
Traceback (most recent call last):
  File "script.py", line 22, in <module>
    print(sub_array_sum(p, q))
  File "script.py", line 14, in sub_array_sum
    assert(q <= len(arr))
NameError: name 'arr' is not defined
0.235 s 14 KBi
#13
Error en tiempo de ejecución (NZEC)
Exited with error status 1
Traceback (most recent call last):
  File "script.py", line 22, in <module>
    print(sub_array_sum(p, q))
  File "script.py", line 14, in sub_array_sum
    assert(q <= len(arr))
NameError: name 'arr' is not defined
0.202 s 16 KBi
#14
Error en tiempo de ejecución (NZEC)
Exited with error status 1
Traceback (most recent call last):
  File "script.py", line 22, in <module>
    print(sub_array_sum(p, q))
  File "script.py", line 14, in sub_array_sum
    assert(q <= len(arr))
NameError: name 'arr' is not defined
0.216 s 16 KBi
Puntos totales: 0 / 100

Código

n = int(input())
numbers = list(map(int, input().split()))
assert(n == len(numbers))
c = int(input())
queries = [list(map(int, input().split())) for i in range(c)]
accumulated_sum = []
sum = 0
for number in numbers:
    sum += number
    accumulated_sum.append(sum)

def sub_array_sum(p, q):
    assert(p <= q)
    assert(q <= len(arr))
    if p == q:
        return (accumulated_sum[q])
    return(accumulated_sum[q] - accumulated_sum[p])


for query in queries:
    p, q = query
    print(sub_array_sum(p, q))