Open jamperezmondragon opened 1 month ago
Looks interesting, though I don't really know it would go considering it's a mix of some topics already in the guide / some new things. Maybe after the others in the Plat range queries section?
Questions:
Thus, the final complexity is $O(Q(N/B + B))$, and since $Q = O(N)$ we can take $B = \sqrt{N}$, which is optimal by AM-GM inequality.
Hello, I was talking to lunchbox and thought maybe it could be an interesting addition to the guide, he told me to write an issue.
This (and the next 2 proposals) are classes I taught to the Mexican IOI team some months ago (I am the team leader).
This is just a draft, if you like it I can work more on it and make a PR in the next couple weeks.
Advanced data structure design
Inspired by this blog and it's video.
What is an invariant? What is a monovariant?
Example problem to define and showcase this concepts is IMO 2009 C1.
The main idea of this module is to think about data structures as graphs where each node stores an invariant or a monovariant.
It's a good idea to start designing a data structure as a "bag" where you can add nodes, and as you start to recognize more properties you'll need to solve the problem, use degrees of freedom to narrow down the structure of the algorithm, connecting the nodes in some way and adding invariants or monovariants to them.
Definitions:
Example problems
Range Updates and Sums with Square Root Decomposition
The main idea is to do blocking, and maintain several invariants for each block. Say there's $N/B$ blocks, we'll maintain the following variables:
Our invariants are:
We will process updates in such a way that this invariants will always hold. Whenever we process any update, if it's contained within the same block, reconstruct it in $O(B)$ time.
For set updates, we do it similarly, for blocks completely contained in the query we update the ranges, the lazy value and the sum value. And overlapping blocks are handled in the same way as above. So each of our updates take $O(N/B + B)$. And each of our queries take $O(N/B + B)$ which are processed by just following the invariant we stated initially, processing overlapping blocks separately than blocks contained in the whole range.
Thus, the final complexity is $O(Q(N/B + B))$, and since $Q = O(N)$ we can take $B = \sqrt{N}$, which is optimal by AM-GM inequality.
Here's an implementation of this idea, although the comments are in Spanish haha.
You can see that the code is very simple and easy to write because many parts have the same structure and you just have to copy paste them.
Scoreboard Semanal
Translation of the problem:
There's a set of students. Each week, they solve some amount of problems (could be negative). After each week, the student $i$ will get 1 stress point for each student with more solved problems than them. given $N \le 10^5$ students, and $Q \le 10^5$ weeks, each week having $U_i$ updates to the ranking (which consists of a student that solved a non zero number of problems and how many they solved), determine the final number of stress points each student gets after the $Q$ weeks. It is guaranteed that the sum of $U_i$ is at most $5\times 10^5$ and that the number of solved problems for each student will never leave the range $[-5\times 10^5, 5\times10^5]$.
Solution: (I have yet to write a more detailed and motivated explanation)
T-shirts
We iterate over the t-shirts in decreasing order of quality untying by cost. Each t-shirt with cost $c$ will be bought by any person with a budget larger than or equal to $c$ when that t-shirt is processed. We want to decrease by $c$ all the budgets larger than or equal to $c$, and add 1 to their answers.
Here's the point where we start to define what structure we will use to maintain buckets. Until now it's been just an abstract bag where we add and remove elements. Let's analyze the properties we need to determine the structure:
I have an implementation of this idea but it's a bit messy.
Welcome home, Chtholly
Similar idea to the editorial, I think it's pretty educational and we can motivate each step of the solution after seeing the problems above.
Problems to try