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:
So how to build a segment tree?
Basic usage:
Update on range:
Fenwick tree
Definition:
So how to build a Fenwick tree?
Basic usage:
More functions:
Disjoint Set Union
Definition:
So how to build a Disjoint Set Union?
Basic usage:
Treap
Definition:
So how to build a Disjoint Set Union?
Basic usage:
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 usingC/C++
just for compiling speed, they don't know how powerfulPython
is and just reject it while doing CP. This is why there are a lack of necessary libraries forPython
. 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 upFind 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++.
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...
Excuse me, but I'm curious about the mistake you are talking about.
Feel free to add more mistakes that are common in CP in the comment section.
Using Python