ps | |
---|---|
링크 | acmicpc.net/… |
출처 | BOJ |
문제 번호 | 14427 |
문제명 | 수열과 쿼리 15 |
레벨 | 골드 1 |
분류 |
우선순위큐 |
시간복잡도 | O(n+mlogn) |
인풋사이즈 | n<=100,000, m<=100,000 |
사용한 언어 | Python |
제출기록 | 51624KB / 468ms |
최고기록 | 468ms |
해결날짜 | 2021/03/20 |
"""Solution code for "BOJ 14427. 수열과 쿼리 15".
- Problem link: https://www.acmicpc.net/problem/14427
- Solution link: http://www.teferi.net/ps/problems/boj/14427
"""
import sys
import heapq
def main():
N = int(sys.stdin.readline())
A = [int(x) for x in sys.stdin.readline().split()]
heap = [(a_i, i + 1) for i, a_i in enumerate(A)]
heapq.heapify(heap)
M = int(sys.stdin.readline())
for i in range(M):
query = [int(x) for x in sys.stdin.readline().split()]
if query[0] == 1:
_, i, v = query
heapq.heappush(heap, (v, i))
A[i - 1] = v
while heap[0][0] != A[heap[0][1] - 1]:
heapq.heappop(heap)
else:
print(heap[0][1])
if __name__ == '__main__':
main()
"""Solution code for "BOJ 14427. 수열과 쿼리 15".
- Problem link: https://www.acmicpc.net/problem/14427
- Solution link: http://www.teferi.net/ps/problems/boj/14427
"""
import sys
from teflib import segmenttree
def main():
N = int(sys.stdin.readline())
A = [int(x) for x in sys.stdin.readline().split()]
segtree = segmenttree.SegmentTree((a_i, i + 1) for i, a_i in enumerate(A))
M = int(sys.stdin.readline())
for i in range(M):
query = [int(x) for x in sys.stdin.readline().split()]
if query[0] == 1:
_, i, v = query
segtree.set(i - 1, (v, i))
else:
print(segtree.query(0, N)[1])
if __name__ == '__main__':
main()