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

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

Imagine doing bfs on a 2D $$$n \times n$$$ grid. Your code may look something like this:

import collections
NOT_VISITED, VISITED = 0, 1
n = int(input())
grid = [[NOT_VISITED] * n for i in range(n)]
queue = collections.deque([(0, 0)])
while len(queue):
    x, y = queue.popleft()
    for nx, ny in [(x + 1, y), (x - 1, y), (x, y + 1), (x, y - 1)]:
        if 0 <= nx < n and 0 <= ny < n and grid[nx][ny] == NOT_VISITED:
            queue.append((nx, ny))
            grid[nx][ny] = VISITED
print(grid)

It works in $$$O(n^2)$$$, nothing interesting. But if we write it like this:

import collections
NOT_VISITED, VISITED = 0, 1
n = int(input())
grid = [[NOT_VISITED] * n for i in range(n)]
queue = collections.deque([(0, 0)])
while len(queue):
    x, y = queue.popleft()
    grid[x][y] = VISITED
    for nx, ny in [(x + 1, y), (x - 1, y), (x, y + 1), (x, y - 1)]:
        if 0 <= nx < n and 0 <= ny < n and grid[nx][ny] == NOT_VISITED:
            queue.append((nx, ny))
print(grid)

The code now works in $$$O\left(\dfrac{4^n}{\sqrt{n}}\right)$$$ :skull: :skull: :skull:

Can you figure out why?

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

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

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

Recently beyondpluto created a chrome extension which paints every day in the calendar with the color of the hardest problem solved in that day. You can read about it here: https://mirror.codeforces.com/blog/entry/140881

And I've just realized: that it's the greatest tool for catching streak frauds! Here is the meme depicting what I mean:

Post similar frauds in the comment! And huge thanks to beyondpluto for this extension!

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

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

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

This blog will be useful for all those who never achieved Master but really wants to. Based on my experience, you can achieve Master by doing these steps:

  1. Become GM on your main account

  2. Create an alt and smurf Div.2+ contests until you reach Master.

  3. ...

  4. PROFIT!

Hope it helps, codeforcers!

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

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

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

During the past week I've been working on implementing and optimizing Gauss elimination algorithm for sparse systems of linear equations (SLE). I took 2028E - Alice's Adventures in the Rabbit Hole as a reference: constructed 2e5 linear equations and put them into my solver. And starting from 20s runtime was able to optimize my algorithm to 1s (300847774), comfortably passing intended 2s TL.

Now I wanna try my implementation somewhere else. Can you share some other problems which are solvable by constructing big sparse SLE?

UPD: was able to optimize my implementation to 0.35s on 2028E (link) and crack some other problems. Here is the current statistics of my algorithm. $$$n$$$ is the number of variables, $$$k$$$ is the number of non-zero coefficients in the matrix. I'm still looking for more problems to test!

W:

https://mirror.codeforces.com/contest/1823/problem/F ($$$n = 2e5, k = 6e5$$$, 0.96/2s, 302018850)

https://mirror.codeforces.com/contest/2028/problem/E ($$$n = 2e5, k = 6e5$$$, 0.35/2s, 301505556)

https://mirror.codeforces.com/contest/2032/problem/E ($$$n = 2e5, k = 6e5$$$, 0.78/2s, 301921985)

https://mirror.codeforces.com/contest/2055/problem/C ($$$n = 2e3, k = 4e3$$$, 0.43/2s, 300892471)

https://judge.yosupo.jp/problem/sparse_matrix_det ($$$n = 3e3, k = 1e4$$$, 0.57/10s, 261477)

https://mirror.codeforces.com/contest/1844/problem/G (smart approach) ($$$57$$$ SLE with $$$n = 1e5, k = 2e5$$$, 3.57/5s, 301156684)

L:

https://mirror.codeforces.com/contest/1844/problem/G (straightforward approach) ($$$n = 1e5, k = 3e5$$$, ~3600/5s on caterpillar trees)

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

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

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

The dynamic RMQ problem goes as follows:

Given an array of integers $$$a$$$ of length $$$n$$$ and $$$q$$$ queries of $$$2$$$ types:

  1. $$$l\ r$$$ — find the minimum on $$$a[l..r]$$$
  2. $$$i\ x$$$ — make $$$a_i = x$$$

If the number of updates $$$\gt \gt$$$ the number of queries (which may occur in MO algorithm for example, where we can have $$$O(n)$$$ min queries and $$$O(n\sqrt n) $$$ updates), what is the most efficient way to solve the problem?

We obviously need smth faster than $$$O(\log(n) )$$$ per update (which is achievable with a ton of ways), like $$$O(1)$$$ or maybe $$$O(\log{\log{n} }) $$$.

I though about it for a while but wasn't able to come up even with sublinear solution for querying min while preserving $$$O(1)$$$ update time.

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

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

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

Current rating graph looks like this:

But it should look like this:

MikeMirzayanov, when rating graph will be improved?

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

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

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

How to solve today's C problem if alphabet is not $$$26$$$ characters but rather $$$O(n)$$$? I could only come up with simple offline $$$O(q \sqrt n)$$$ solution using basic MO algorithm. Any ideas?

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

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