Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
π λ¬Έμ λ§ν¬
2042λ² κ΅¬κ° ν© κ΅¬νκΈ°
βοΈ μμλ μκ°
?
β¨ μλ μ½λ
μ¬κΈ°μ μ¬μ©ν μκ³ λ¦¬μ¦(νΈλ¦¬) Fenwick Tree, Binary Indexed Tree(BIT)
μκ° λ³΅μ‘λ O(logN)
곡κ°λ³΅μ‘λ O(N)
1μ°¨μ, 2μ°¨μ νΉμ λ€μ°¨μμ Query λ₯Ό μ²λ¦¬νλλ° μ¬μ© λ μ μλ λ§€μ° ν¨μ¨μ μΈ μλ£κ΅¬μ‘°μ λλ€.
Aλ°°μ΄μλ μ«μκ° λ€μ΄κ°λλ€.
treeλ°°μ΄μλ ꡬκ°ν© μ λ³΄κ° λ€μ΄κ°λλ€.
νμ νΈλ¦¬μμ νμλ²μ§Έ κ°μ μκΈ°μμ μ΄κ³ μ΄μΈμλ μκΈ°μμ κΉμ§μ λ²μ κ°μ΄λ€
νμ νΈλ¦¬λ₯Ό ꡬννκΈ° μν΄μ κ°μμ 0μ΄ μλ μ΅νμ λΉνΈλ₯Ό ꡬν΄μΌνλ€.
3 = (11)β => (01)β
5 = (101)β =>(001)β
6 = (110)β => (010)β
8 = (1000)β => (1000)β
μ΄κ±Έ ꡬνκΈ° μν΄μ κ°μ iλΌκ³ νλ©΄
iβ & -iβ λΉνΈ and μ°μ°μ νλ©΄ λλ€.
μλ₯Ό λ€μ΄μ i = 13(1101)β
(1101)β & (0011)β == (0001)β
μ΄λ κ² 13μμ 첫λ²μ§Έλ‘ 1μΈ λΉνΈλ 첫λ²μ§Έμ μλκ±Έ μ μ μλ€.
Update()
κ°μ λ£κ±°λ μμ ν λ μ¬μ©νλ ν¨μλ₯Ό λ³΄κ² μ΅λλ€.
μΈλ±μ€κ° Nλ³΄λ€ μκ±°λ κ°μλκΉμ§ μ΅νμλΉνΈκ° 1μΈκ³³μ μ°Ύμμ λν΄μ€λλ€.
κ·Έλ κ² νλ©΄ μ΄ μ«μκ° ν¬ν¨λ λΆλΆν© λΆλΆμ μΈλ±μ€λ₯Ό λ€ μ°Ύμ μ μκ³ κ·Έκ³³μ κ°μ μμ ν΄μ€λλ€.(μ€λ₯Έμͺ½μΌλ‘ κ°λ λλ)
λ€μκ³Ό κ°μ index μμλλ‘ μ°¨μ΄κ°λ§νΌ κ°μ λν΄μ£Όλ©΄ λ©λλ€.
sum()
κ΅¬κ° ν©μ ꡬνλ ν¨μ
ꡬκ°ν©μ μ²μλΆν° iλ²μ§Έ μΈλ±μ€κΉμ§μ ν©μ ꡬν μ μμ΅λλ€.
κ·Έλμ νΉμ ꡬκ°μ ꡬνκΈ° μν΄ μλμ κ°μ΄ ν μλ μμ΅λλ€.
ꡬκ°ν©μ μ λ°μ΄νΈμ λ°λλ‘
μΈλ±μ€κ° 0λ³΄λ€ ν¬λ©΄ μ΅νμλΉνΈκ° 1μΈκ³³μ μ°Ύμμ λΉΌμ€λλ€(μΌμͺ½μΌλ‘ κ°λ λλ)
13λ²μ§Έ κΉμ§μ ν©μ ꡬνλ©΄ μμκ°μ΄ 17μ΄ λμ΅λλ€.
π μλ‘κ² μκ²λ λ΄μ©
2μ°¨μ λΆλΆν©λ μ μ μλ€κ³ ν©λλ€