제출 #1269356

#제출 시각아이디문제언어결과실행 시간메모리
1269356PagodePaivaSjeckanje (COCI21_sjeckanje)Pypy 3
0 / 110
165 ms50612 KiB
import sys
import threading

def main():
    import sys
    data = sys.stdin
    line = data.readline().split()
    n, q = int(line[0]), int(line[1])
    a = list(map(int, data.readline().split()))
    # If there's only one checkpoint, scenic score is always 0
    if n == 1:
        for _ in range(q):
            data.readline()
            print(0)
        return
    # Build difference array d[i] = a[i+1] - a[i]
    d = [a[i+1] - a[i] for i in range(n-1)]
    # Initial total scenic score = sum of absolute differences
    total = sum(abs(v) for v in d)
    out = []
    for _ in range(q):
        l, r, x = map(int, data.readline().split())
        # Convert to 0-based
        l -= 1
        r -= 1
        # Update the difference at l-1 if l > 0
        if l > 0:
            idx = l - 1
            old = d[idx]
            new = old + x
            total += abs(new) - abs(old)
            d[idx] = new
        # Update the difference at r if r < n-1
        if r < n - 1:
            idx = r
            old = d[idx]
            new = old - x
            total += abs(new) - abs(old)
            d[idx] = new
        out.append(str(total))
    sys.stdout.write("\n".join(out))

if __name__ == "__main__":
    main()

컴파일 시 표준 출력 (stdout) 메시지

Compiling 'Main.py'...

=======
  adding: __main__.pyc (deflated 39%)

=======
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...