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

Автор Pa_sha, история, 3 недели назад, По-английски

2008A - Sakurako's Exam

Tutorial
Solution in C++
Solution in Python
Rate the problem

2008B - Square or Not

Tutorial
Solution in C++
Solution in Python
Rate the problem

2008C - Longest Good Array

Tutorial
Solution in C++
Solution in Python
Rate the problem

2008D - Sakurako's Hobby

Tutorial
Solution in C++
Solution in Python
Rate the problem

2008E - Alternating String

Tutorial
Solution in C++
Solution in Python
Rate the problem

2008F - Sakurako's Box

Tutorial
Solution in C++
Solution in Python
Rate the problem

2008G - Sakurako's Task

Tutorial
Solution in C++
Solution in Python
Rate the problem

2008H - Sakurako's Test

Tutorial
Solution in C++
Solution in Python
Rate the problem

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

Разбор задач Codeforces Round 970 (Div. 3)
  • Проголосовать: нравится
  • +62
  • Проголосовать: не нравится

Автор Pa_sha, история, 3 недели назад, По-английски

Hello Codeforces!

I am pleased to invite you all to participate in Codeforces Round 970 (Div. 3), which will start on Sep/01/2024 17:35 (Moscow time).

The format of the event will be like any Div. 3 rounds:

  • 6-8 tasks;

  • ICPC rules with a penalty of 10 minutes for an incorrect submission;

  • 12-hour phase of open hacks after the end of the round (hacks do not give additional points)

  • after the end of the open hacking phase, all solutions will be tested on the updated set of tests, and the ratings recalculated

  • by default, only "trusted" participants are shown in the results table.

I encourage participants with a rating of 1600+ not to create new accounts but to participate unofficially.

Only trusted participants of the third division will be included in the official standings table. This is a forced measure for combating unsporting behavior. To qualify as a trusted participant of the third division, you must:

  • take part in at least five rated rounds (and solve at least one problem in each of them),
  • do not have a point of 1900 or higher in the rating.

Regardless of whether you are a trusted participant of the third division or not, if your rating is less than 1600 (or you are a newcomer/unrated), then the round will be rated for you.

Also, it will be the first round with unrated register. If you already registered as rated participant you can change registration type here.

I would like to thank

Good luck!

UPD:

Editorial has been published.

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

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

Автор Pa_sha, история, 5 недель назад, По-английски

I haven't seen anyone to write about this technique, so I decided to make a blog about it. I know that it is mostly general intuition, but not everyone really understand it. Also, I would be happy if you add something in comments or correct some errors. Also, before reading this blog I recommend to have some knowledge about segment tree and divide and conquer.

I would like to thank riazhskkh and FBI for reviewing this blog.

The main idea

When we have some divide and conquer algorithm, we can memorize each recursive call to be able to operate with it as data structure. For example, when we do merge sort, we can memorize how array looked after sorting on each call. Using this we can get merge sort tree. Also, if we memorize quick sort in such way, we will get wavelet tree. A lot of standart ways to use divide and conquer would lead to segment tree. But, it also can be used when we divide array on 3 parts or more, when we divide considering parity of indexes of array and so on. One of the main usage of it, that we can do almost all operation which we can do on segment tree, such as lazy propagation or tree descent, (in fact it depends on the task that we are solving) and in the most cases it optimize solutions alot. For example, if we havee recursion that recursevily divide array on even and odd elements,

Here is what I mean

and assume we memorize at each level (even and odd array each time), then we can do lazy propagation here. For example, we can add $$$x$$$ to all elements on the segment $$$[l,r]$$$, in the same way as in the segment tree. But this recursion can also solve queries to add $$$x$$$ to all elements with even (or odd) indexes on the segment $$$[l,r]$$$, or such indexes that are equal 3 by modulo 4, or in general any index that has last $$$k$$$ bits equal to some number. Also, as you may see, if we replace indexes by numbers, we would get a classic binary tree (a prefix tree).

The problem

We will solve this problem.

Solution

Firstly, we will solve the problem without queries. To make it easier, we can change vertex numbers on the tree using DFS.

For example, from this  as in the statement to this  .

After changing graph indexing, we can use divide and conquer to check if the permutation is good. In fact, for any vertex, all vertexes in its subtree after sorting should be continuous. It is true because of the way we change vertex numbers. So, it can be easily verified by just taking maximum and minimum of all subtrees and checking if there is the same number of elements between maximum and minimum as there is in the tree (It works because all elements are distinct). Important thing is that we can do it on segments, since segment [1,n] represents the whole tree, while segment [2, $$$\lfloor\frac{n+1}{2}\rfloor$$$ ] represents its right subtree, and segment [ $$$\lfloor\frac{n+1}{2}+1\rfloor$$$ ,n] represents its left subtree. Also, it is important to check if the depth of the vertex is the same. You see, in any DFS order, the depth of all vertices doesn't change, but it is easy to come up with a test, where divide and conquer solution will give yes and depths will be wrong.

