-
[백준 20364] 부동산 다툼백준/비트마스크 2023. 6. 30. 20:52
제목이 굉장히 별로다
문제는 쉽다
bitset 을 사용해서 풀어봐서 정리해놔야겠다
bitset사용 + /2 대신 비트연산자 사용한거 중점으로 보면 된다
#include <iostream> #include <bitset> #define SIZE 1048577 using namespace std; bitset<SIZE> tree; int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); int N, Q; cin >> N >> Q; int x; for (; Q--;) { cin >> x; int temp = x; int ans = 0; while (x) { if (tree[x]) ans = x; x = x >> 1; } cout << ans << "\n"; if (!ans) tree[temp] = 1; } return 0; }
'백준 > 비트마스크' 카테고리의 다른 글
[백준 1244] 스위치 켜고 끄기 (0) 2023.11.11 [백준 20501] Facebook (0) 2023.07.07 [백준 27375] 금공강 사수 (0) 2023.07.04 [백준 11723] 집합 (0) 2023.07.03