Problem Solving

[BOJ10816] 숫자 카드 2

dododoo 2020. 3. 21. 13:09

1. 문제

https://www.acmicpc.net/problem/10816

2. Note

std::lower_bound, std::upper_bound를 사용하는 문제

2.1. lower_bound(first, last, value)

value보다 크거나 같은 첫 번째 iterator 반환, 없을 시 last 반환

2.2. upper_bound(first, last, value)

value보다 큰 첫 번째 iterator 반환, 없을 시 last 반환

2.3. equal_range()

return std::make_pair(std::lower_bound(first, last, value),
                      std::upper_bound(first, last, value));

NOTE: 위 세 함수는 random access iterator가 아니면 선형 시간복잡도를 갖는다.

2.4. std::distance vs. operator-

Since only random access iterators provide + and - operators, the library provides two function templates advance and distance. These function templates use + and - for random access iterators (and are, therefore, constant time for them); for input, forward and bidirectional iterators they use ++ to provide linear time implementations.

https://stackoverflow.com/questions/1668088/advance-iterator-for-the-stdvector-stdadvance-vs-operator

3. Reference

'Problem Solving' 카테고리의 다른 글

[BOJ1300] K번째 수 (이분 탐색)  (0) 2020.03.23
[BOJ2110] 공유기 설치  (0) 2020.03.23
[BOJ2261] 가장 가까운 두 점  (0) 2020.03.20
[BOJ11004] K번째 수 (K-th smallest)  (0) 2020.03.19
[BOJ2749] 피보나치 수 3  (0) 2020.03.16