Скоро Codeforces Round 1133 (Div. 1, Div. 2)! Регистрация здесь. ×

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

Автор elnazar, история, 22 месяца назад, По-русски

Recently, I faced with one issue where two seemingly similar solutions performed differently. I want to know why it is happening?

Code 1: Used an XOR operation (num ^ some_randint) to preprocess numbers before counting their frequencies

Code 2: Counted numbers directly without any transformation.

Both codec followed identical logic after this step, but code 1 passed the test cases efficiently, while code 2 gotaTLE.

WHY? I would be happy if someone could explain.

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

»
22 месяца назад, скрыть # |
 
Проголосовать: нравится +1 Проголосовать: не нравится

Are you counting frequency with unordered_map? You’re probably facing a hashing collision attack and the xor helps avoid it (although one could theoretically hack it during contest)