Можно ввести несколько слов — все они попадут в требования к поиску. Кроме того, осуществляется поиск по словоформам и, если повезет, по синонимам. Поддерживается поиск по названию, автору и специальный синтаксис запросов. Примеры:

  • 305 — ищет все посты, содержащие 305, найдет посты про Раунд 305
  • andrew stankevich contests — можно писать сразу много слов, будут искаться все
  • user:mikemirzayanov title:сазанка — ищет все посты в названии со словом "сазанка" авторства MikeMirzayanov
  • "vk cup" — можно использовать кавычку, чтобы искать точные совпадения
  • title:educational — искать в названии

Результаты

1.

Complexity

Последнее посещение:  6 лет назад
Зарегистрирован:  10 лет назад
2.
Автор Rhodoks, история, 4 года назад, По-английски
Codeforces Round #810 Editorial Sorry for the late editorial. May this editorial help you. If you have questions, feel free to ask. [problem:1711A] <spoiler summary="hint1."> The minimal weight is at least $1$ since $1$ divides any integer (so $1$ divides $p_1$). </spoiler> <spoiler summary="solution"> Since $k+1$ does not divide $k$, a permutation with weight equal to $1$ is: $[n,1,2,\cdots,n-1]$. </spoiler> <spoiler summary="code"> ~~~~~ #include <bits/stdc++.h> using namespace std; void work() { int n; cin>>n; cout<<n<<' '; for (int i=1;i<n;i++) cout<<i<<' '; cout<<endl; } int main() { int casenum=1; cin>>casenum; for (int testcase=1;testcase<=casenum;testcase++) work(); return 0; } ~~~~~ </spoiler> [problem:1711B] <spoiler summary="hint1."> See the party as a graph. </spoiler> <spoiler summary="hint2."> Divide the vertices into two categories according to their degrees' parity. </spoiler> <spoiler summary="solution"> Let's consider ...
Time complexity is $O(2^9 |n|)$ where $|n|$ is the length of input. , Total time complexity: $O(n)$. , Total time complexity: $O(n+m)$. , Total time complexity: $O(n\log n)$. , Total time complexity: $O(n^2)$.

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

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

3.
Автор Radewoosh, история, 8 лет назад, По-английски
Blogewoosh #1 Hello, codeforces! The community wants so the community gets it! :D Here it is, my very first blog about tasks and algorithms. At the beginning I've decided to post my entries on codeforces, maybe I'll switch to something different if it becomes uncomfortable. To pour the first blood I decided to choose a task from one of the old ONTAK camps. Task's name is "different words" ([you can submit here](https://szkopul.edu.pl/problemset/problem/wTy-sxQCIKry0Ml-6RvM0L78/site/?key=statement)). The statement goes as follows: You are given $n$ words ($2 \leq n \leq 50\,000$), every of length exactly $5$ characters. Each character can be a lowercase letter, an uppercase letter, a digit, a comma... basically, it can be any character with ASCII code between $48$ and $122$ (let's say that $k$ is the number of possible characters). A task is to find all pairs of indexes of words which are $\textbf{really different}$. Two words are $\textbf{really different}$ if they differ at all $5$ corres...
come up with something with $k^3$ in complexity, then it'll probably be multiplied by $n$. $O(k^5)$ is, out to be hard, even if you can come up with something with $k^3$ in complexity , then it'll, Total complexity is something like $O(n \cdot 600 \cdot log(n))$, but we can get rid of the $log

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

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

4.
Автор MikeMirzayanov, 9 лет назад, По-русски
Codeforces: Updates in rating and rounds <img src="/predownloaded/21/a3/21a33b497ee8a34a678befc3f79745eb69a9cf07.png" style="float:right; margin: 0 1em 1em 1em;"/> Hello, Codeforces! It's time for news. I hope you will enjoy! * We reduce the rating bound for the orange color. Thus, now the orange rating (and the _Master_ title) will start from 2100 rating units. * The lower bound of the rating for _legendary grandmasters_ is increased to 3000 rating units. Thus, right now in the community, 14 participants meet this requirement. Real legends! * For rounds like "Div. 2 Only" the upper bound of the rating for official participation is increased. Now everyone whose rating is less than 2100 (i.e., before _masters_) will be able to register for such rounds to participate officially, their rating will be updated based on the results of the round. We do not plan to increase the complexity of Div. 2 rounds. Practice shows that the problems of such rounds are interesting and useful for participants "below the orange". ...
round. We do not plan to increase the complexity of Div. 2 rounds. Practice shows that the problems of, the results of the round. We do not plan to increase the complexity of Div. 2 rounds. Practice, * As an experiment, we plan to host rounds of simplified complexity (Div. 3). In such rounds, the

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

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

5.
Автор Error_Yuan, история, 3 года назад, По-английски
Goodbye 74TrAkToR + Problem A~E: The problems themselves are good and typical A~E. Indeed I like problem D. The pretest for A is a bit weak, and it's not a big problem yet. + Problem F: The problem has an origin. :) See the link: [click](https://www.luogu.com.cn/problem/P9394). The problem in contest is only a weakened version of the one in Luogu. + Problem G: It's said that our great coordinator had not proved the time complexity of the intended solution is correct :) If the authors did, please share it in the editorial. (although this problem is completely beyond my ability :) ) + Problem H: Oh dear [user:74TrAkToR,2023-12-30], could you please OEIS the sequence before you use the "several-integer-input" problem in rounds next time? Anyone who copied the first example and opened [https://oeis.org/A286331](https://oeis.org/A286331) could quickly get the formula. And the problem itself is not so hard imo. Anyway, it should not be used in contest, especially for the last problem. For me pers...
proved the time complexity of the intended solution is correct :) If the authors did, please share it, + Problem G: It's said that our great coordinator had not proved the time complexity of the

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

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

6.
Автор TLE, история, 8 лет назад, По-английски
Linear Recurrence and Berlekamp-Massey Algorithm **#IjustWantContribution** It seems there isn't any blog about Berlekamp-Massey Algorithm around here, so I decided to go on a try. :P Acknowledgement: Hats off to matthew99 for introducing this algorithm. #### What is 'linear recurrence'? Assuming there is a (probably infinity) sequence $a_0,a_1...a_{n-1}$, we call this sequence satisfies a linear recurrence relation $p_1,p_2...p_m$, iff $\forall i \geq m,~a_i=\sum_{j=1}^m a_{i-j}p_j$. (Obviously, if $m\geq n$ any $p$ can do :P) #### How to calculate k-th term of a linear recurrence? For a polynomial $f(x)=\sum_{i=0}^{t} c_ix^i$, we define $G(f)=\sum_{i=0}^{t} c_ia_i$. Obviously $G$ satisfies $G(f)\pm G(g) =G(f \pm g)$. Because $a_i=\sum_{j=1}^m a_{i-j}p_j$, if we let $f(x)=x^m-\sum_{j=1}^m x^{m-j}p_j$, then $G(f)=0$. Also $G(fx),G(fx^2)...=0$. So $G(fg)=0$ (g is any polynomial). What we want is $G(x^k)$. Because $G(f\lfloor x^k/f\rfloor)=0$, then $G(x^k)=G(x^k \bmod f)$. [cut] We can calculate $x^k \b...
)$. Time complexity is $O(m^2\log(k))$ or $O(m \log(m)\log(k))$ (if you use fft etc.)

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

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

7.
Автор Um_nik, история, 2 года назад, По-английски
On AI ruining "solving math problems with computer" You all went crazy. Instead of arguing with every opinion separately, I just want to ask one question: Why are you doing competitive programming? Is it to get to 1600 rating and put it on the resume? If so, please use AI, cheat, and do everything possible to get to 1600 as soon as possible and get the f**k out of this platform. And if you are (not) a normal person and do competitive programming because it is fun to solve problems, do you think it is fun to copy the problem statement into an AI model prompt and then copy the code it spews to submit? And why do you assume that everyone else will do that if there will be such an opportunity? The same goes for cheaters. Yes, some people do not do this as a sport, for fun. Why do you care? I do think that AI is ruining competitive programming. By proxy. And that proxy is all of you who are running around yelling "We will all die, somebody do something about AI". I have seen a couple of comments saying "authors/coordinators must make s...
a better complexity than $O(n^2)$. Why? Instead, we could just make tests for $n \le 100$ to check, better complexity than $O(n^2)$. Why? Instead, we could just make tests for $n \le 100$ to check for

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

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

8.
Автор Um_nik, история, 4 года назад, По-английски
Pro Tips - get them while they are free More tips to use while studying under my tutoring [here](https://um-nik.notion.site/Pro-Tips-8b923b0dc7c94770824bdf4184afc43c). ## Stop caring about the rating Unless there are prizes involved, your position in the standings makes no difference. I can feel awful after winning a contest if I know that I could solve one more problem. Or I can feel OK losing a bunch of rating points knowing that I solved everything I could.  Because rating is just a number. It is highly volatile and it depends on other people, not only on your skill. But solving problems is totally up to you. And you should evaluate yourself not based on some random metric, but on your honest feeling whether you performed up to your expectations. Your sense of self should be under your control, don't get hung up on some imaginary value, you cannot reduce your progress to a single number. ## Don't use more than one account Rating is just a number. Do not be afraid to lose your colour. You’ll get it back in no t...
example of this is guessing solution or complexity from constraints and/or underlying objects. Yes, it is, - What’s the complexity? - Do I understand the problem correctly? - What functions do I need, One very special example of this is guessing solution or complexity from constraints and/or

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

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

9.
Автор MikeMirzayanov, 6 лет назад, перевод, По-русски
Codeforces New Feature: Rewrite Statements in Mashups Hello Codeforces! There is something new for you. It seems that now it will be easier to reuse problems from the archive for educational and other purposes. As you know, problems from past Codeforces rounds can be added to <a href="https://codeforces.me/blog/entry/10099">mashups</a> simply by their codes of the form like <code>1234D</code> (contest ID + problem letter). I myself regularly used this when I taught at Saratov University &mdash; it was very convenient to prepare trainings: problems have expected complexity and topics, there are Russian and English statements, you can see the analysis and many solutions. Because of hacks and uphacks, problems in the archive usually have strong tests. Almost all of them are well-prepared. In addition, with the help of <a href="https://codeforces.me/blog/entry/21912">user lists</a>, you can easily pick up problems for a group of students that they did not solve. <img src="/predownloaded/2f/ec/2fecbf1f7e7a8f8655f0f74576fd1f6dbbc2307...
very convenient to prepare trainings: problems have expected complexity and topics, there are Russian, : problems have expected complexity and topics, there are Russian and English statements, you can see

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

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

10.
Автор EvenImage, история, 7 лет назад, По-английски
A problem collection of ODE and differential technique ##A problem collection of ODE and differential technique *This problem might be well-known in some countries, but how do other countries learn about such problems if nobody poses them.* For those who are interested in well-known problems in China. Thank [user:Elegia,2020-04-23] and [user:djq_cpp,2020-04-23] for developing this technique. Thank [user:tEMMIE.w.,2020-04-23] for reviewing this article. ####[Chain Reaction](http://uoj.ac/problem/50) in UOJ Round 3 By [user:vfleaking,2020-04-23] **Statement** ​ You are given a set $A$, you need to compute $g_{i} = \frac{1}{2} \sum_{j,k}{i-1 \choose j}{i-1-j \choose k} g_jg_k$ where $i-1-j-k \in A$. **Solution** ​ Let the EGF of $g$ be $x(t)$ and EGF of $A$ be $a(t)$. Thus $x'(t)=\frac{1}{2} a(t) x^2(t)+1$. We can solve this equation by D&C and FFT in $O(n\log^2 n)$. But there is a <s>slower</s> solution in $O(n\log n)$. ​ For a polynomial equation $f(x(t))=0$, we can use the Newton's method to solve it. If we find ...
compute $G(u,v)=F(u,v)^k$. If we use FFT directly, the time complexity is $O(k^2 \log k)$, which might be, ')^j$ for $i+j\leq k$. So the time complexity is $O(k^2 nk )$. It may perform well when $k$ is, (n \log n)$ time, the we have the time complexity $T(n)=T(n/2) + O(n\log n)$,which is $O(n\log n)$., )$. If we use FFT directly, the time complexity is $O(na^2 \log n)$. Since the degree of $P$ is not

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

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

11.
Автор Ari, история, 6 лет назад, По-английски
On Problems vs. Questions in Competitive Programming: My solution _TL;DR: The most reasonable solution to the problems vs. questions debate is to use none of the currently accepted terms._ As we have seen many times, particularly over the past few days, the task of assigning a label to the activities we perform as competitive programmers is a bigger problem than one might think at first. Time and time again we have seen people questioning what we should call our activities, often to the point of eliciting some rather harsh responses. To give some context to this discussion, I will focus on two of the terms that members of the community have adopted over the years, _problems_ and _questions_. (Sorry task lovers! You have some fine points for sure, we frequently talk about subtasks rather than subproblems or subquestions after all :P). All quotations here are posted anonymously, but if you want to claim ownership of one of them or have one removed, just tell me. If you are familiar with the arguments, feel free to skip to the final section of the...
exist even algorithmic questions like “what’s the complexity of Dijkstra algorithm?” but problems

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

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

12.
Автор -is-this-fft-, история, 5 лет назад, По-английски
[Tutorial] Collection of little techniques #### Introduction There are a number of "small" algorithms and facts that come up again and again in problems. I feel like there I have had to explain them many times, partly because there are no blogs about them. On the other hand, writing a blog about them is also weird because there is not that much to be said. To settle these things "once and for all", I decided to write my own list about about common "small tricks" that don't really warrant a full tutorial because they can be adequately explained in a paragraph or two and there often isn't really anything to add except for padding. This blog is partly inspired by [user:adamant,2022-03-15]'s [blog](48417) from a few years ago. At first, I wanted to mimic adamant's blog structure exactly, but I found myself wanting to write longer paragraphs and using just bolded sentences as section headers got messy. Still, each section is short enough that it would not make much sense to write separate blogs about each of these things. A...
does not allow $O(n^2)$ or similar space complexity. This includes making $n$ bitsets of length $n$., one that's present. The time complexity of doing that in $O(\sqrt n)$. , sorted in a certain magical order, we get $O(n \sqrt n \log n)$ complexity. Unfortunately, this is too, this for each $x$ and you have an unproven expected $O(n)$ complexity. , with only $O(\sqrt m)$ elements, which can be lead to a better complexity in many cases., #### 7. $O(n^2)$ complexity of certain tree DPs, ,$$ so the complexity of this part of the algorithm is $O(n \log n)$., The algorithm has exactly the form as seen above, thus its complexity is $O(C \log C)$, where $C, The complexity of this is $O(n^2)$ (this is not obvious: when I first saw it I didn't realize it, ]$. With ideas similar as above, we can show that this has the complexity $O(n^2)$ as well., complexity comes to $O(n^2)$.

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

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

