목차

커피숍2

ps
링크acmicpc.net/…
출처BOJ
문제 번호1275
문제명커피숍2
레벨골드 1
분류

구간합 쿼리

시간복잡도O(n+mlogn)
인풋사이즈n<=100,000, m<=100,000
사용한 언어Python
제출기록42424KB / 1016ms
최고기록1016ms
해결날짜2022/07/04
태그

[라이]세그먼트 트리

풀이

코드

"""Solution code for "BOJ 1275. 커피숍2".

- Problem link: https://www.acmicpc.net/problem/1275
- Solution link: http://www.teferi.net/ps/problems/boj/1275

Tags: [Fenwick tree]
"""

import sys
from teflib import fenwicktree


def main():
    # pylint: disable=unused-variable
    N, Q = [int(x) for x in sys.stdin.readline().split()]
    nums = [int(x) for x in sys.stdin.readline().split()]
    fenwick = fenwicktree.FenwickTree(nums)
    for _ in range(Q):
        x, y, a, b = [int(x) for x in sys.stdin.readline().split()]
        print(fenwick.query(x - 1, y) if x < y else fenwick.query(y - 1, x))
        fenwick.set(a - 1, b)


if __name__ == '__main__':
    main()