| # | User | Rating |
|---|---|---|
| 1 | Benq | 3676 |
| 2 | jiangly | 3670 |
| 3 | Kevin114514 | 3657 |
| 4 | maroonrk | 3355 |
| 5 | Um_nik | 3353 |
| 6 | squareOf105 | 3346 |
| 7 | tourist | 3343 |
| 8 | strapple | 3324 |
| 9 | heuristica | 3322 |
| 10 | jiangbowen | 3291 |
| # | User | Contrib. |
|---|---|---|
| 1 | Qingyu | 158 |
| 2 | nik_exists | 150 |
| 2 | maspy | 150 |
| 4 | AmShZ | 143 |
| 5 | Um_nik | 141 |
| 6 | Errichto | 139 |
| 7 | adamant | 137 |
| 8 | BledDest | 133 |
| 8 | maroonrk | 133 |
| 10 | qwexd | 129 |
I just discovered a problem, https://qoj.ac/contest/1901/problem/8616, that the intended solution is https://codeforces.me/blog/entry/67001. Is there any sub $$$O(nq)$$$ solution for this problem?
I have a question regarding Div 3/4 editorials: Why isn't range trees being used in any problem except last Div 3 problem? Many problems seems more intuitive to do with range trees than with sets. No need for iterators and is certainly more flexible, too. One such example I have seen is 1374E2 - Чтение книг (сложная версия), where two Fenwick trees with binary lifting is, in my opinion, more direct and easy to understand than the editorial's solution.
Given a tree rooted at node $$$1$$$, each node $$$i$$$ has value $$$a_i$$$, let $$$s(u)$$$ denote the set of nodes in $$$u$$$'s subtree. You should calculate the sum: $$$\sum_u{(XOR_{c\in s(u)}(a_c+d(u,c)))}$$$.
I have reduced the problem to:
Add 1 to every number on a segment.
Find XOR on a segment.
But I can't think of any DS that solves the problem above. Any help will be appreciated.
I have this code here: https://codeforces.me/contest/444/submission/310588587. It is really weird that:
On custom invocation, it sometimes output 6, then after that it just do -1
The res[id][i] value never seems to be written to the correct value (2), even though I have checked for overflow and the value is correct
On my machine, it output 2 as normal.
Putting res as a global variable fixes the above.
Can anyone explains why this happen, is it a bug in my code or a bug on Codeforces?
There is a problem that I solved earlier: Find how many permutations p s.t. $$$|p_i-i|\leq k$$$ for all $$$i$$$. Constraints: $$$n\leq 10^9,k\leq 4$$$. I solved it using matrix multiplication (converted ARC132C 's transitions to matrix form), but naively multiplying the matrix creates the insane complexity of $$$O(64^k*\log(n))$$$. By skipping the non-zero terms in the left hand side, I was able to get it passed. Can anyone explain why this passes, and maybe prove the complexity of it?
Is this problem doable with less than $$$O(n\sqrt{n}log(log(n)))$$$ time?
Given an array $$$p$$$, assuming $$$p_i=O(n)$$$. The array is cut to $$$O(\sqrt{n})$$$ blocks.
There is only one kind of query:
$$$1\ i\ j\ k$$$: Count the numbers from block $$$i$$$ to block $$$j$$$ such that $$$p_k$$$ is a multiple of (the query must be done in $$$O(1)$$$).
Any help is appreciated.
Given the problem below: Find the lexicographically minimum cyclic shift of a binary string s of length n ($$$n\leq 3*10^4$$$). A normal brute force solution runs in only 0.05s:
string x = s;
for (int i = 1; i < s.size(); i++)
{
string x2 = string(s.begin() + i, s.end()) + string(s.begin(), s.begin() + i);
if (x2 < x)
x = x2;
}
cout << x << endl;
I only know an $$$O(n^2)$$$ algorithm (the algorithm above) or $$$O(n^2/w)$$$ using bitsets. Is this the intended solution, or is there any better algorithm?
We will describe an approach that solves this problem in at most $$$3*n+3$$$ queries. The first 3 queries are for getting the counts of A,T,G,C.
We can search for 2 characters at once:
Assume that the queried string is "yyyyyyyy...yyyyxyyyyyyy...yy" (x and y are 2 different characters)
If the similarity count has increased by 1 from "yyyyyyyyyyyyyyyy...y" then the character is x, else, if it has decreased by 1, then it is y.
We search for the first 2 characters with the most count, which will take $$$2*n$$$ queries.
Then we search for the last 2 characters, which will take $$$n$$$ queries at most (since at least $$$n$$$ characters have been searched in the string before).
Complexity: $$$O(n^2)$$$.
Code: https://codeforces.me/contest/1981/submission/263736407
It is easy to observe that the gcd is <= min, and one popcount operation reduces the min to <= $$$log(a)$$$.
So we can just brute force all gcds from 2 to log(a), note that each element takes $$$O(log^{*}(a))$$$ iterations to be reduced to 1.
Complexity: $$$O(n*log(a)*log^{*}(a))$$$.
Code: https://codeforces.me/contest/1981/submission/263736978
One can see that pressing the button $$$k$$$ times applies $$$2^k$$$ times the original permutation on $$$[1,2,3,...,n]$$$.
To find how many times the permutation need to be applied on to go back to $$$[1,2,3,...,n]$$$, one can just use any solution of 1249B2 - Books Exchange (hard version) with the note that it is the LCM of the cycles.
To check for the power of $$$2$$$ fast one should use GCC builtins (that can do it in $$$O(1)$$$ instead of $$$O(log(n))$$$).
Complexity: $$$O(n)$$$.
Code: https://codeforces.me/contest/1981/submission/263738042
The probability of rolling a head after rolling $$$k$$$ heads and $$$n$$$ coins is $$$(50+n-2*k)\%$$$.
Let's use this fact to build a dp solution.
Let $$$hp(k,n)$$$ being $$$(50+n-2*k)*828542813$$$ if $$$0\leq k \leq n$$$, else 0. (you will see why later).
$$$dp[heads][n]\equiv(hp(heads-1,n-1)*dp[heads-1][n-1])+((1-hp(heads,n-1))*dp[heads][n-1]))$$$ $$$(mod\ 998244353)$$$.
with $$$dp[0][0]=1$$$.
But: this solution is $$$O(n^2)$$$!
There is an observation that is needed to solve the problem.
It is:
The condition for $$$dp[i][j]$$$ to be nonzero is $$$max(0,\lceil{n/2}\rceil-25)\leq i \leq min(n,\lfloor{n/2}\rfloor+25)$$$.
So by shifting the positions in the dp array,
Let's create two new variables $$$shift1,\ shift2$$$ with $$$shift1$$$ being the shift on $$$dp[n]$$$ ($$$dp[heads][n]$$$ now turns to $$$dp[heads-shift1][n]$$$) and $$$shift2$$$ is the same for $$$dp[n-1]$$$.
Set $$$shift1$$$ to $$$max(0,\lceil{n/2}\rceil-25)$$$ and $$$shift2$$$ to $$$max(0,\lceil{(n-1)/2}\rceil-25)$$$. Let's modify the dp formula to use them. Now the dp formula is:
$$$dp[heads-shift1][n]\equiv(hp(heads-1,n-1)*dp[heads-1-shift2][n-1])$$$ $$$+((1-hp(heads,n-1))*dp[heads-shift2][n-1]))\ (mod\ 998244353)$$$ for $$$heads$$$ satisfying $$$shift1 \leq heads \leq min(n,\lfloor{n/2}\rfloor+25)$$$.
Since there are only a maximum of 51 values of $$$dp[heads][n]$$$ that is nonzero, we get a $$$O(n)$$$ solution.
Why 828542813? $$$828542813*100\equiv 1\ (mod\ 998244353)$$$.
Code: https://codeforces.me/contest/1981/submission/263741468
When I was doing 1207F - Задача об остатках, I don't know why my program got TLE. Then this ONE trick cut 1 second off my program. You can see this video for more information: https://www.youtube.com/watch?v=ssDBqQ5f5_0. When the compiler compiles x/9, the code roughly converts to ((long long)954437177*x)>>33. Division is a much more expensive operation than multiplies and shifts. But what's the special constant 954437177? It's $$$\lceil \frac{2^{33}}{9} \rceil$$$. So we have this identity which is vaild for every $$$0\leq a \lt 2^{31}, 0 \lt x \lt 2^{31}$$$:
You can clearly see how this speeds up 1207F: 244531668, 244540601. Note that gcc also does this trick on 64 bits.
After brute forcing with $$$a = 2^{31}-1$$$ I got this new, fixed identity. This should work for all $$$a$$$ (while the old one does not).
This is only a suggestion. GCC 13.2 have nearly full C++23 support & (we once had GCC 11 with C++20). So I just want that GCC 13.2 (or 14) has C++23 support enabled with -std=c++23 (as another GCC 13 compiler option, or when GCC 14 is released, or when GCC 11 is back).
| Name |
|---|


