본문 바로가기
python-algorithm

14648 쿼리 맛보기

by 무적김두칠 2021. 12. 6.

1
2
3
4
5
6
7
8
9
10
11
m,n=map(int, input().split())
myList=list(map(int, input().split()))
for i in range(n):
    myQuery=list(map(int,input().split()))
    if myQuery[0]==1:
        print(sum(myList[myQuery[1]-1:myQuery[2]]))
        tmp=myList[myQuery[1]-1]
        myList[myQuery[1]-1]=myList[myQuery[2- 1]
        myList[myQuery[2- 1]=tmp
    if myQuery[0]==2:
        print(sum(myList[myQuery[1- 1:myQuery[2]])-sum(myList[myQuery[3- 1:myQuery[4]]))
cs

그냥 구현하는 문제라서 어렵지 않아요
다만 폐구간이라는 점 인지하시면서 풀면 되겠어요

반응형

'python-algorithm' 카테고리의 다른 글

백준 1769 3의 배수  (0) 2021.12.06
백준 1292 쉽게 푸는 문제  (0) 2021.12.06
백준 10769 행복한지 슬픈지  (0) 2021.12.03
백준 10426 기념일 2  (0) 2021.12.03
백준 9506 약수들의 합  (0) 2021.12.03

댓글