====== 커피숍2 ====== ===== 풀이 ===== * 구간합과 포인트 업데이트를 번갈아서 처리해주면 되는 기본적인 [[ps:구간 쿼리#구간합|구간합 쿼리]] 문제. * Fenwick tree를 이용하면 초기화에 O(n), 각 쿼리 하나 처리에 O(logn)이 걸린다. 총 시간복잡도는 O(n+mlogn) ===== 코드 ===== """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() * Dependency: [[:ps:teflib:fenwicktree#FenwickTree|teflib.fenwicktree.FenwickTree]] {{tag>BOJ ps:problems:boj:골드_1}}