thanhchauns2's blog

By thanhchauns2, history, 23 months ago, In English

Not long ago ToxicPie9 posted a blog explaining common mistakes in competitive programming and how to avoid them. I was greatly inspired by that post so I decided to write an episode on my own.

Today I will mention four topics that I learned why practicing Competitive Programming and I will also mention how to build them. Also, in most cases, I will give you a chance to find out what the hard part is before I reveal the culprit as I tried to make this blog interactive. The codes that I have used in this blog have been written in Python as it is the most powerful language for CP.

Segment trees

Definition:

Click me

So how to build a segment tree?

Click me

Basic usage:

Click me

Update on range:

Click me

Fenwick tree

Definition:

Click me

So how to build a Fenwick tree?

Click me

Basic usage:

Click me

More functions:

Click me

Disjoint Set Union

Definition:

Click me

So how to build a Disjoint Set Union?

Click me

Basic usage:

Click me

Treap

Definition:

Click me

So how to build a Disjoint Set Union?

Click me

Basic usage:

Click me

More about data structures in Python:

Although Python is the most powerful language in CP, there are some data structures that we cannot install through pip like sparse table or sqrt decomposition. If such case, we should:

  • Develop a pip package on your own. Since people, including me, are indiscriminately using C/C++ just for compiling speed, they don't know how powerful Python is and just reject it while doing CP. This is why there are a lack of necessary libraries for Python. Your contribution is priceless.

  • Implement you own library. If pip does not solve the problem, you can just implement your own version. Whenever a contest starts, just copy and paste them in. Voila.

  • Convert the current problem to another problem using a library that is solvable by using pip. This requires a lot of experience in Competitive Programming, since it is a hard job to do.

  • Give up Find another way to solve it, don't give up.

Thanks for reading the blog. Feel free to add more mistakes that are common in CP in the comment section.

See you on a later episode, friend!

P.S. Although this is mostly a joke post, I tried to be accurate about the facts and did not intentionally put incorrect information in it (which means you may treat it as a somewhat educational blog). It also aims to showcase some features of Python that helps you avoid some common CP mistakes in languages like C++.

  • Vote: I like it
  • +46
  • Vote: I do not like it

»
23 months ago, # |
  Vote: I like it +3 Vote: I do not like it

Feel free to add more mistakes that are common in CP in the comment section.

I'm disappointed that you removed this sentence from the original post. Actually, there is one big common mistake in CP which costs very, very much. I think it's also related to this article...

  • »
    »
    23 months ago, # ^ |
      Vote: I like it +8 Vote: I do not like it

    Excuse me, but I'm curious about the mistake you are talking about.

    Spoiler
»
23 months ago, # |
  Vote: I like it +6 Vote: I do not like it

Feel free to add more mistakes that are common in CP in the comment section.

Using Python