13.
Автор ATSTNG, история, 7 лет назад, перевод, По-русски
[Tutorial] Matroid intersection in simple words **[This article is also available in [Russian](https://codeforces.me/blog/entry/69287?locale=ru)]** Hello, CodeForces. I think that matroids are beautiful and powerful concept, however, not really well known in competitive programming. I’ve discovered matroids at 2019 Petrozavodsk Winter Training Camp. There was a problem that clearly cannot be solved using usual techniques I knew, editorial for this problem was just these three words “just matroid intersection”. Back then it took me more than 2 days of upsolving to find all the information and details I need and implement solution that gets Accepted on this. And it took way longer to actually understand why does it work and exactly how does it work. (I still hesitate in some details.) Of course, it is not hard to google up all the definitions and some related articles, but in my opinion they all are focused more on mathematical part of theory, strict proofs in some not really obvious but short ways, and observing only ke...
Implementation and complexity, oracles ------------------, Turns out this optimization actually improves complexity. In total we need $\mathcal{O}(\sqrt{r

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

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

14.
Автор Tony2_CF, история, 11 месяцев назад, По-английски
The Time Complexity Lower Bound for Segment Tree Beats is log^2 Original Post: https://jiry-2.blog.uoj.ac/blog/1404 The following content is translated by Gemini 2.5 Pro. ## Part 1: Introduction to the Hacking Method ### How to Map the Hack Sequence to a Segment Tree First, we are given a Hack sequence of length $len$. After $O(1)$ range addition operations and $\Theta(\log len)$ global $\text{chkmax}$ operations, this sequence becomes a cyclic shift (rotation) of the original sequence. Since a cyclic shift does not affect our range addition and global $\text{chkmax}$ operations (we can simply shift the indices for the range addition accordingly), we can consider the sequence as unchanged. If we have such a sequence, let $len=n^{\frac{1}{3}}$, and place such a sequence at intervals of $n^{\frac{2}{3}}$. Each sequence corresponds exactly to a segment tree interval. A subtree of size $n^{\frac{2}{3}}$ contains exactly one such segment tree interval. For the Hack sequence, the range addition operations are performed one by one on eac...
The Time Complexity Lower Bound for Segment Tree Beats is log^2, this back then and didn't even try to understand the time complexity.

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

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

15.
Автор shiven, история, 2 года назад, По-английски
A summary of what passes for an Indian ICPC Contest, apparently The online round for the India’s ICPC was held on 23rd. And also a week before that. The first time around, the organisers tried debuting a self-hosted DOMjudge instance. That didn’t go too well, so a recontest was scheduled on CodeChef. If you’re not too familiar with the Indian ICPC system — this online prelims is used to select teams that can participate in the offline regionals. From a single university, usually approx. 2 teams (for the top unis) or 1 (for almost all unis that aren’t in top-15) qualify. As you could guess, it’s quite easy for good teams to miss a spot. Looking at the first contest’s rankings, teams from rank 2 to 100+ all had 4 solves. Owing to severe system issues in the first contest, the time penalties weren’t too reliable differentiators, leading to the recontest this Saturday. In hindsight, we forgot to be grateful for the problemset and reliable testcases the first time. I’m sure everyone agrees that the basic requirements (ignoring all other stuff...
-cases enforce any time complexity (given that the model solution was itself guilty of being the, -polynomial complexity. They probably discussed this and realised that the earlier faster solution, To add to that, the solution is presented in a way that pretends that the complexity is *obviously

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

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

16.
Автор PinkieRabbit_buster, 3 года назад, По-английски
PinkieRabbit Cheated in Div. 1 Contest on Apr 27 I am writing to report an incident of cheating by PinkieRabbit during the recent contest 1965 on Codeforces. **PinkieRabbit asked help about problem D from others during the contest,** which is definitely against the contest rules. I have attached the evidence of the cheating behavior in the appendix, please read it. This evidence clearly shows the communications PinkieRabbit had with another person during the contest. It is a contest recording video published after contest by himself. As a former fan of PinkieRabbit, after seeing this video, I was shocked by how dishonest PinkieRabbit was. I believe such actions undermine the integrity of the competition and the platform as a whole. [user:win114514,2024-05-05] cheated by grouping up in contest 1905, finally punished by skipping. Therefore, I respectfully request that Codeforces take appropriate action against PinkieRabbit to maintain the fairness of the contests on Codeforces. He only cheated in one problem this round, so I sugg...
P:Can this be enumerated? (Will the time complexity pass this problem?)

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

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

17.
Автор maomao90, 3 года назад, По-английски
Editorial for Hello 2024 ### [problem:1919a] Author: [user:maomao90,2024-01-02] <spoiler summary="Hint 1"> When does the game end? </spoiler> <spoiler summary="Solution"> Depending on whether the player chooses to exchange wallets with their opponent on step $1$, $1$ coins will be removed from either the opponent's wallet or the player's wallet. This means that if either of the players still has remaining coins, the game will not end as at least one of the choices will still be valid. The only way that the game ends is when both players have $0$ coins. Since each operation decreases the total amount of coins by exactly $1$, the only way for Alice to win the game is if $a + b$ is odd. </spoiler> <spoiler summary="Code"> ~~~~~ #include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { int a, b; cin >> a >> b; if ((a + b) % 2 == 0) { cout << "Bob\n"; } else { cout << "Alice\n"; } } ...
$\texttt{B}$ and the left endpoint of the right node is $\texttt{A}$. The final timecomplexity is, hash, the time complexity is $O(n^2)$. Well-optimised bitset code with time complexity of $O(\frac, minimum queries on ranges $[1, a_i - 1]$ and $[a_i, n]$. The final time complexity is $O(n\log n

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

Разбор задач Hello 2024
  • Проголосовать: нравится
  • +760
  • Проголосовать: не нравится

18.
Автор Radewoosh, 8 лет назад, По-английски
Blogewoosh #3 Hello, codeforces! This time I've decided to choose a task from my own contest which took place last April and was known as the Grand Prix of Poland. If you want to write this contest virtually in the future, then consider not reading this blog. If you've participated in this contest and maybe even solved this task, then anyway I recommend reading it, cause this task has many very different solutions, each of them being very interesting (in my opinion). It's also a reason why this blog is longer than previous ones. I'll write about task C "cutting tree" (not uploaded to the ejudge yet :/). The statement goes as follows: You are given a tree with $n$ vertices ($1 \leq n \leq 2 \cdot 10^5$). The task is to calculate $f(k)$ for each integer $k$ from the range $[1, n]$ where $f(k)$ is defined as the maximum number of connected components of size $k$ which we can "cut off" from the tree. A connected component of size $k$ is a set of $k$ vertices such that it's possible to traverse ...
one with the biggest subtree in complexity and it will amortize. And here we're doing this same thing, searches, so the formal complexity will decrease to $O(n \cdot \sqrt{n \cdot \log(n)})$., It turns out that this solution works in this same complexity but is substantially faster., To solve this problem without $\sqrt{n}$ factor in complexity we need to use again the fact that $k, complexity is $O(n^{1.5} \cdot \log(n))$ ($O(n)$ because this is the time complexity of calculating

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

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

19.
Автор lotusblume, 16 месяцев назад, По-английски
Worst-Case Graphs for Maximum Flow Algorithms Maximum flow algorithms are known to perform significantly better in practice than their worst-case time complexities would suggest. So in this blog, I will present graphs on which the following maximum flow algorithms actually achieve their worst-case running time: | Algorithm | Time Complexity | | ----------------------- | ------------------------------ | | Ford-Fulkerson with DFS | $\mathcal{O}\big(m^2 \cdot U)$ | | Edmonds-Karp | $\mathcal{O}\big(n \cdot m^2\big)$ | | Dinic | $\mathcal{O}\big(n^2 \cdot m\big)$ | | DFS with Scaling | $\mathcal{O}\big(m^2 \cdot \log(U)\big)$ | | Dinic with Scaling | $\mathcal{O}\big(n \cdot m \cdot \log(U)\big)$ | | Most Improving Augmenting Paths | $\mathcal{O}\big(m \cdot \log(U) \cdot (m + n \cdot \log(n))\big)$ | | FIFO Preflow Push | $\mathcal{O}\big(n^3\big)$ | | Highest-Label Preflow Push | $\mathcal{O}\big(n^2 \cdot \sqrt{m}\big)$ | Here and in the rest of this blog: - $n =$ number of vertices, ...
| Algorithm | Time Complexity

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

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

20.
Автор jiry_2, история, 9 лет назад, По-английски
A simple introduction to "Segment tree beats" Hi, I’d like to introduce a simple trick about segment tree in this blog as I promised in [this comment](http://codeforces.me/blog/entry/54750?#comment-387957). Sorry for the long delay, as a sophomore in Peking University, I've just finished a tired semester and a painful final exam. And now I finally have enough time to do a simple introduction to this interesting algorithm. It may be a huge project for me since my English is not good. I think I will finish this blog in several steps and I will try to finish it as soon as possible :) In China, all of the 15 candidates for the Chinese National Team are asked to write a simple research report about algorithms in informatics Olympiad, and the score will be counted in the final selection. There are many interesting ideas and algorithms in these reports. And I find that some of them are quite new for competitors in CF although they are well known in China from the final standings of some recent contests. For example, In the last co...
$\Phi(x)$, we know that the time complexity is $O(n \log n)$., $\Phi(x)$, we prove that the time complexity is $O(n \log^2 n)$., also has a very nice time complexity. (I will give out the proof of the time complexity in the third, although there is a flaw about time complexity. [user:xyz111,2018-01-24] gave me a lot of inspiration, ### Part 3. The time complexity, In this part, I will give the proofs of the time complexity of Part 1 Task 1 and Part 1 Task 2. You, It can be solved in $O(n \log^2 n)$ and I could not proved the exact time complexity yet, maybe It, It can be solved in $O(n \log^2 n)$ and if there are $k$ arrays, the time complexity will be raised, It’s time complexity is the same as Task 2., [user:gepardo,2018-01-27] has given a clear proof to show the time complexity of this problem is $O, ] == min_value[node]`. And we can find that the time complexity of this segment tree is also $O(n \log, complexity carefully.

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

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

21.
Автор -is-this-fft-, история, 6 лет назад, По-английски
How to ask for help in PM There was a blog today with a similar title, and although it was (I think, not really sure as I didn't get a good look) some kind of satire/joke blog, I wanted to post some serious advice about things I (don't) like to see when people are PMing me. However I decided that this wouldn't be in the spirit of the blog and decided to make a separate blog. And now that blog is deleted anyway. While it's not a bad thing to write messages to more experienced users, most people who write me do things that make them very difficult to deal with. These are my opinions, but somewhy I feel that many reds will agree. Some things here feel silly to write because they are so obvious. But I'm only writing them because people regularly mess them up. [cut] $~$ ####Use punctuation and spelling. There are some [very simple rules](https://codeforces.me/blog/entry/82186#comment-689836) that make your messages infinitely more readable. I find it especially strange when many of these messagers call...
(maybe exponential complexity) (if you can, you may also just copy someone else's solution) > - Write a, - you know what complexity is and - you read/print input efficiently (`sync_with_stdio` and

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

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

22.
Автор Radewoosh, история, 8 лет назад, По-английски
Blogewoosh #4 Hello, codeforces! It's time to continue the series of Polish tasks. I've decided to write about my own task one more time. Its name is "cook" ([you can submit here](https://szkopul.edu.pl/problemset/problem/9NFtPM59qGWa7wdn570ifuP0/site/?key=statement)). The task isn't very hard, but it uses cute (in my opinion) trick. The statement goes as follows: There is a cook in a restaurant. He has $n$ ($1 \leq n \leq 10^6$) orders which he must fill. Every order is a piece of paper, and all orders are speared on a spindle (sharp stick with pierced pieces of paper) in a fixed order which cannot be changed. Normal cook would just take orders one by one from the top of the spindle and fill them in this order, but the cook in this task has supernatural cooking powers and can combine orders to fill them faster. In particular, if at some moment there are $k$ out of $n$ orders still on the spindle, he can choose one of three options: $---$ He can take the topmost piece of paper and fill this...
$O(n \cdot (n+e))$ complexity, so it's too slow. To speed it up we need an easy observation, is the size of a column). Has the complexity just increased to $O(n \cdot \log^2(n))$? No! The main, options. This solution has $O(n \cdot (n+e))$ complexity, so it's too slow., works in $O(n \cdot \log(n))$ time complexity, whenever cook's energy is greater than $20$ (including

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

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

23.
Автор -is-this-fft-, 5 лет назад, По-английски
[Tutorial] Proving the inverse Ackermann complexity of Union-Find #### Introduction Most of us are familiar with the union-find data structure and the two optimizations one can do on it: _union by rank_ and _path compression_. Most tutorials will introduce these methods and state that if both optimizations are used, the complexity will be $\mathcal{O}((n + m) \alpha(n))$. Here, $n$ and $m$ are the number of vertices and queries respectively. What is $\alpha$? Generally, we are told that $\alpha$ is some mysterious function that grows very slowly: $\alpha(N) < 5$ where $N$ is the number of subsets of particles in the observable universe and whatnot. What it is is usually not clarified very much. And there is typically no proof (or intuition and other such justifications) as to why the complexity is like that: usually we're told that the complexity analysis is quite long and complicated. At the time of writing, both [cp-algorithms](https://cp-algorithms.com/data_structures/disjoint_set_union.html) and [Wikipedia](https://bit.ly/3EvnzrI) are like th...
[Tutorial] Proving the inverse Ackermann complexity of Union-Find, $\mathcal{O}((n + m) \log \log n)$ complexity, and if we don't, we get $\mathcal{O}((n + m) \log n, $\mathcal{O}(\alpha(n))$, the number of find-edges and thus the complexity of the algorithm comes to, get $\mathcal{O}(m + n \sqrt{\log n})$ complexity, and if we don't, we get $\mathcal{O}(m + n \sqrt{n, ours will have inverse Ackermann complexity in the worst case. Here, "similar to ours" means:, that if both optimizations are used, the complexity will be $\mathcal{O}((n + m) \alpha(n))$. Here, the complexity of the union-find data structure, in the article a lower bound is also calculated. I, these methods and state that if both optimizations are used, the complexity will be $\mathcal{O}((n + m, upper bound on the number of find-edges and therefore complexity. At this point I want to remind you, #### Union-by-rank and its complexity, **Observation 2.** The time complexity of union-find with the union-by-rank rule is $\mathcal{O}(n, **Theorem.** The complexity of union-find with path compression and union-by-rank is $\mathcal{O, - How does one even analyze the time complexity of path compression — it seems quite chaotic, After seeing this complexity and proof, one may think that the Ackermann function is just some, Now we will attack the time complexity of union-find if both union-by-rank and path compression are, The complexity of the algorithm hinges on the number of find-edges, because that is the number of, The total number of find-edges, and also complexity, is $\mathcal{O}(m + n \log^* n)$.

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

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

24.
Автор Errichto, 6 лет назад, По-английски
Matrix Exponentiation tutorial + training contest tl;dr &mdash; video tutorial https://www.youtube.com/watch?v=eMXNWcbw75E and codeforces GYM training https://codeforces.me/gym/102644 (register by finding this contest in GYM instead of using the link directly) video editorial: [part 1 (ABCDEF)](https://www.youtube.com/watch?v=kQuCOFzWoa0) and [part 2 (GHI)](https://www.youtube.com/watch?v=RA_SpxP2t54) codes to all 9 problems: https://github.com/Errichto/youtube/tree/master/matrix-exponentiation Prerequisites: binary exponentiation and iterative dp (you don't need to know matrices) The youtube tutorial ([link](https://www.youtube.com/watch?v=eMXNWcbw75E)) focuses on intuition and graph-like visualization . Or, if you prefer, below is a shorter (less detailed) text tutorial instead. You can practice by solving a set of 9 educational problems in GYM https://codeforces.me/gym/102644. ABCD are easy, EF medium, GHI are hard. If you are stuck, see hints below or watch the full solution analysis &mdash; [part 1 (ABCDEF)](https:...
The total time complexity is $O(s^3 \cdot \log n)$ where $s$ is the matrix size (also called

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

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

25.
Автор Radewoosh, история, 8 лет назад, По-английски
Blogewoosh #7 Hello, codeforces! Long time no see, right? So maybe it's a good idea to try to return to my blogs slowly. This time the blog will be about a trick, which usually isn't necessary to solve a task, but can be useful to make implementation much more comfortable. Let's look at [this](https://codeforces.me/contest/932/problem/F) problem. It is about some DP on a tree in which we have to use convex hull trick to improve the complexity. The task requires merging two convex hulls with "smaller to bigger" trick. I recommend you to read the statement before reading the rest of the blog (and the [editorial](https://codeforces.me/blog/entry/57796) if you don't know how to solve it). [cut] $ $ So, how to merge two convex hulls? If we keep them in something like the set from C++, then we can just take every element from the smaller one and try to add it to the bigger one. Unfortunately, adding one element in this way requires some ifology and care. It's hard to implement it, especiall...
a tree in which we have to use convex hull trick to improve the complexity. The task requires, convex hull trick to improve the complexity. The task requires merging two convex hulls with "smaller, . As we still care about the complexity and want to have very few convex hulls in each node (node of, But we still have to care about the complexity. So, here comes [user:mnbvmar,2019-05-28] with his, The complexity of recalculations is $O(n \cdot \log(n))$ (or $O(n \cdot \log^2(n))$) in total. On

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

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

26.
Автор Phantasmagorias, история, 5 лет назад, По-английски
Codeforces Round #745 Editorial I'm very sorry about all the inconvenience, and I would like to bear the blame. Much thanks to those who help me prepare this round. It's not their fault. And much thanks to your participation. [problem:1581A] ------------------ idea: [user:interlude,2021-09-30] preparation: [user:CQXYM,2021-09-30] tutorial: [user:CQXYM,2021-09-30] Assume a permutation $p$, and $\sum_{i=2}^{2n}[p_{i-1}<p_i]=k$. Assume a permutaion $q$, satisfying $\forall 1 \leqslant i \leqslant 2n, q_i=2n-p_i$. We can know that $\forall 2 \leqslant i \leqslant 2n,[p_{i-1}<p_i]+[q_{i-1}<q_i]=1$. Thus,$\sum_{i=2}^{2n}[q_{i-1}<q_i]=2n-1-k$, and either $p$ should be counted or $q$ should be counted. All in all, the half of all the permutaions would be counted in the answer. Thus, the answer is $\frac{1}{2}(2n)!$. The time complexity is $O(\sum n)$. If you precalulate the factors, then the complexity will be $O(t+n)$. ----- <spoiler summary="solution"> ~~~~~ #include<stdio.h> int f[100001]; int m...
a fixed $w$, so the total complexity is $O(nq)$., cartesian tree. The time complexity is $O(n^2m^2k)$, space complexity is $O(nmk)$. However, it's, dynamic programming with the time complexity $O(n^2)$., in the answer. Thus, the answer is $\frac{1}{2}(2n)!$. The time complexity is $O(\sum n)$. If you, sums. The time complexity is $O(\sum n^2m^2)$. When we enumerated the upper edge and the lower, the array and add the contribution to the array. The algorithm works in the timecomplexity of $O(nm, the total complexity is $O((n+q)logn)$., transform a problem with limit $m$ to $\frac{m}{2}$, so the time complexity is $O(n \log n \log m)$., The time complexity is $O(t)$., Thus the intended time complexity is $O(m\sqrt{m})$ and the intended memory complexity is $O(n + m)$., complexity only when we are calculating the dp state of their LCA, the total timecomplexity is $O(n^2)$.

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

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

27.
Автор YouKn0wWho, 4 года назад, По-английски
[Tutorial] Common Mistakes in Competitive Programming and How to Avoid Them One thing is for sure. You do make mistakes. I also make miskates and that's what makes us human. But what we can surely do is &mdash; to try to minimize the errors that we make throughout our life. I have compiled some of the mistakes that I made in my early Competitive Programming phase. I also mentioned how to avoid them. Also, in most cases, I will give you a chance to find out what the bug 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 C++ as it is the most used language for CP. **So, if you are new to CP, stick with me as you might don't wanna repeat the mistakes that I made when I was a beginner.** #### Mistake 1 Check out the following code: <spoiler summary="Code"> ~~~~~ #include<bits/stdc++.h> using namespace std; int main() { int a = 1000'000'000,b = 1000'000'000; long long product = a * b; cout << product << '\n'; return 0; } ~~~~~ </spoiler> The outp...
Because of `unordered map`! The worst-case time complexity of our code is, Nope! The complexity is actually $O(n^2)$., The time complexity of this solution is clearly $O(n \, \log{n})$, right?, What is the time complexity of this solution?, What is the time complexity of this?, Why? Because the time complexity is logarithmic in the size of the container + linear in the number

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

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

28.
Автор zscoder, история, 10 лет назад, По-английски
[Tutorial] Non-trivial DP Tricks and Techniques Hi everyone! Today I want to share some DP tricks and techniques that I have seen from some problems. I think this will be helpful for those who just started doing DP. Sometimes the tutorials are very brief and assumes the reader already understand the technique so it will be hard for people who are new to the technique to understand it. Note : You should know how to do basic DP before reading the post DP + Bitmasks ------------------ This is actually a very well-known technique and most people should already know this. This trick is usually used when one of the variables have very small constraints that can allow exponential solutions. The classic example is applying it to solve the Travelling Salesman Problem in $O(n^{2} \cdot 2^{n})$ time. We let $dp[i][j]$ be the minimum time needed to visit the vertices in the set denoted by $i$ and ending at vertex $j$. Note that $i$ will iterate through all possible subsets of the vertices and thus the number of states is $O(2^{n} \cdo...
(in $O(K^2)$ or $O(K\log K)$ with FFT, but that doesn't really change the complexity since the, and this can reduce your time complexity and memory complexity., step by step, using at most $\log A$ steps. Thus, the total time complexity is $O(n^2\log A)$, which, This will give us a complexity of $O(An)$, which is clearly insufficient.

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

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

29.
Автор antontrygubO_o, история, 7 лет назад, По-английски
On problemsetting 2 [Previous part](https://codeforces.me/blog/entry/70178) Hi there again! Previous part with opinions of some amazing problemsetters turned out to be interesting for you, so I decided to gather some more opinions :D. I really hope that this post will help someone in their problemsetting future! #### When and how did you start problemsetting? [user:300iq,2020-01-11]: April, 2017 [user:maroonrk,2020-01-11]: In 2015 Summer, I hold the first contest with friends at high school club. It was a local Japanese contest. [user:Radewoosh,2020-01-11]: In high school, so probably for 5 years. I was creating problems for other people from my school as my teacher told me that it's a completely different point of view. [user:voidmax,2020-01-11]: It was 3 years ago. I was on plane and I didn't have a clue what to do in my free time. Then I realized that I can try myself in problemsetting. Later I created first and one of my favorite problem ([problem:963B]). I was full of inspiration a...
[problem:1131G] This task really shines when you are finding solution with complexity $O(m)$. I

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

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

30.
Автор platelet, 3 года назад, По-английски
CodeTON Round 5 Editorial ### [problem:1842A] <spoiler summary="Tutorial"> Let's view it as when monsters $x$ and $y$ fight, their health changes into $\max(x-y,0)$ and $\max(y-x,0)$ respectively. So any monster with $0$ health is considered dead. Therefore, a player loses when the health of his monsters are all $0$. Notice that $\max(x-y,0)=x-\min(x,y)$ and $\max(y-x,0)=y-\min(x,y)$. Therefore, after each step, the sum of the health of monsters decrease by the same amount for both players. Therefore, we only need to know $\sum a_i$ and $\sum b_i$ to determine who wins. If $\sum a_i > \sum b_i$, Tsondu wins. Else if $\sum a_i < \sum b_i$, Tenzing wins. Else, it is a draw. </spoiler> <spoiler summary="Code"> ~~~~~ #include <iostream> using namespace std; int main() { ios::sync_with_stdio(false), cin.tie(nullptr); int T; cin >> T; while (T--) { int n, m, a[50], b[50]; long long sumA = 0, sumB = 0; cin >> n >> m; for (int i = 0; i < n;...
Ignoring time complexity for now, how do we calculate the answer? The, to calculate the cost and solution for $b_1=x$ in $O(\sum r_i-l_i+1)$ time complexity. Then, The Method of Four Russians can also be used to achieve $O(n)$ time complexity. Divide the sequence, Time complexity analysis: $\sum r_i-l_i+1=(\sum r_i-l_i)+m$. If the sum of adjacent parts is $\leq, Time complexity is $O((n+k)\log k)$., Time complexity: $O(n)$ per test case. , Use a Disjoint Set Union to query the smallest $i\ge l$ such that $cnt_i\ne 0$. The timecomplexity, complexity is $O(n^2)$.

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

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

31.
Автор Balajiganapathi, история, 11 лет назад, По-английски
ICPC Regionals — The Chennai flood and the Asia Director Background ---------- One of the regionals in India was scheduled to be held at [Hindustan University](http://icpc.hindustanuniv.ac.in/) at Chennai on December 17 &mdash; 18, 2015. Unfortunately Chennai was stuck by a [natural disaster](https://en.wikipedia.org/wiki/2015_South_Indian_floods). The entire south India received heavy rainfall and hence there was a lot of flooding at many places including Chennai around that time. Atleast 347 people died in the state of Tamil Nadu (where Chennai is located). The damage due to the floods overall in south India is estimated to be atleast USD 3 Billion. It is the costliest flood in 2015. Ofcourse, due to this the Chennai regionals was postponed. I think everyone here will agree that this was an unexpected, unprecedent situation and hence it was entirely understandable that the regionals was postponed. The Blog post ------------- Dr. C J Hwang is the ICPC Asia director. In response to the above postponement he posted a blog article...
the complexity of calculating Asia site scores prevent us from any other solutions."_

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

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

32.
Автор Xellos, история, 11 лет назад, По-английски
Codeforces Round #333 — editorial ### Hints: [div2A](#div2A): Try conversions between bases. [div2B](#div2B): Solve a simpler version of the problem where $A_{i+1} \neq A_i$ for all $i$. [div1A](#div1A): What are the shortest paths of the vehicles? what's the shorter of those paths? [div1B](#div1B): Forget about the ceiling function. Draw points $(i,A[i])$ and lines between them &mdash; what's the Lipschitz constant geometrically? [div1C](#div1C): Some dynamic programming. Definitely not for the exp. score of one person &mdash; look at fixed scores instead. [div1D](#div1D): Compute $dif(v)$ in $O(N)$ (without hashing) and then solve the problem in $O(N^2)$. You need some smart merges. [div1E](#div1E): Can you solve the problem without events of type 1 or 2? Also, how about solving it offline &mdash; as queries on subsets. ![ ](https://i.imgur.com/bnWmD60.png) ### <a name="div2A"></a>Div. 2 A: Two Bases ------------------------------------ It's easy to compare two numbers if the same bas...
(\log{Q})$ and the time complexity is $O((N+Q)k\log{Q})$., , but $O(N \log N )$. The time complexity is therefore $O(N\log{N}\sigma)$. However, the same is, Bonus 2: Can you get rid of the logarithm in the time complexity?, In summary, time and memory complexity: $O(N^2)$., The second part of the complexity, $O(Qk)$ time, is spent by copying the values of $s(m)$ first, The total time complexity is $O(NQ)$, memory $O(N)$., This only needs a constant number of operations per each $A_i$, so the time complexity is $O(N, To conclude, the time complexity is $O((N+Q)k\log Q)=O(qk\log q)$ and since we don't need to

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

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

33.
Автор Radewoosh, история, 5 лет назад, По-английски
My own algorithm — offline incremental strongly connected components in O(m*log(m)) Hello Codeforces! As all of you know, there are so many known algorithms named after people who invented them &mdash; from the easiest ones, like Dijkstra, to the harder ones, like Berlekamp–Massey algorithm. These algorithms were innovative when they were invented, so of course, it's good that they are named after their inventors. But, today, I've seen a blog about the solution to the problem "compute LCS of two strings in time $O((n + k) \cdot \log(k))$, where $n$ is the sum of lengths of the strings, and $k$ is the number of pairs of matching positions in them". To be honest, it a bit pissed me off that even this algorithm is named after its creators. Is it ok to name the solution to every possible problem after its author? I won't judge it. Anyway, I want my very own Radecki algorithm, so let me give it a try. If anyone has ever heard about it &mdash; it's cool. Let me know, and it'll be just another helpful blog on Codeforces. Let's imagine the following problem: there is...
$s$. We want to split recursively somehow, but how to do it to keep good complexity? It turns out

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

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

34.
Автор twosquares, 11 месяцев назад, По-английски
Good Bye 2025 Editorial We'd like to thank you all for participating in the contest, and hope you enjoyed it. Any feedback would be appreciated! <!-- You lost the game. --> <spoiler summary="Rate the contest"> - Great contest: - Good contest: - Average contest: - Bad contest: </spoiler> --- <spoiler summary="Did Franklin (from problem D) succeed in massacring a village of innocent elves like Frieren and Dilhan (from problem E)?"> The official lore is that he got lost in a forest of oddly colored Christmas trees (from problem F) and decided instead to write this editorial. </spoiler> <!-- ########### --> <!-- #PROBLEM A# --> <!-- ########### --> <h2>[problem:2178A]</h2> <spoiler summary="Did you like the problem?"> - Great problem: - Good problem: - Average problem: - Bad problem: - Did not solve: ...
chord (without caring about complexity)

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

Разбор задач Good Bye 2025
Теги sus
  • Проголосовать: нравится
  • +697
  • Проголосовать: не нравится

35.
Автор Errichto, 5 лет назад, По-английски
[Tutorial] Square Root Techniques _This is my 100th CF blog!_ This is a list of techniques with $O(\sqrt n)$ time complexity. Watch the lecture https://youtu.be/BJhzd_VG61k, with timestamps! 1. Square root decomposition &mdash; split the sequence into blocks of fixed size. 2. Splitting objects (e.g. vertices) into light and heavy. 3. Square root decomposition by the time of queries & rebuilding the structure. 4. Mo's algorithm &mdash; processing queries in proper order and updating the answer by erasing/inserting new elements. https://cp-algorithms.com/data_structures/sqrt_decomposition.html 5. Strings &mdash; if the sum of lengths is $S$ then there are at most $\sqrt{S}$ distinct lengths. 6. Birthday paradox & baby-step giant-step. See P4 and P6 [here](https://codeforces.me/blog/entry/95571), and see https://cp-algorithms.com/algebra/discrete-log.html. P1. [problem:398D] P2. [problem:220B] P3. <s>[problem:86D]</s> (actually, skip this one because it's boring) P4. Count triangles in a graph, i....
This is a list of techniques with $O(\sqrt n)$ time complexity. Watch the lecture https://youtu.be

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

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

36.
Автор parveen1981, история, 6 лет назад, По-английски
I compiled a list of almost all useful blogs ever published on Codeforces [update: till 09.06.2021] <h3 style="color:red">If there are any blogs that I have missed, please tell in the comment section. Thank you.</h3> # Mathematics Stuff - [Number Theory in Competitive Programming [Tutorial]](https://codeforces.me/blog/entry/46620) - [Number of points on Convex hull with lattice points](https://codeforces.me/blog/entry/62183) - [FFT, big modulos, precision errors.](https://codeforces.me/blog/entry/48465) - [Number of ways between two vertices](https://codeforces.me/blog/entry/19078) - [Mathematics For Competitive Programming](https://codeforces.me/blog/entry/76938) - [FFT and NTT](https://codeforces.me/blog/entry/19862) - [Burnside Lemma](https://codeforces.me/blog/entry/51272) - [Number of positive integral solutions of equation 1/x+1/y=1/n!](https://codeforces.me/blog/entry/76836) - [On burnside (again)](https://codeforces.me/blog/entry/64860) - [Simple but often unknown theorems/lemmas/formula? Do you know?](https://codeforces.me/blog/entry/55912) - [Probabili...

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

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

37.
Автор PrinceOfPersia, 12 лет назад, По-английски
Algorithm Gym :: Data structures Today I want to introduce you some very very useful data structures. In this lecture, we are trying to improve your data structures skills, stay with us and click on **read more**. [cut] Important data structures : Trees ----- Trees are one of the most useful data structures.A tree is a connected-acyclic graph.There are too many types of trees, like : rooted trees, weighted trees, directed trees, tries, etc. Partial sum ----------- There are two types of problems solvable by partial sum. 1.Problems which you are asked to answer some queries about the sum of a part of elements (without modify queries). Solution of all of this problems are the same. You just need to know how to solve one of them. Example : You are asked some queries on an array $a_1,a_2,...a,_n$. Each query give you numbers $l$ and $r$ and you should print $a_l + a_{l+1} + ... + a_r$ . Solution : You need to build another array $s_1, s_2, ..., s_n$ which $s_i = a_1 + a_2 + ... + a_i$ ...
time complexity would be $O(n.log^2(n))$ . (One $log$ is for inserting)., So time complexity would be $O(n.log(n))$ ., The time complexity is good because for each tool, we take and put it in an other box at most $log

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

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

38.
Автор Monogon, 4 года назад, По-английски
[Tutorial] Supporting Priority-Queue-like Undoing on DS _Good morning!_ In this blog, I will present an online algorithm that can perform priority-queue-like undoing on a data structure, given a few assumptions. I will also present and solve a generalization of that problem. For context, I highly recommend reading this blog that shows how to solve the easier problem of queue-like undoing. That blog gave me the inspiration for the trick I will describe here, but I will still try to write this blog so that it can be understood without it. Thank you [user:Noam527,2023-01-08] for introducing such a great trick to the competitive programming community. [[Tutorial] Supporting Queue-like Undoing on DS](https://codeforces.me/blog/entry/83467) Acknowledgment ----------------- Huge thanks go to [user:peltorator,2023-02-20] for hosting a [blog contest](https://codeforces.me/blog/entry/110840). His generous prize of $300 got many people to write blogs on new, interesting ideas, and it was one of the main reasons I wrote this blog. I'm...
### Complexity Analysis, ))$ time, which is good enough for the proof of time complexity of the entire algorithm., Complexity Analysis -------------------, The complexity analysis above is somewhat incomplete, because we haven't seen how to choose an, The complexity analysis is very similar; all we have to show is that there is some value $\beta, This means that $\beta=O(d)$ and so our final complexity becomes $O(dnT(n)\log n)$., This means that if we treat $d$ as a constant, the complexity is $O(nT(n)\log n)$.

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

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

39.
Автор ToxicPie9, 3 года назад, По-английски
You won't believe how this simple trick defeated the unexplained bug destroying every top LGM ### TL;DR Currently people are discussing a slowdown bug on Codeforces that seems to happen randomly, and can cause code to run 100x slower and get TLE. More details in [user:pajenegod,2024-03-03]'s [blog post](https://codeforces.me/blog/entry/126654). In this article, I present a mitigation: add the following to your code. ~~~~ #include <windows.h> void *operator new(size_t size) { if (void *ptr = HeapAlloc(GetProcessHeap(), 0, size ? size : 1)) return ptr; throw std::bad_alloc{}; } void operator delete(void *ptr) { HeapFree(GetProcessHeap(), 0, ptr); } ~~~~ <spoiler summary="If you use malloc/free in C++ (you shouldn't), also change them."> ~~~~ void *my_malloc(size_t size) { if (void *ptr = HeapAlloc(GetProcessHeap(), 0, size ? size : 1)) return ptr; throw std::bad_alloc{}; } void my_free(void *ptr) { HeapFree(GetProcessHeap(), 0, ptr); } ~~~~ </spoiler> <spoiler summary="If you use aligned new/delete in C++, also change the...
libraries or STL, the lack of source code (and the sheer complexity) makes the Windows API [impossible to

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

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

40.
Автор MikeMirzayanov, 8 лет назад, перевод, По-русски
Codeforces Global Rounds Hello! It is always satisfying and important for me when former contest participants offer their help to the community and support the development of programming competitions. And now I am in a hurry to share the news that thanks to the support of <a href="https://www.xtxmarkets.com/">XTX Markets</a> and the personal participation of Yuri Bedny and Alexander Gerko, we are launching a new line of Codeforces Global Rounds. Hooray! <img src="/predownloaded/2e/e2/2ee2f0f95f05aae6ca6f47812dae2dc2aabf277b.png" style="width:200px; float:right; margin: 0 1em 1em 1em"/> Like many of you, I had never heard of <a href="https://www.xtxmarkets.com/">XTX Markets</a> before but it is one of the largest quantitative-driven electronic liquidity providers in the world. I understand little about the financial sector, but with their 34,148 cores and 42 petabytes of usable storage in their research cluster, XTX’s rapid growth and strong market share globally speak for themselves. So, in 2019, w...
rounds will be 2-3 hours, depending on the number and complexity of the problems. All such rounds will be

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

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

41.
Автор DanAlex, история, 11 лет назад, По-английски
How to sweep like a Sir ### Cutting to the chase Clearly you don't need a PhD in Computing to sweep in the yard , but one might be useful in order to know linear and radial sweep algorithms. So , what's all about ? It's just what it sounds it is , sweeping linear ( up to down , for example ) or radial ( making a 360 degrees loop ). How this can help? [cut] Well... ### Linear sweep Suppose you a set of objects in an Euclidean plane. We need to extract information about some objects. The method of linear sweeping takes a line and moves it on a fixed direction. Usually the line taken would be vertical and the direction would be left to right or up to down. ![ ](https://upload.wikimedia.org/wikipedia/commons/2/25/Fortunes-algorithm.gif) Quite abstract for the moment , huh ? Let's go to a more specific example. #### Rectangle union area This example is well known. You have a set of rectangles with edges parallel to the OX and OY axes. What is their union area. Well , first of all , let'...
points of the N are on it. Make the equation and verify. The complexity would be `O(N^3)` cause, update the segment trees at in and out queries. Again complexity `O(N log N)`., with a priority queue. Therefore , the complexity would be `O(N log N)`., . Finally , the complexity would be `O(N^2 log N)`., Note: We could have used hashes ( that's a better complexity ) or maps ( same ) , but we insisted

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

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

42.
Автор Geothermal, история, 3 года назад, По-английски
Four Proposals Regarding FSTs While I very much enjoy Codeforces rounds overall, FSTs are by far my least favorite part of the Codeforces contest format. There are two reasons I dislike contests with weak pretests. The first is stylistic: I don't care very much about penalizing people who don't rigorously prove their solutions before submitting (which is the main justification for having weak pretests) and I think it's essentially impossible to FST these solutions without more frequently FSTing contestants who make minor mistakes in their code. (The vast majority of my FSTs are due to this sort of minor glitch rather than an error in the underlying idea). The second is that FSTs introduce an element of hidden information to Codeforces rounds. During a contest, you have no way of knowing whether the authors have written strong pretests. If you act as though the pretests are weak, you will be at a disadvantage if pretests are actually strong (because if you knew pretests are strong, you could have e.g. submit...
the complexity analysis more complex. However, any exceptions should require justifications approved

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

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

43.
Автор Monogon, история, 5 лет назад, По-английски
[Tutorial] Blossom Algorithm for General Matching in O(n^3) I have decided to write a tutorial on a topic not even [user:Um_nik,2021-06-29] knows! ([source](https://codeforces.me/blog/entry/92248)) In this tutorial, I will talk about the blossom algorithm, which solves the problem of **general matching**. In this problem, you are given an undirected graph and you need to select a subset of edges (called matched edges) so that no two edges share a vertex, and the number of matched edges is maximized. More common in competitive programming is bipartite matching, which is the same problem but when the graph is guaranteed to be bipartite. In competitive programming, general matching seems to get a lot of hate for being very challenging to implement. However, the blossom algorithm is quite beautiful, and important in the history of algorithm research. It will help if you are already familiar with bipartite matching. I will discuss the high level ideas of the algorithm, but my main focus will be on the tricky implementation details. So you may...
The complexity of this function is $O(n)$., The complexity of this function is $O(n|b_c|)$ if the number of vertices/blossoms in $c$ is $|b_c|$.

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

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

44.
Автор errorgorn, 5 лет назад, По-английски
Linear Basis (Xor Basis Extended) As part of the graduation requirements for my school, I have to complete a simple research project, so I decided to do something related to data structure and algorithms. I believe I have come out with a data structure that maintains the basis of vectors in $(\mathbb{Z}/m\mathbb{Z})^d$, where $m$ **may not be prime**. Since this was related to competitive programming, I think it is a good idea to share it here. Hopefully, this algorithm is actually novel :P I would like to thank: - [user:icypiggy,2021-12-26] for being my research mentor and tolerating my dumb questions - [user:rama_pang,2021-12-26] and [user:adamant,2021-12-28] for their helpful suggestions and comments Please comment under the blog or message me on codeforces if any parts are unclear or wrong. Also, I hope that some LGMs can help solve the open problems in this blog. # Introduction Maintaining the basis of vectors in $(\mathbb{Z}/2 \mathbb{Z})^d$, also known as the xor basis algorithm is a well-studie...
# Complexity, The complexity of $\texttt{Inside-Basis}$ is trivially $O(d^2)$., Upon analysis of the time complexity, it is easy to see that the time complexity is actually $O((n

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

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

45.
Автор TheScrasse, история, 3 года назад, По-английски
Editorial of Pinely Round 3 (Div. 1 + Div. 2) The official implementations of all the problems are [here](https://drive.google.com/file/d/1q2PHS9nJt84FRwfMoiMslQULFE4dTMU4/view?usp=sharing). <spoiler summary="Timeline of the round proposal (may contain spoilers)"> (problems D', H', etc. were not used) - Feb 19, 2022: I proposed problem D' to [contest:1654], but it was not used. - Mar 13, 2023: I invented problem A. - May 16: I invented problem H'. - May 19: I realized problem G can be solved in $O(n)$ time and we used it in the Italian team selection test for IOI. - Jul 04: I opened a Div. 1 proposal containing A, D', G, H' and other problems which are not going to be used. - Aug 09: I invented problem I, with intended solution in $O(n^3)$. - Sep 27: I invented problem C. - Oct 14: [user:errorgorn,2023-12-23] replied to my contest proposal. - Nov 02: I invented problem D''. [user:errorgorn,2023-12-23] solved problem I in $O(n^2 \log n)$. - Nov 08: I invented problems E and F. I didn't propose problem F because I th...
Complexity for each test: $O(\sum n + (\sum m \cdot k^{2k-4}))$ (if $\lfloor n/k \rfloor$ lamps, Complexity: $2n-3$ moves, $O(n \log n)$ time. , Complexity: $O(n + \log(\max a_i))$ , Complexity: $O(n \log n)$ , Complexity: $O(n \log(\max a_i))$ , Complexity: $O(n)$ , Complexity: $O(n^2 \log n)$

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

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

46.
Автор gepardo, история, 8 лет назад, По-английски
An alternative sorting order for Mo's algorithm Hello, Codeforces! I think many of you know about Mo's algorithm. For those, who don't know, please read this [blog](https://codeforces.me/blog/entry/7383). Here, I consider an alternative (and faster) approach of sorting queries in Mo's algorithm. # Table of contents * [Canonical version of the algorithm](#s1) * [Achieving a better time complexity](#s2) * [Relation to TSP](#s2-1) * [Hilbert curve](#s2-2) * [Benchmarks](#s3) * [Applicability](#s4) <div style="font-size: 1pt"> &nbsp; [cut] &nbsp; </div> <a name="s1"></a> # Canonical version of the algorithm The canonical version of this algorithm has $O((n + q)\cdot\sqrt{n})$ time complexity if insertions and deletions work in $O(1)$. Usually, the two comparators for query sorting are used. The slowest one: ~~~~~ struct Query { int l, r, idx; inline pair<int, int> toPair() const { return make_pair(l / block, r); } }; inline bool operator<(const Query &a, const Query &b) { re...
<> # Achieving a better time complexity, But how this complexity can be achieved?, The canonical version of this algorithm has $O((n + q)\cdot\sqrt{n})$ time complexity if insertions, We can achieve $O(n\sqrt{q})$ complexity for Mo's algorithm (still assuming that insertions and, complexity](#s2) * [Relation to TSP](#s2-1) * [Hilbert curve](#s2-2) * [Benchmarks](#s3

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

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

47.
Автор okwedook, 6 лет назад, По-русски
Codeforces Round #703 (Div. 2) Editorial [problem:1486A] <spoiler summary="Hint1"> What's the lower bound for the amount of blocks for the answer to be $\texttt{YES}$? </spoiler> <spoiler summary="Hint2"> Check the predicate for every prefix. </spoiler> <spoiler summary="Solution"> Let's consider the smallest amount of blocks we need to make the first $i$ heights ascending. As heights are non-negative and ascending the heights should look like $0, 1, 2, 3, ..., i - 1$, so the minimum sum is $\frac{(i - 1) \cdot i}{2}$. It turns out that this is the only requirement. If it's not the case for every prefix the answer is $\texttt{NO}$ because we can't make some prefix ascending. Otherwise the answer is $\texttt{YES}$ because you can move the blocks right till there is at least $i$ blocks in the $i$-th stack and this would make the heights ascending. </spoiler> Solution using C++: [submission:107892022]<br> Solution using Python: [submission:107892053] [problem:1486B] <spoiler summary="Hint1"> Is proble...
So the resulting complexity is $O(nlogn)$. , The resulting complexity is $O(Mlog^2M)$ or $O(MlogM)$ or even $O(M)$ if you're strong enough.

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

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

48.
Автор -is-this-fft-, история, 5 лет назад, По-английски
[Tutorial] The command line: how to read input from file without #ifdef and much more #### Introduction Instead of algorithms and math, I'll be doing something completely different here. There is something that has bothered me for a long time: people not understanding the tools they use to participate in contests and thus failing to take real advantage of them. And it all goes back to not understanding the command line. Some of you might say, "well surely, the command line is something obsolete and you're only clinging to it because you [insert ridiculous amateur-psychology here]?" No! The command line is not obsolete, and unless competitive programming becomes so mainstream that software vendors start writing professional-grade tools aimed specifically at us, it won't be. [cut] $~$ What is the command line? Any of these: ![ ](/predownloaded/bd/b6/bdb6c157b9b3ce5ae046c9064e469e0081f8c0fe.png) As you can see, it comes in many background colors and fonts, but the basic idea is always the same. It's a box you can type commands in, which it will ...
> - Write a very naive and simple solution to the problem (maybe exponential complexity) (if you

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

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

49.
Автор Errichto, 7 лет назад, По-английски
Bitwise operations 2 — popcount & bitsets Part 1 ([link](https://codeforces.me/blog/entry/73490)) introduces basic bitwise operations. This is part 2 and it's mainly about (in)famous bitsets and example problems. Also, see links to very useful advanced stuff at the bottom. EDIT: here's [video version](https://www.youtube.com/watch?v=jqJ5s077OKo&list=PLl0KD3g-oDOHpWRyyGBUJ9jmul0lUOD80) of this blog (on my Youtube channel). ### Built-in functions In C++, `__builtin_popcount(x)` returns popcount of a number &mdash; the number of ones in the binary representation of $x$. Use `__builtin_popcountll(x)` for long longs. There are also `__builtin_clz` and `__builtin_ctz` (and their long long versions) for counting the number of leading or trailing zeros in a **positive** number. Read more [here](https://www.geeksforgeeks.org/builtin-functions-gcc-compiler/). Now, try to solve these two simple tasks in $O(1)$, then open the spoiler to check the solution: <spoiler summary="Compute the biggest power of 2 that is a divisor o...
The complexity of bitwise operations is $O(\frac{size}{32})$ or $O(\frac{size}{64})$, it depends on, [x] = 1`, and print `visited.count()`. The time complexity is $O(N + \frac{MAX\\_X}{32})$, space is

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

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

50.
Автор dreamoon_love_AA, 12 лет назад, По-английски
If you ask me how to improve your algorithm competition skill, I will give you the link of this blog. In recent one year, I don't know why but there are many people sending messages to me for asking similar problems. So I decide to create this blog. In the beginning, I must say, you may feel disappointed after reading this blog. Because I don't have any special tips. My study method has wasted me many many time. There are some basic points I think you have known. 1. **Practice, practice, and practice.** I take so many time to think and solve problems. I think I do it 5 hours a day on average. 2. **Make friends with many awesome people.** I know many awesome people. For example, [user:arosusti,2015-02-24], [user:kelvin,2015-02-24], peter50216([user:0O0o00OO0Oo0o0Oo,2015-02-24]), [user:seanwu,2015-02-24], [user:Shik,2015-02-24], [user:takaramono,2015-02-24], [user:tmt514,2015-02-24], ... If I have some problems that I can't solve in few weeks, I can almost get solution from my friends. Then I say what I do for training myself. When I do problems. There are two possi...
different solutions, better time complexity solutions, or short solutions.

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

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

51.
Автор Radewoosh, история, 6 лет назад, По-английски
Special place for algorithm explanations/tutorials — feature proposal There are many blogs on Codeforces, and most of them aren't very important a long time after publishing, like round announcements, saying "hello", asking for a better explanation of problem B than the one in the editorial, and so on. Among them, there are a few very interesting blogs that are a great resource of knowledge, like [ODE by MiFaFaOvO](https://codeforces.me/blog/entry/76447), [HLD by Vladyslav](https://codeforces.me/blog/entry/12239), [suffix automaton by quasisphere](https://codeforces.me/blog/entry/20861) or even Blogewooshes. In my opinion, it would be great if there would be a special place for such blogs, accessible for example, by navigation bar, where they would be somehow sorted. It would be much easier to think "Let's learn something new!" and to do it. Also, probably Codeforces would have the greatest such base for competitive programmers. What do you think guys and [user:MikeMirzayanov,2020-06-04]? **EDIT** One more argument after thinking a bit more: of ...
"proper" to have something like this in the complexity while ofc for us it's great and has a lot of

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

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

52.
Автор MikeMirzayanov, 4 года назад, По-английски
Looking For EDU Lecturers <img src="/predownloaded/47/86/4786c2ec901c0b5b490794ca6fd5145f0dcdeae3.png" style="float:right; width: 400px; margin: 0 1em 1em 1em"/> Hello! I always like to think that Codeforces is not only a place where you come to compete but also a place where you can learn. Learn new things. Two years ago, we launched the [EDU](https://codeforces.me/edu/courses) subproject, a platform for publishing classes. There are already several classes, but there are so many interesting topics around! The Codeforces team can write the platform, make the technical foundation, but it would be great to write content with the support of the community. Thanks to the support of competitive programming alumni, we have a budget for targeted grants for the preparation of new classes in the EDU section. Hope we have new content soon! We are looking for lesson authors who could prepare and record one or more lessons. Those who are now red or have ever been red are invited. We assume that one le...
a wide range of complexity (from the most basic on this topic to quite tricky ones) * first of all

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

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

53.
Автор peltorator, 7 месяцев назад, По-английски
So Do You Really Understand Fast Matrix Multiplication? Most of you have probably heard of $\omega$, the matrix multiplication exponent. Are you sure you fully understand its definition, though? I thought so too, until I started asking myself some uncomfortable questions and realized that I had some subtle misconceptions. To answer these questions, I read a bunch of papers and book chapters, and now I have some peace of mind. Let me try to scare you a bit first and then hopefully rebuild your understanding of fast matrix multiplication. Let's start with four questions. Try to answer them before reading further. Q1: Does there exist an $O(n^{\omega})$-time matrix multiplication algorithm? Q2: Does there exist an $o(n^{\omega})$-time matrix multiplication algorithm? Q3: Does there exist an $O(n^{\omega + 0.1})$-time algorithm for integer matrix multiplication? Q4: Does there exist an $O(n^{\omega - 0.1})$-time algorithm for integer matrix multiplication? <spoiler summary="Answers"> A1: Maybe. We don't know. A2: ...
relies on several nontrivial facts connecting algebraic complexity over fields to actual algorithms, : it is about arithmetic complexity over $\mathbb{R}$. There is no obvious reason why the optimal

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

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

54.
Автор ko_osaga, история, 7 лет назад, По-английски
Story about edge coloring of graph You are given a graph $G$, and for each vertex $v$ you have to assign a positive integer **color** such that every adjacent pair of vertices (vertices directly connected by edge) have different color assigned. You have to minimize the maximum color assigned: In other words, you have to minimize the number of distinct assigned colors. But that's [graph coloring](https://en.wikipedia.org/wiki/Graph_coloring) (vertex coloring). It's hard. Ok, one more time: You are given a graph $G$, and for each **edge** $e$ you have to assign a positive integer **color** such that every adjacent pair of edges (edges sharing same endpoints) have different color assigned. You have to minimize the maximum color assigned: In other words, you have to minimize the number of distinct assigned colors. This is the edge coloring of graph, and I will talk about this now. *Note that this can be interpreted as "graph coloring (vertex coloring) of line graphs". In that sense, you can consider in a similar...
reduce the time complexity from $O(D \times MN^{0.5})$ to $O(MN^{0.5} \log D)$.

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

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

55.
Автор duality, 3 года назад, По-английски
Codeforces Round #884 (Div. 1 + Div. 2) Editorial Video editorials for [B](https://www.youtube.com/watch?v=5nzUni8dFLQ), [C](https://www.youtube.com/watch?v=8mz7gnAJ5QM), and [D](https://www.youtube.com/watch?v=ahnNAwpGwHc) are available on [user:ak2006,2023-07-11]'s channel. ### [problem:1844A] <spoiler summary="Hint 1"> There exists a small $n$ where the second player can win. </spoiler> <spoiler summary="Hint 2"> If $a \ge 2$, then $n = 1$ works. </spoiler> <spoiler summary="Solution"> [tutorial:1844A] </spoiler> <spoiler summary="Implementation"> ~~~~~ #include <bits/stdc++.h> using namespace std; int main() { int t,a,b; scanf("%d",&t); while (t--) { scanf("%d %d",&a,&b); printf("%d\n",a+b); } return 0; } ~~~~~ </spoiler> ### [problem:1844B] <spoiler summary="Hint 1"> In order for $(l,r)$ to contribute to the primality, we must have $\operatorname{MEX}(a_l,\dots,a_r) \ge 2$, so there is some value $1$ between indices $l$ and $r$. </spoiler> <spoile...
The time complexity is $\mathcal{O}(n \log n)$.

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

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

56.
Автор feecIe6418, 4 года назад, По-английски
Editorial of Codeforces Global Round 21 Thanks for participation! If your solution to D involves any data structures and is not $O(n)$ -- please read the "solution 1". I believe it is very interesting, but to make the difficulty suitable for D we allowed not $O(n)$ solutions. [problem:1696A] <spoiler summary="Hint 1"> How many operations will we perform? <spoiler summary="Answer"> At most one. Why? </spoiler> </spoiler> <spoiler summary="Solution"> Suppose we can only perform exactly one operation. In this case the answer is $S=\max_{1\le i\le n}(a_i\mathrm{\ or\ }z)$. In fact, we can prove that this is the answer. Define $a_i'$ as the value of $a_i$ after some operations. It suffices to prove the answer will never exceed $S$. Note that $z$ will always become a submask of itself after any number of operations, so $a_i$ will always be a submask of $(a_i\mathrm{\ or\ }z)$ after any number of operations. This leads to the conclusion that $a_i'\le (a_i\mathrm{\ or\ }z)$ for all $i$. Thus $\max_{1\le i...
Use monotonicity to reduce the complexity. , . There are at most $\dfrac n2$ such components, so complexity is $O(n^4)$. Proper pre-computation, Complexity: $O(n+q\log n)$. , The time complexity is $O(n)$. , The time complexity is $O(n+V)$, where $V=\max a_i$. , Time complexity is $O((n+k)\log_m V)$, where $V=\max a_i$. , Time complexity is $O(n)$.

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

Разбор задач Codeforces Global Round 21
  • Проголосовать: нравится
  • +332
  • Проголосовать: не нравится

57.
Автор Noam527, 6 лет назад, По-английски
[Tutorial] Supporting Queue-like Undoing on DS In many data structures, the operation of "undo" on the last update can be implemented easily: we can (usually) maintain a stack of the updates, where each update on the stack holds the memory cells it changed, and their original values. To undo an operation, just revert all changes from the top update on the stack. To maintain good complexity, we require the updates to operate in non-amortized time. I've seen this being used multiple times on DSU (without path compression). If we imagine the updates as a sequence, then we can push an update to the end, and pop an update from the end by undo. Then, this sequence is a stack of updates. Here we discuss the idea of having a queue of updates: we can add a new update, or undo the oldest update still active. Specifically, this blogpost attempts to solve the following problem: Given a data structure that can support some updates, some queries and an "undo" operation (each with their own time complexity), how can we create a data structu...
original DS (we don't care if its complexities are amortized, this includes the complexity of its, with their own time complexity), how can we create a data structure that supports the same updates and, Also, the total time complexity of the algorithm is equal to the sum of all the fixing costs, so we

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

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

58.
Автор Radewoosh, история, 8 лет назад, По-английски
Blogewoosh #2 Hello, codeforces! All signs in the sky and on the ground indicate that you've enjoyed my first blog, so here is the second one. I've decided to choose a Polish task again, as there are plenty of interesting ones. This time we'll take a look at the "plot purchase" ([you can submit here](https://szkopul.edu.pl/problemset/problem/hwbyoUkNFPXQLOPcw3x5huTR/site/?key=statement)), which is a bit easier, but a few years ago I was very proud of myself when I solved it. The statement goes as follows: You are given a square $n \times n$ grid ($1 \leq n \leq 2000$). In every cell, there is a number from the range $[1, 2 \cdot 10^9]$. You are also given an integer $k$ ($1 \leq k \leq 10^9$). A task is to find a subrectangle of this grid such that the sum of values in this subrectangle lies in the range $[k, 2\cdot k]$ (or report that there is no such subrectangle). Just print coordinates of its opposite corners. [cut] $ $ If the problem would be more difficult, and we'd be asked to fi...
remove it from the stack), so in total there are $O(n^2)$ considered rectangles.Complexity is the

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

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

59.
Автор Monogon, история, 6 лет назад, По-английски
[Tutorial] Voronoi Diagram and Delaunay Triangulation in O(n log n) with Fortune's Algorithm What's a Voronoi Diagram? ------------------ Given a set $S$ of $n$ points in the 2D plane, the Voronoi diagram is a partition of the plane into regions. The region associated with a point $p\in S$ contains precisely the points $q$ such that $q$ is closer to $p$ than any other point in $S$. In other words, a point $q$ belongs to the region of its nearest neighbor. <img src="https://upload.wikimedia.org/wikipedia/commons/thumb/5/54/Euclidean_Voronoi_diagram.svg/1024px-Euclidean_Voronoi_diagram.svg.png" width="300px" height="auto"/> The Voronoi diagram can be represented by the planar graph of boundaries between regions. A vertex in this graph is where three or more segments meet (or a point at infinity), and an edge is a segment connecting two of these vertices. The way the regions were defined, we see that a segment contains the points equidistant to two points in $S$, so it is part of their perpendicular bisector. Similarly, a Voronoi vertex is equidistant to three or more v...
computations. The disadvantage is the complexity of the quad-edge data structure and the costly memory usage

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

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

60.
Автор snowysecret, 5 лет назад, По-английски
Editorial for Codeforces Round #761 (Div. 2) Thanks for participating, hope you enjoyed the problems! Implementations for the problems are chosen randomly among testers, and I made some changes to their codes (for example, deleted meaningless comment lines). Please do not hesitate to provide feedback in the comments, so I can improve in setting problems next time. **UPD**: Sorry but there is a checker bug in problem E. All submissions of problem E will be rejudged soon. **UPD2:** Rejudge done, the round remains rated. <spoiler summary="Statistics"> Number of FST for rated participants: - Problem A: $29$ - Problem B: $90$ - Problem C: $12$ - Problem D1: $4$ - Problem D2: $0$ - Problem E: $6$ Number of AK: $22$ Number of clarifications: $85$ </spoiler> [problem:1617A] <spoiler summary="Hint"> When is the lexicographically smallest permutation of $S$ (i.e. the sorted string) not the answer? </spoiler> <spoiler summary="Solution"> If there are no occurrences of `a`, `b` or `c` in $S$, ...
In both ways, the time complexity is $O(n \log max(a_i))$.

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

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

61.
Автор Monogon, история, 5 лет назад, По-английски
[Tutorial] Graph Potentials, Johnson's Algorithm, and Min Cost Max Flow In this tutorial I'll introduce potentials as it applies to directed graphs and discuss a few of its applications. I haven't seen many resources about this topic, so I decided to write one. Prerequisites: - Shortest path algorithms ([Dijkstra](https://cp-algorithms.com/graph/dijkstra.html) and [Bellman-Ford](https://cp-algorithms.com/graph/bellman_ford.html)) - For the Min Cost Max Flow section, you should be familiar with [Ford-Fulkerson](https://cp-algorithms.com/graph/edmonds_karp.html). But you can benefit from this blog with just the Johnson's Algorithm section if you're not familiar with flows. Introduction ------------------ For notation, let's say there is a weighted, directed graph $G=(V,E)$. Let $n=|V|$ and $m=|E|$. For simplicity, let's assume there are no loops or multiple edges between the same pair of nodes in the same direction. For an edge $u\to v$, we will use $w(u\to v)$ to denote its weight. Let's motivate the idea of a potential, so the definition d...
Overall, step 3 is the bottleneck and Johnson's algorithm has complexity $O(nm\log n)$ (or $O(n^2, complexity. Dijkstra's is $O(m\log n)$ while Bellman-Ford is $O(mn)$. Technically, Dijkstra's

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

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

62.
Автор Kuroni, 7 лет назад, По-английски
Slope trick explained _Special thanks to [user:Ari,2020-05-13] for helping me proof-reading this blog :D_ Hi everyone! Some years ago I read [user:zscoder,2020-05-12]'s tutorial on slope trick. Initially, I found the blog a bit difficult to understand, so I came up with a different explanation and system for my personal use. Today, I finally have the courage to share it with you guys. So without further ado, let's get started! #### Formulation and properties Slope trick is a way to represent a function. Here, I denote that a function is **slope-trick-able** (sorry for the lack of creativity) if the function satisfies 3 conditions: 1. It is continuous. 2. It can be divided into multiple sections, where each section is a linear function with an integer slope. 3. It is a convex/concave function. In other words, the slope of each section is non-decreasing or non-increasing when scanning the function from left to right. For example, the function $y = f(x) = |x|$ is a slope-trick-able function ...
function of the minimum section itself. Complexity is $O(n \log n)$., . The complexity is $O(n \log n)$.

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

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

63.
Автор kpw29, 6 лет назад, По-английски
Meet IT Codeforces Round Editorial Thank you very much for taking part in the contest! <spoiler summary="Contest timeline"> - -0:05. Starting the chat with the Questions Answering team: [user:tnowak,2020-11-15] and our beloved coordinator [user:antontrygubO_o,2020-11-15]. We hope that there won't be that many questions :) - -0:01. One minute to go! I hope that everything goes smoothly. I'm so afraid of posting the editorial accidentally that I moved this timeline into another blog... - 0:01. First blood in Div2! Congratulations to [user:majorro,2020-11-15]!. - 0:03. First blood in Div1 as well! Congratulations to [user:Errichto,2020-11-15], your knapsack is ready for a journey to win! - 0:04. [user:Sho10,2020-11-15] first to solve Div2B. Well done! - 0:05. We also have the first question. So far so good... - 0:06. [user:Um_nik,2020-11-15] gets the first pretests pass in Div1B. The cheaters are caught! - 0:09. [user:bandiaoz,2020-11-15] packs the first Knapsack in Div2! A difficulty spike is coming... - 0:12....
interval with sum $0$. Thus, we get a solution with complexity $O(100\cdot n$).

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

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

64.
Автор TheScrasse, история, 6 лет назад, По-английски
Editorial of Codeforces Round #701 (Div. 2) [problem:1485A] Author: [user:TheScrasse,2021-02-07]<br> Preparation: [user:MyK_00L,2021-02-07] <spoiler summary="Hint 1"> Suppose that you can use $x$ operations of type $1$ and $y$ operations of type $2$. Try to reorder the operations in such a way that $a$ becomes the minimum possible. </spoiler> <spoiler summary="Hint 2"> You should use operations of type $2$ first, then moves of type $1$. How many operations do you need in the worst case? ($a = 10^9$, $b = 1$) </spoiler> <spoiler summary="Hint 3"> You need at most $30$ operations. Iterate over the number of operations of type $2$. </spoiler> <spoiler summary="Solution"> Notice how it is never better to increase $b$ after dividing ($\lfloor \frac{a}{b+1} \rfloor \le \lfloor \frac{a}{b} \rfloor$). So we can try to increase $b$ to a certain value and then divide $a$ by $b$ until it is $0$. Being careful as not to do this with $b<2$, the number of times we divide is going to be $O(\log a)$. In particular, i...
Complexity: $O(\log^2 a)$., Complexity: $O(\sqrt x)$. , Complexity: $O(n + q)$. , Complexity: $O(n)$ or $O(n\log n)$. , Complexity: $O(n\log n)$. , Complexity: $O(nm)$.

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

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

65.
Автор gepardo, история, 9 лет назад, По-английски
Sqrt-tree: answering queries in O(1) with O(NloglogN) preprocessing. Hello, Codeforces! Some time ago I invented an interesting data structure and I'd like to share it with the community. Maybe, it was known before, and if you knew about it before my blog post, please share the link to the source. # What can the data structure do? Given an array $a$ that contains $n$ elements and the operation $op$ that satisfies associative property: $(x\ op\ y) op\ z = x\ op (y\ op\ z)$ is true for every $x$, $y$ and $z$. So, such operations as $gcd$, $\min$, $\max$, sum, multiplication, $and$, $or$, $xor$, etc. satisfy these conditions. Also we have some queries $l, r$. For each query, we need to find $a_l\ op\ a_{l+1}\ op\ \dots op\ a_r$. Let's call such queries $q(l, r)$. My data structure can process such queries in $O(1)$ time with $O(n \cdot \log \log n)$ preprocessing time and $O(n \cdot \log \log n)$ memory. # How it works? [cut] # ## 1. Sqrt Let's do a sqrt-decomposition. We divide our array in $\sqrt{n}$ blocks, each block ha...
## 3. Optimizing the query complexity

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

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

66.
Автор DrSwad, история, 7 лет назад, По-английски
A Beautiful Technique for Some XOR Related Problems ## Inspiration I'm very excited about this blog, as it took me quite a lot of effort and scavenging through the internet to completely grasp the concept of this technique(That's probably because I have almost zero knowledge in Linear Algebra or I'm just plain dumb). So I feel like I genuinely conquered a challenge, and I really want to share it with someone. But there's no way my CP friends circle will believe it, they'll think I'm just trying to show off :P So here I am, sharing it on CF. I also created a [personal blog](https://drschwad.github.io/), so that if I ever feel like sharing something again(not only about CP), I can write a blog there. I also added this same post [there](https://drschwad.github.io/2019-08-06-z2-space-xor-trick/), you can read it there if you prefer dark theme. I'll be pleased to hear any thoughts on the blog or if I can improve it in some way ^\_^ ## Introduction Since it concerns Linear Algebra, there needs to be a lot of formal stuff going on ...
But, the complexity is $O(n \cdot 2^{19}),$ which is way too high :(

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

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

67.
Автор Syloviaely, история, 8 лет назад, По-английски
A simple introduction to "Segment tree beats" **This blog is just a back up of [http://codeforces.me/blog/entry/57319](http://codeforces.me/blog/entry/57319) to prevent this tutorial from discarding after [user:jiry_2,2018-10-17] is banned.** Hi, I’d like to introduce a simple trick about segment tree in this blog as I promised in [this comment](http://codeforces.me/blog/entry/54750?#comment-387957). Sorry for the long delay, as a sophomore in Peking University, I've just finished a tired semester and a painful final exam. And now I finally have enough time to do a simple introduction to this interesting algorithm. It may be a huge project for me since my English is not good. I think I will finish this blog in several steps and I will try to finish it as soon as possible :) In China, all of the 15 candidates for the Chinese National Team are asked to write a simple research report about algorithms in informatics Olympiad, and the score will be counted in the final selection. There are many interesting ideas and algorit...
### Part 3. The time complexity, It’s time complexity is the same as Task 2.

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

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

68.
Автор sdnr1, история, 8 лет назад, По-английски
[Tutorial] Searching Binary Indexed Tree in O(log(N)) using Binary Lifting **NOTE** : Knowledge of Binary Indexed Trees is a prerequisite. ## Problem Statement Assume we need to solve the following problem. We have an array, $A$ of length $N$ with only non-negative values. We want to perform the following operations on this array: 1. Update value at a given position 2. Compute prefix sum of $A$ upto $i, i \leq N$ 3. Search for a prefix sum (something like a `lower_bound` in the prefix sums array of $A$) [cut] <br> ## Basic Solution Seeing such a problem we might think of using a Binary Indexed Tree (BIT) and implementing a binary search for type $3$ operation. Its easy to see that binary search is possible here because prefix sums array is monotonic (only non-negative values in $A$). The only issue with this is that binary search in a BIT has time complexity of $O(log^2(N))$ (other operations can be done in $O(log(N))$). Even though this is naive, here is how to do it: <spoiler summary="Implementation"> `int sum(pos)` -> comput...
Complexity : $O(log(N)) * O(log(N)) = O(log^2(N))$

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

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

69.
Автор Sol1, 4 года назад, По-английски
Unofficial tutorial to Codeforces Round 844 (A-G) Seems like the official editorial has not been released for a long time, I'll try to provide an unofficial one for those who are tired of waiting. But I'm too weak to understand the solution to H by reading others' code :(. If you know the solution, I'll appreciate it if you can explain it to me. Implementation can be seen in my [submissions](https://codeforces.me/submissions/Sol1/contest/1782). This is the first time I write an English editorial like this. If there's anything inappropriate, kindly point out. A ------------------ Note that you have to move from the bottom to the top no matter what, so we can consider the following problem: Given 2 points $A,B$ in a $w\times d$ rectangle, find one path from $A$ to $B$ that moves parellel to the edges of the rectangle and touch the edges at least once. After we get the answer to this problem, we can add $h$ to it to get the answer of the original. This problem is easy to solve: iterate over which edge to touch, and the d...
Total complexity is $O(n\log n)$.

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

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

70.
Автор bicsi, история, 4 года назад, По-английски
"Merging treaps" -- or how to merge sorted sets in good complexity... ... without doing much of anything. I've been obsessed for the last two days about problem [Data Centers](https://ubilo.tubitak.gov.tr/egoi2022/assets/tasks/DataCenters.pdf) from EGOI 2022. In particular, it has a subtask where $1 \leq N \leq 10^5$ and $1 \leq S \leq 5000$, where it seems $O(NS)$ wouldn't fit TL. I've been conjecturing that using treaps would amortize to good complexity, and after two days of burning grey matter, I've finally found a proof, and it's pretty cool to make a blog out of it. The problem basically starts with an array $[v_1, v_2, ..., v_N]$, where $1 \leq v_i \leq V$ for all $i$. It then asks us to iteratively simulate the operation: "Subtact $x_i$ from the biggest $m_i$ elements.". All this while keeping the array sorted. We'll show that just using treaps (or any BBST for that matter) yields a good amortized complexity. More exactly, we'll prove $O((N + Q) \log V \log N)$, and it should actually be better in practice. ### Naive solution with tr...
"Merging treaps" -- or how to merge sorted sets in good complexity..., First, it is rather straightforward to write an implementation of merge on BBST that hascomplexity, We'll show that just using treaps (or any BBST for that matter) yields a good amortizedcomplexity

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

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

71.
Автор adamant, история, 3 года назад, По-английски
Dirichlet convolution. Part 1: Fast prefix sum computations Hi everyone! Suppose that you need to compute some sum of a number-theoretic function that has something to do with divisors: $$\begin{gather} \sum\limits_{k=1}^n \varphi(k) = ? \\ \sum\limits_{k=1}^n \sum\limits_{d|k} d^2 = ?? \\ \sum\limits_{x=1}^n \sum\limits_{y=1}^x \gcd(x, y) = ?!? \end{gather}$$ As it turns out, such and many similar sums can be computed with Dirichlet convolution in $O(n^{2/3})$, and in this article we will learn how. Let $f(n)$ and $g(n)$ be two [arithmetic functions](https://en.wikipedia.org/wiki/Arithmetic_function). Let $F(n)$ and $G(n)$ be their prefix sums, that is $$\begin{matrix} F(n) = \sum\limits_{i=1}^n f(i), & G(n) = \sum\limits_{j=1}^n g(j). \end{matrix}$$ We need to compute a prefix sum of the [Dirichlet convolution](https://en.wikipedia.org/wiki/Dirichlet_convolution) $(f * g)(n)$. In this article, we will consider some general methods, and show how to do so in $O(n^{2/3})$ if we can compute prefix sums of $F(n)$ and $G(n)$ in ...
proving the overall complexity of $O(n^{2/3})$.

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

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

72.
Автор errorgorn, 4 года назад, По-английски
[Tutorial] Theoretically Faster HLD and Centroid Decomposition This blog was going to be translation of $[1]$ (which is in Chinese) but I think I ended up deviating too much from the source material that it would not be appropriate to call this a translation. Anyways, I am honestly amazed by how ahead of its time this paper is. In its abstract, it starts by saying that the state of art for tree path queries is $O(n \log n + q \sqrt n \log n)$, which I honestly can't fathom how one would arrive, then proceeds to claim that it has found an $O((n+q) \log n)$ algorithm. All the more, in 2007. While I was in the process of writing this blog, [user:smax,2022-07-18] sniped me and posted $[9]$. However, we will focus on static trees **only**. Thanks to [user:oolimry,2022-07-18], [user:everule,2022-07-18] and [user:timreizin,2022-07-18] for proofreading. Note to reader: I am expecting the reader to be familiar with what a splay tree and HLD is. You do not really need to know why splay trees are $O(\log n)$ amortised but you should know what the z...
### $O(\log n)$ Time Complexity Bound, ### $O(\log^2 n)$ Time Complexity Bound, - zig has a time complexity of $O(r'(x)-r(x)+1)$ amortised - zig-zig and zig-zag has a time

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

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

73.
Автор PrinceOfPersia, 12 лет назад, По-английски
Algorithm Gym :: Graph Algorithms Welcome to the new episode of [user:PrinceOfPersia,2015-01-31] presents: Fun with algorithms ;) You can find all the definitions here in the book "Introduction to graph theory", Douglas.B West. [cut] Important graph algorithms : DFS --- The most useful graph algorithms are search algorithms. DFS (Depth First Search) is one of them. While running DFS, we assign colors to the vertices (initially white). Algorithm itself is really simple : ~~~~~ dfs (v): color[v] = gray for u in adj[v]: if color[u] == white then dfs(u) color[v] = black ~~~~~ Black color here is not used, but you can use it sometimes. Time complexity : $O(n + m)$. #### DFS tree DFS tree is a rooted tree that is built like this : ~~~~~ let T be a new tree dfs (v): color[v] = gray for u in adj[v]: if color[u] == white then dfs(u) and par[u] = v (in T) ...
Time complexity : $O(n + m)$., Time complexity : $O(nm)$., Time complexity : $Unknown!$.

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

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

74.
Автор Gellyfish, 3 года назад, По-английски
About Codeforces Round 901 (Div.1, Div.2) First of all, I'm sorry for the unreasonable difficulty. The problems are much harder than usual, so we choose 3 hours. But it seems that it didn't work :( About the problems: - [problem: 1874C] : It seems that the out-degree of the vertex is not maximized, [user:znstz2018,2023-10-01] prepared it for me, but I forgot to check the data, I'm sorry for the unfairness caused to the round. - [problem: 1874D] : There are some hacks appearing in this problem. Some adjustments in the approximate solution past the problem, but there's really nothing I can do about it. Hack can only make the adjustments you need to make larger, but if you have a good approximate solution and adjust up to about $[-50, +50]$. You can pass all the test cases satisfying $1 \leq n \leq m \leq 3000$. Also, different approximate solutions have different hacks for them, we really have no way to hack all of them. But luckily, no matter what solution you use, you must know $ans = n + 2 \times \sum_{i=1}^n\sum_{j=...
Memory complexity: $O(\min(\sqrt n, m) \times k)$, Time complexity: $O(\min(\sqrt n, m) \times k)$

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

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

75.
Автор -Morass-, история, 9 лет назад, По-английски
Problem Topics Good Day to you! I've been asked to make some topic-wise list of problems I've solved. Even though I couldn't involve all problems, I've tried to involve at least "few" problems at each topic I thought up (I'm sorry if I forgot about something "easy"). I've alredy made such list once anyway I've tried to include more problems now &mdash; so here it is: <spoiler summary="aho"> http://www.spoj.com/problems/ADAJOBS/ URI 2226 (5) //[NICE][NUMBERS][DP] http://www.spoj.com/problems/SUB_PROB/en/ http://codeforces.me/contest/696/problem/D 8 http://www.spoj.com/problems/AHOCUR/ 5 //Aho-Corassic + DP https://www.codechef.com/problems/LYRC (5) //Sample aho-brute-force http://codeforces.me/problemset/problem/346/B //Proposed by [user:bradyawn,2019-08-03] </spoiler> <spoiler summary="automat"> 6861 [LA] //CYK UVA 10679 //Suffix Automat http://www.spoj.com/problems/STRMATCH/ //Suffix Automat &mdash; trie might do too http://www.spoj.com/problems/NSUBST...
http://codeforces.me/gym/101962/problem/K (3) //[NICE] //Complexity

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

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

76.
Автор Nachia, история, 2 года назад, По-английски
Determine A Non-Increasing Integer Sequence of Length n with a[k]<=n/k in O(sqrt(n)) Steps This is a topic on complexity analysis (for [Round 975 Div. 1 E](https://codeforces.me/contest/2018/problem/E2)) with no special algorithm. ## Problem An integer sequence $(a _ 1,a _ 2,\ldots ,a _ n)$ is hidden. We know: * It is non-increasing. ( $a _ k\geq a _ {k+1}$ ) * $0\leq a _ k\leq n/k$ Suppose we can get one value of $a _ k$ in $O(C)$ time. Find all values of $a _ 1,a _ 2,\ldots ,a _ n$ . ## Algorithm Put $a _ 0=n+1$ and $a _ {n+1}=0$ and call $\text{S} _ \text{EARCH}(1,n)$ . In a call of $\text{S} _ \text{EARCH}(l,r)$ , do nothing if $l\gt r$ . Also no more search is required if $a _ {l-1}=a _ {r+1}$ . Otherwise evaluate $a _ {\lfloor (l+r)/2\rfloor}$ and recursively call $\text{S} _ \text{EARCH}(l,\lfloor (l+r)/2\rfloor -1)$ and $\text{S} _ \text{EARCH}(\lfloor (l+r)/2\rfloor +1,r)$ . ```py A = [0] * (n+2) A[0] = n+1 A[n+1] = 0 def f(k) : # find a_k def search(l, r) : if l > r return if A[l-1] == A[r+1] : for x ...
## Complexity Analysis

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

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