Code of divide and conquer

This solution works in $$$O(n\cdot log(n))$$$, but we can memorize all layers of a recursion call just like in the segment tree. In fact, all we need to memorize is a maximum and a minimum on a segment and if the segment is good (if check function from divide in conquer returns true or false). Then, we have queries which are to swap two elements. It is the same as changing the value of one element to the value of a second and vice versa for the second element, so all we need to be able to do is to change value of some element. Here, we can just memorize all states of recursion and make something like a segment tree, where segment [l,r) has children [l+1, $$$\lfloor\frac{l+r}{2}\rfloor$$$ ) and [ $$$\lfloor\frac{l+r}{2}\rfloor$$$ , r). So, it will work in $$$O(n\cdot log(n))$$$

Note

This technique can be used not only as binary tree like segment tree, trie or other, but also as another data structures. So, if you have tree with depth $$$g$$$, then you can answer the query in $$$O(g\cdot C)$$$ time where $$$C$$$ is number of operation needed to make decision to the child of the vertex. It means, that in path graph and star graph this will work in linear time per query.

So, you can solve the last problem not only when it is binary, but also when it is random generated. It is because the depth of the random generated tree is $$$O(log(n))$$$.

Also, I believe there could be a lot more tricks like this. Like taking random vertex as a root or doing same on any graph but on MST and so on. Unfortunetly, I have no samples for this yet.

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

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

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

We are excited to announce a new Weekend Practice round on August 3, at 19 UTC. This is a ranking competition at Eolymp.

Format and Difficulty

Same as in previous rounds, the competition is primarily aimed at improving practical skills. There will be 2.5 hours for 5 tasks of varying difficulty, the easiest of which can even be solved by beginners.

The scoring for each task being block-based (meaning points are awarded for each block of tests separately, and only if the solution passes all tests in the block). If there is a tie between two participants, the one whose last productive submission (i.e., a submission that added at least one point) was made earlier will be ranked higher in the leaderboard.

The statements will be available in the following languages: English, Ukrainian, French, Spanish, Azerbaijani, Russian.

Registration

You can join the competition on the competition page.

Prizes

The top-10 participants of the competition, as well as 10 random participants from those who rank from 11th to 100th place, will receive prizes in the form of t-shirts. Please, note, that we have changed how prizes are awarded,

Visit Frequently Asked Questions section to learn more.

Thanks a lot to:

Sponsors

This round is sponsored by Pinely.

Pinely is a dynamic company, which deals with algorithmic trading is privately held and self-funded, with offices in Singapore, the Netherlands and Cyprus. We specialize in high-frequency and ultra-low latency trading, striving to be among the best trading companies in the world.

To join our team, please send your resume to [email protected].

UPD

Congrats to the winners:

The editorial is available by the following links:

  1. Sakurako's Birthday

  2. Math Test

  3. Party gathering

  4. Long-Awaited Party

  5. Sakurako and Old Dictionary

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

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

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

Hello Codeforces!

We are pleased to invite you all to participate in Codeforces Round 891 (Div. 3), which will start on Aug/07/2023 17:35 (Moscow time).

The format of the event will be like any Div. 3 rounds:

  • 6-8 tasks;

  • ICPC rules with a penalty of 10 minutes for an incorrect submission;

  • 12-hour phase of open hacks after the end of the round (hacks do not give additional points)

  • after the end of the open hacking phase, all solutions will be tested on the updated set of tests, and the ratings recalculated

  • by default, only "trusted" participants are shown in the results table.

We encourage participants with a rating of 1600+ not to create new accounts but to participate unofficially.

Only trusted participants of the third division will be included in the official standings table. This is a forced measure for combating unsporting behavior. To qualify as a trusted participant of the third division, you must:

  • take part in at least five rated rounds (and solve at least one problem in each of them),
  • do not have a point of 1900 or higher in the rating.

Regardless of whether you are a trusted participant of the third division or not, if your rating is less than 1600 (or you are a newcomer/unrated), then the round will be rated for you.

Problems have been created and written by our team: FBI, Skillful_Wanderer, SashaT9 and Pa_sha.

We would like to thank

Good luck!

UPD: There was an error on problem F. We fixed the tests and rejudged solutions . We apologize for that. It only affected a few people whose solutions passes all tests now. Also some hacks were already added to the tests and broke some of solutions.

UPD2: Editorial

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

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