Блог пользователя 0t0infinity

Автор 0t0infinity, история, 4 месяца назад, По-английски

This is the Part-2 of my Bitwise Operations Blog. In this part, I focused more on intermediate-level bitwise tricks, Common CP Patterns and a few slightly advanced techniques that appear frequently in contest. — Part-1 — Click Here
I tried to explain the intuition and thinking process behind each trick as clearly and simple as possible.

And as always, Heartfelt thanks to Raha Ahmed for her endless encouragement, strongest support and constant belief in me !


Core Concepts You Must Understand First :-


Intermediate level Bitwise Problems in CP rarely ask you to just "check" or "set" a bit. Instead, they require you to use the Mathematical Properties of bits to optimize your code. Before we jump into the 8 Master Pattern, you need to firmly understand these 5 core concepts.
If you understand these the upcoming patterns will feels like magic !


Core Explanations - (click here)

Topic 1 : Bit-by-Bit Contribution :-


Explanation - (click here)

Topic 2 : The Equation That Solves Half of Bitwise Math :-


Explanation - (click here)

Topic 3 : The Monotonicity of AND / OR :-


Explanation - (click here)

Topic 4 : Greedy with MSB : Top-Down Approach :-


Explanation - (click here)

Topic 5 : Prefix XOR : The O(1) Range Query Magic :-


Explanation - (click here)

Topic 6 : Submask Enumeration : The Magic Loop :-


Explanation - (click here)

Topic 7 : __builtin_clz and __builtin_ctz Tricks :-


Explanation - (click here)

Topic 8 : Game Theory : The Magic of Nim-Sum :-


Explanation - (click here)


Part-3 (Advanced Bitwise Operations) :-

To be honest, I haven’t completely mastered the most advanced bitwise techniques yet and there is still so much left for me to learn.
So I plan to write a Part-3 in the future when I dive deeper into those advanced topics and feel truly capable of explaining them.
Please keep me in your prayers. Happy journey, Everyone ! Regards :- RS1630


Полный текст и комментарии »

  • Проголосовать: нравится
  • +75
  • Проголосовать: не нравится

Автор 0t0infinity, история, 5 месяцев назад, По-английски

Bitwise Operations was one of the most confusing topics for me at first. But once I started understanding how bits actually work, many CP problems suddenly became much easier to think about and optimize.

This blog is the result of a full day of grinding, where I tried to organize everything I know about bitwise tricks into a clear and structured form — from the basics to useful CP patterns. I tried to keep everything as simple and beginner-friendly as possible so that anyone can understand the core idea behind each trick instead of memorizing formulas. If even one trick from this blog helps someone solve a problem faster or understand bits more clearly, then this effort feels truly meaningful for me.

And finally, I want to express my deepest gratitude to Raha Ahmed for being The Strongest support in my CP journey. Her constant encouragement, belief and presence have played a huge role in shaping my progress and I’m truly grateful for everything she has done.


The Basics for Beginners :


Basics All - (click here)

Trick 1 : Check Odd or Even Number


Explanation - (click here)

Trick 2 : Check The k-th bit


Explanation - (click here)

Trick 3 : iterate Through All Bits


Explanation - (click here)

Trick 4 : Count Set bits / On bits


Explanation - (click here)

Trick 5 : Set and Clear The k-th bit


Explanation - (click here)

Trick 6 : Toggle The k-th bit


Explanation - (click here)

Trick 7 : Multiply and Divide by 2


Explanation - (click here)

Trick 8 : Remove The Lowest Set bit


Explanation - (click here)

Trick 9 : Get The Lowest Set bit


Explanation - (click here)

Trick 10 : Count Trailing and Leading Zeros


Explanation - (click here)

Trick 11 : Find The Highest Set Bit Position


Explanation - (click here)

Trick 12 : Check whether A Number is Power of 2


Explanation - (click here)

Trick 13 : Find The Unique Element using XOR


Explanation - (click here)

Trick 14 : Generate All Subsets using Bitmask


Explanation - (click here)

Part 2 (Intermediate Level) : Part-2 — Click Here


Полный текст и комментарии »

  • Проголосовать: нравится
  • +62
  • Проголосовать: не нравится