Predictor | A | B | C1 | C2 | D | E | F | G | H |
---|---|---|---|---|---|---|---|---|---|
Proof_by_QED | 800 | 800 | 900 | 1300 | 1200 | 1500 | 1700 | 1800 | 2100 |
DivinePunishment | 800 | 1000 | 900 | 1400 | 1400 | 1400 | 1600 | 1700 | |
poi | 800 | 800 | 800 | 1000 | 1200 | 1200 | 1700.223 | 1600 | Didn't solve so $$$\infty$$$ |
mathtsai | 800 | 900 | 1000 | 1200 | 1400 | 1500 | 1700 | 1600 | |
macaquedev | 800 | 800 | 800 | 900 | 1200 | 1300 | 1400 | 1400 | |
Intellegent | 800 | 800 | 900 | 1100 | 1300 | 1500 | 1700 | 1800 | 2100 |
cry | 800 | 800 | 900 | 1100 | 1300 | 1500 | 1700 | 1800 | 2100 |
larush | 800 | 800 | 900 | 1200 | 1400 | 1500 | 1800 | 1700 | 2100 |
temporary1 | 800 | 800 | 900 | 1200 | 1300 | 1500 | 1600 | 1900 | 2300 |
Lilypad | 800 | 800 | 900 | 1200 | 1300 | 1300 | 1500 | 1600 | |
LMeyling | 800 | 800 | 1200 | 1500 | 1100 | 1400 | 1600 | 1500 | 1900 |
A | B | C1 | C2 | D | E | F | G | H | |
---|---|---|---|---|---|---|---|---|---|
Average | 800 | 961.5 | 1100 | 1307.7 | 1630.8 | 2000 | 2291.7 | 2100 | |
Actual | 800 | 1000 | 900 | 1100 | 1500 | 2200 | 2400 |
[problem:2065A]
Problem Credits: chromate00
Analysis: macaquedev
Let $$$n$$$ be the length of the string. Output the first $$$n-2$$$ characters of the string (to remove the suffix "us"), then the lowercase letter "i".
Will be added after open hacking phase
[problem:2065B]
Problem Credits: cry
Analysis: macaquedev
Note that if you can ever do an operation, the answer is $$$1$$$. This is because once you've done an operation on a string of length $$$k$$$, you are free to choose any character to replace $$$s_i$$$ with. Therefore, if you replace $$$s_i$$$ either with the character directly before it, or the character directly after it, you will end up with a string with length $$$k-1$$$ upon which you can do an operation again. Therefore, by induction, it's clear that you can keep operating on the string until only one character remains.
However, if you cannot perform any operations, the answer is $$$|s|$$$, because you have not modified the original string.
Therefore, the answer is $$$1$$$ if $$$s_i = s_{i+1}$$$ for some $$$i$$$, or $$$n$$$ otherwise.
Will be added after open hacking phase
[problem:2065C1] and [problem:2065C2]
Problem Credits: larush
Analysis: macaquedev
The overall idea for both subtasks is that you need to iterate from left to right, and upon each element, pick the operation such that you obtain the smallest value of $$$a_i$$$ that is greater than $$$a_{i-1}$$$.
For C1, you only have two values to consider for each index — $$$b_1-a_i$$$ and $$$a_i$$$. First, set $$$a_1 = min(a_1, b_1-a_1)$$$, then for each subsequent element $$$i$$$, consider the two values $$$b_1-a_i$$$ and $$$a_i$$$. If the smaller of these values is greater than or equal to $$$a_{i-1}$$$, then set $$$a_i$$$ to this value. Otherwise, check the larger value. If this value is less than $$$a_{i-1}$$$, you can straight away output $$$NO$$$ and move onto the next testcase. Otherwise, set $$$a_i$$$ as the larger of the two aforementioned values. Time complexity: $$$\mathcal{O}(n)$$$ per testcase.
For C2, you now have $$$m$$$ values in the array $$$b$$$. Clearly, we now need to consider $$$m+1$$$ different possible values per index of $$$a$$$. Solving this problem in $$$\mathcal{O}(nm)$$$ is clearly too slow. Therefore, we need to employ a different technique.
Note that instead of trying every value, you can sort all the values in $$$m$$$, and then binary search for the minimal value of $$$b_j$$$ such that $$$b_j-a_i >= a_{i-1}$$$. Then, you're left with the original problem, where you either leave $$$a_i$$$ untouched or you set it to $$$b_j - a_i$$$ for this optimal index $$$j$$$ that you found using binary search. Now, by proceeding as before, the problem is solved in $$$\mathcal{O}(n \log m)$$$ time.
Will be added after open hacking phase
[problem:2065D]
Problem Credits: cry
Analysis: macaquedev
It is clear that the score of an array $$$b$$$ of length $$$n$$$ can be expressed as $$$n * b_1 + (n-1) * b_2 + (n-2) * c_2 \dots + 1 * b_n$$$.
Let's solve this problem with $$$n=1$$$ for just one array with $$$m$$$ elements in it. Due to the above fact, it's clear that the optimal way to arrange this array is to sort the elements from largest to smallest.
Now, we come to the issue of combining arrays. Suppose you have two arrays $$$a$$$ and $$$b$$$, both of length m. Is there a nice way of expressing the score of $$$a+b$$$ and the score of $$$b+a$$$ (where $$$+$$$ represents concatenation) in terms of $$$score(a)$$$ and $$$score(b)$$$?
Turns out there is. The score of $$$a+b$$$ is equal to $$$n * sum(a) + score(a) + score(b)$$$. This is because of the following:
$$$score(a+b) = (2n * a_1) + ((2n-1) * a_2) \dots + ((n+1) * a_n) + (n * b_1) \dots + (1 * b_n)$$$
Now, we can clearly replace all the $$$b$$$ terms with $$$score(b)$$$ as follows: $$$score(a+b) = (2n * a_1) + ((2n-1) * a_2) \dots + ((n+1) * a_n) + score(b)$$$
Now, we can take out a factor of $$$n$$$ as follows: $$$score(a+b) = ((n+n) * a_1) + ((n + (n-1)) * a_2) \dots + ((n+1) * a_n) + score(b)$$$ $$$score(a+b) = (n * (a_1 + a_2 + a_3)) + (n * a_1) + ((n-1) * a_2) \dots + (1 * a_n) + score(b)$$$ $$$score(a+b) = (n * sum(a)) + score(a) + score(b)$$$
Therefore, whichever of $$$a$$$ and $$$b$$$ has the larger sum should go first, because then you get a larger overall score. This argument also extends beyond two arrays, so the solution is as follows:
Sort each array in decreasing order. Sort the arrays themselves in terms of their sum, from largest sum to smallest Put together the final array Take the score This score is guaranteed to be maximal.
Will be added after open hacking phase
[problem:2065E]
Problem Credits: Proof_by_QED
Analysis: macaquedev
Claim 1: It is impossible when $$$k < |n-m|$$$
Proof 1: The entire string will have a balance value greater than $$$k$$$.
Claim 2: It is impossible when $$$k > max(n, m)$$$
Proof 2: The maximal possible balance value of any string with $$$n$$$ ones and $$$m$$$ zeroes is $$$max(m, n)$$$, as it is impossible due to the balance value definition.
To complete the construction, WLOG $$$n>m$$$ (because you can invert the string to get the solution for $$$n<=m$$$. Output $$$k$$$ zeroes, then output alternating ones and zeroes, then output the remaining ones at the end. Note that with this construction, a substring with balance value $$$k$$$ exists (as you can take the first $$$k$$$ numbers), but a substring with balance value $$$>k$$$ does not exist (as taking more of the string cannot increase the balance value).
Will be added after open hacking phase
[problem:2065F]
Problem Credits: chromate00
Analysis: chromate00
Assume that a sequence a of length $$$n$$$ contains two types of elements, $$$1$$$ denoting majority and $$$0$$$ denoting "not majority".
Then, if a contains a majority and $$$n \ge 2$$$, the following condition holds. a must contain either $$$[1,1]$$$ or $$$[1,0,1]$$$.
This can be shown by contradiction. It is given that there are $$$k$$$ instances of $$$1$$$ and $$$n-k$$$ instances of $$$0$$$. Then it is known that $$$k>n-k$$$, so $$$2k>n$$$. If a does not contain $$$[1,1]$$$, then it needs a $$$0$$$ between every $$$1$$$. The only way this can happen is when $$$n-k \ge k-1$$$. This means $$$n+1 \ge 2k$$$, but because $$$n<2k \le n+1$$$ the only value $$$k$$$ can take is $$$\frac{n+1}{2}$$$. When this happens, the only valid orientation of $$$a$$$ is $$$[1,0,1,0,\ldots,0,1,0,1]$$$, but still this contains $$$[1,0,1]$$$. Therefore, it definitely contains either $$$[1,1]$$$ or $$$[1,0,1]$$$.
But we can notice, the subarrays $$$[1,1]$$$ and $$$[1,0,1]$$$ already contain the majority $$$1$$$. So due to this, we conclude that the tree containing the pattern $$$[k,k]$$$ or $$$[k,x,k]$$$ for some value $$$k$$$, is an equivalent condition to the tree containing a non-trivial path with majority $$$k$$$.
Checking the existence of $$$[k,k]$$$ and $$$[k,x,k]$$$ in the tree for all k can be done in $$$\mathcal{O}(n)$$$ time, due to $$$\sum{\text{deg}} = 2m = 2(n-1)$$$. The problem has been solved in $$$\mathcal{O}(n)$$$ time.
You can solve this problem using the Auxiliary Tree technique. Formally, the auxiliary tree of $$$k$$$ specified vertices is the tree consisting of the specified vertices and their pairwise lowest common ancestors. It can be shown that such a tree will always have $$$\mathcal{O}(k)$$$ vertices and can be found in $$$\mathcal{O}(k \log n)$$$ time using widely known algorithms.
Observe the fact that, when you transform the value $$$x$$$ into $$$1$$$ and all other values into $$$-1$$$, $$$x$$$ is the majority of the sequence if and only if the transformed sequence has a positive sum. This hints us towards finding the maximum sum of any non-trivial path under the transformed tree. If the maximum sum is found to be positive, then we can determine that there exists a path with $$$x$$$ as its majority.
This subproblem can be solved by running a modified version of Kadane's algorithm, adapted for use on a tree. This adaptation is widely known for the case when the given tree is a binary tree, and it is trivial to modify it for use on any tree while keeping the time complexity to be $$$\mathcal{O}(n)$$$.
The only problem is that solving this for all values is $$$\mathcal{O}(n^2)$$$, so we compress the tree for each value using the Auxiliary Tree technique. By getting the auxiliary tree for the specified vertices, you get the specified vertices and their LCAs. If some vertex is specified, the value on it is transformed into $$$1$$$. Otherwise, the value on it is transformed into $$$-1$$$. Meanwhile, now there are lengths on edges, and an edge with length greater than $$$1$$$ means that there are unspecified vertices compressed in the edge. Therefore, if an edge has length $$$l$$$ which is greater than $$$1$$$, make sure to make a new vertex with value $$$-l+1$$$ in the middle of the edge as it means that $$$l-1$$$ vertices are compressed into the edge.
As there are $$$n$$$ specified vertices in total, finding each auxiliary tree takes $$$\mathcal{O}(n \log n)$$$ time. Solving the rest of the problem for each $$$i$$$ only takes $$$\mathcal{O}(n)$$$ time trivially. Thus, the problem has been solved in $$$\mathcal{O}(n \log n)$$$ time.
Will be added after open hacking phase
[problem:2065G]
Problem Credits: larush
Analysis: Proof_by_QED
Let $$$a_i=x$$$ and $$$a_j=y$$$ for any pair $$$(i,j)$$$ that we count.
First, let's note that since $$$x|lcm(x,y)$$$, we don't need to consider any cases where $$$x$$$ or $$$y$$$ has more than two prime factors. There are three cases we must consider:
$$$x$$$ and $$$y$$$ are primes, and $$$x\neq y$$$. Then, $$$lcm(x,y)=x\cdot y$$$ and has two prime factors.
$$$x$$$ is a semiprime, and $$$y$$$ is a prime factor of $$$x$$$. Then, $$$lcm(x,y)=x$$$.
$$$y$$$ is a semiprime, and $$$y=x$$$.
To count this, let's first factorize each number in the array (either by trial division in $$$O(n\sqrt{a_i})$$$ or $$$O(n\log(n))$$$ sieve precomputation). Let's maintain two maps, one mapping each semiprime present in the array to its number of occurrences, and one mapping each prime present in the array to its number of occurrences. Let $$$cnt[x]$$$ be the number of occurrences of $$$x$$$. Then, we can count each case as follows:
Let the total number of primes be $$$P$$$. For each prime $$$p$$$, its contribution will be $$$cnt[p]\cdot(P-cnt[p])$$$. Note that we must divide our result by $$$2$$$ as we would have counted each pair twice.
For each semiprime $$$pq$$$, add $$$cnt[pq]\cdot cnt[p]+cnt[pq]\cdot cnt[q]$$$.
For each semiprime $$$pq$$$, add $$$cnt[pq]\cdot (cnt[pq]+1)/2$$$.
All of these can be done in $$$O(n\log n)$$$ time. Be sure to not use dictionary, counter, or unordered_map as they can be hacked!
Will be added after open hacking phase
[problem:2065H]
Problem Credits: Proof_by_QED
Analysis: efishel
A brute attempt at a solution would be to go through each non-empty subset of $$${1,2,...,n}$$$ and, for every pair of adjacent indices $$$(i, j)$$$ in the subset, increase $$$ans$$$ if $$$s[i] != s[j]$$$ In other words, increase ans every time $$$s[i]$$$ and $$$s[j]$$$ create a new border
This is extremely slow at $$$O(2^n*n)$$$; however, we can notice that every adjacent pair is independent from the rest in the subset. We may ask ourselves: for a fixed $$$(i, j)$$$, how many subsets increase ans through that $$$(i, j)$$$? The conditions are that: - $$$i$$$ and $$$j$$$ are in the subset - $$$i$$$ and $$$j$$$ are adjacent in the subset (there's no other included value in between) - $$$s[i] != s[j]$$$
Which leaves us free to choose the prefix and the suffix. $$$(2^{i-1}*2^{n-j})$$$.
An $$$O(n^2)$$$ solution is:
ans := 2^n-1
for j (1<=j<=n):
for i (1<=i<j):
if (s[i] != s[j])
ans += 2^(i-1)*2^(n-j)
The rest of the solution will try to optimize how to compute that sum, and then how to maintain the answer through updates. We may notice we can pull out the $$$2^{n-j}$$$ factor and rewrite the loops as:
ans := 2^n-1
for j (1<=j<=n):
sumI := 0
for i (1<=i<j):
if (s[i] != s[j])
sumI += 2^(i-1)
ans += sumI*2^(n-j)
Since the second for loop only cares about what $$$s[j]$$$ is (nothing else about $$$j$$$), we can again easily optimize it as: In other words, we don't need to recalculate $$$sumI$$$ each new $$$j$$$. Instead, we can maintain its $$$2$$$ possible values ($$$s[j]=0, s[j]=1$$$) as we increase $$$j$$$ (since $$$sumI$$$ cares about ($$$1<=i<j$$$))
ans := 2^n-1
sumI := [0, 0]
for j (1<=j<=n):
ans += sumI[s[j]]*2^(n-j)
sumI[s[j]\oplus1] += 2^(j-1)
We can run this $$$O(n)$$$ solution once before any updates, but not after each update because $$$O(q*n)$$$ is too slow. Instead, we can make the minimal adjustments needed to maintain ans correctly. Let's call the toggled index $$$k$$$: How much does $$$s[k]$$$ contribute to ans in the first place? We can partition $$$s[k]$$$'s contribution to the answer in $$$2$$$ cases: - When $$$j=k$$$, $$$ans += sumI[s[k]]*2^{n-k}$$$ - After $$$sumI[s[k]\oplus1] += 2^{k-1}$$$, every time $$$sumI[s[k]\oplus 1]$$$ is used to increase ans
As for the first case, we can calculate the value of $$$sumI[s[k]]$$$ at $$$j=k$$$ using the sum of $$$2^{i-1}$$$ for $$$i < k$$$ and $$$s[i]=s[k]\oplus1$$$. As for the second case, it's only slightly trickier, but along the same general idea. It can be calculated using the sum of $$$2^{n-j}$$$ for $$$j > k$$$ and $$$s[j]=s[k]\oplus 1$$$.
Fenwick (or segment) tree solves both cases, which are essentially dynamically calculating range sums on an array. Since for both cases we may consider when $$$s[k]=0$$$ or $$$s[k]=1$$$, a total of $$$4$$$ different fenwick trees will be needed. $$$(2^{i-1}$$$ when $$$s[i]=0, 0$$$ otherwise); ($$$2^{i-1}$$$ when $$$s[i]=1, 0$$$ otherwise); $$$(2^{n-j}$$$ when $$$s[j]=0, 0$$$ otherwise); $$$(2^{n-j}$$$ when $$$s[j]=1, 0$$$ otherwise)
The procedure is thus: before toggling a bit, subtract its contribution from ans. After toggling the bit, add its new contribution to ans. Also, update the $$$4$$$ fenwick trees accordingly. This correctly maintains ans in $$$O(log(n))$$$ per update.
So, the final complexity is $$$O(n+q*log(n))$$$
Will be added after open hacking phase