BOJ - 14648 - 쿼리 맛보기

Updated:

import sys

def solution():
    N, Q = map(int, sys.stdin.readline().split())
    data = list(map(int, sys.stdin.readline().split()))
    for _ in range(Q):
        query = list(map(int, sys.stdin.readline().split()))

        if query[0] == 1:
            ret = 0
            for i in range(query[1]-1, query[2]):
                ret += data[i]

            print(ret)

            data[query[1]-1], data[query[2]-1] = data[query[2]-1], data[query[1]-1]
        else:
            ret1, ret2 = 0, 0
            for i in range(query[1] - 1, query[2]):
                ret1 += data[i]

            for i in range(query[3] - 1, query[4]):
                ret2 += data[i]

            print(ret1 - ret2)

solution()

https://www.acmicpc.net/problem/14648

Categories:

Updated:

Leave a comment