| ps | |
|---|---|
| 링크 | acmicpc.net/… |
| 출처 | BOJ |
| 문제 번호 | 18436 |
| 문제명 | 수열과 쿼리 37 |
| 레벨 | 골드 1 |
| 분류 |
구간 쿼리 |
| 시간복잡도 | O(n+mlogn) |
| 인풋사이즈 | n<=100,000, m<=100,000 |
| 사용한 언어 | Python |
| 제출기록 | 44656KB / 692ms |
| 최고기록 | 664ms |
| 해결날짜 | 2021/03/24 |
"""Solution code for "BOJ 18436. 수열과 쿼리 37".
- Problem link: https://www.acmicpc.net/problem/18436
- Solution link: http://www.teferi.net/ps/problems/boj/18436
"""
import sys
from teflib import fenwicktree
def main():
N = int(sys.stdin.readline()) # pylint: disable=unused-variable
A = [int(x) for x in sys.stdin.readline().split()]
M = int(sys.stdin.readline())
fenwick = fenwicktree.FenwickTree(x % 2 for x in A)
for _ in range(M):
query = [int(x) for x in sys.stdin.readline().split()]
if query[0] == 1:
_, i, x = query
fenwick.set(i - 1, x % 2)
elif query[0] == 2:
_, l, r = query
print(r - l + 1 - fenwick.query(l - 1, r))
else:
_, l, r = query
print(fenwick.query(l - 1, r))
if __name__ == '__main__':
main()