[Tutorial/Parody] How to practice basic topic in CP (Episode 1)

Правка en3, от thanhchauns2, 2023-01-11 17:19:56

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 discuss about any data structures 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++.

История

 
 
 
 
Правки
 
 
  Rev. Язык Кто Когда Δ Комментарий
en4 Английский thanhchauns2 2023-01-11 17:27:12 48
en3 Английский thanhchauns2 2023-01-11 17:19:56 737
en2 Английский thanhchauns2 2023-01-11 17:18:20 8417 Tiny change: 'ick me">\nA Segmen' -> 'ick me">\n$2$\nA Segmen' (published)
en1 Английский thanhchauns2 2023-01-11 16:25:35 1429 Initial revision (saved to drafts)