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

Автор __yql0991888__, история, 107 минут назад, По-английски

I remember Codeforces is sponsored by TON, but it's sponsored by Telegram now, but why?

Edit: I noted https://codeforces.me/blog/entry/156620 , but why TON will not be the Codeforces sponsor in the future?

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

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

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

If you have a brute force solution runs 10 seconds, but time limit is 2 seconds, stop thinking the correct solution, go to optimize your brute force solution.

Problem: https://qoj.ac/problem/8616

This problem is weird: it requires tree path addition and tree path XOR sum queries.

If the queries were on a sequence rather than a tree, use this approach and you will get an $$$O(q\sqrt{n}\log n\log V)$$$ solution. By combining this with heavy-light decomposition, we can solve the tree version in $$$O(q\sqrt{n} \log^2 n\log V)$$$ time with a high constant factor, cannot pass the time limit. It's even slower than brute force under these constraints!

Now we think of brute force.

The basic brute force approach is, for two nodes $$$u$$$ and $$$v$$$, find their LCA, and move both $$$u,v$$$ upward toward their LCA, update all the elements on the path. This is slow, isn't it? On modern computers, contiguous memory access is faster than random memory access. So we can use heavy-light decomposition to turn the random accesses into $$$O(\log n)$$$ contiguous segments. Then, with #pragma GCC optimize("O3,unroll-loops") and #pragma GCC target("avx2,sse4.2,avx512f"), so you can get accepted on this problem.

Try it! https://qoj.ac/problem/8616

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

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