Tutorial is loading...
Tutorial is loading...
Tutorial is loading...
Tutorial is loading...
Tutorial is loading...
Tutorial is loading...
Tutorial is loading...
Tutorial is loading...
Tutorial is loading...
# | User | Rating |
---|---|---|
1 | tourist | 4009 |
2 | jiangly | 3821 |
3 | Benq | 3736 |
4 | Radewoosh | 3631 |
5 | jqdai0815 | 3620 |
6 | orzdevinwang | 3529 |
7 | ecnerwala | 3446 |
8 | Um_nik | 3396 |
9 | ksun48 | 3388 |
10 | gamegame | 3386 |
# | User | Contrib. |
---|---|---|
1 | cry | 164 |
1 | maomao90 | 164 |
3 | Um_nik | 163 |
4 | atcoder_official | 161 |
5 | -is-this-fft- | 158 |
6 | awoo | 157 |
7 | adamant | 156 |
8 | TheScrasse | 154 |
8 | nor | 154 |
10 | Dominater069 | 153 |
Name |
---|
Why does 63503240 gives TLE in div2 B2?
t = 1e4 and k = 1e6
Because you are allocating and initializing
cnt
for every test case, which makes your code O(tk). Check the values of $$$t$$$ and $$$k$$$ in the question — these values will definitely result in a TLE.Thank you guys. I completely ignored k. Changing array to map does the trick
or you can delete
cnt
after each queryyou can use map,not the ans to index,the ans will TLE
I made the same mistake hah
I thought about clean cnt with n but I didn't fix it
I solved D, with a different approach(after contest).
I calculated divisors of $$$x^k$$$ for every $$$x$$$ such that 1 <= $$$x$$$ <= $$$10^5$$$ and $$$x^k$$$ <= $$$1e10$$$.Since $$$x$$$ can be only in range $$$1$$$ to $$$10^5$$$ in worst case, we can calculate the divisors of $$$x^k$$$ using prime factors of $$$x$$$. Caluculating prime factors of $$$x^k$$$ is easy if we know prime factors of $$$x$$$, we just need to multiply power of every particular prime factor by $$$k$$$. Since we know divisors of every $$$x^k$$$ we can easily count pairs such that $$$Ai*Aj$$$ = $$$x^k$$$.
I don't see your "Accepted" for this problem and how would you then calculate the answer not in an at least quadratic time? It doesn't seem like a good solution to me.
Link to Submission.
I already mentioned that i solved it after contest.
Time complexity of my solution is $$$ (\Sigma_{i=1}^{10^5} divisors(i^k)) * C$$$ (let C be some constant) for calculating divisors,and worst case of this approach occurs when k = 2 because in this case we have to calculate divisors of $$$10^5$$$ numbers. When i computed on my pc they were roughly $$$6*10^6$$$ which is not much for a problem with 2 sec TL.
Oh, I thought that I see all your submissions when I go to your profile but apparently I don't. Thanks for the link.
There is an option named "show unofficial".
Thank you! I could have thought about it.
Thanks for your method to calculate divisors. I used a similar overall solution but the only difference was the method in which I tried to calculate divisors. It gave a TLE for $$$k==2$$$ For each x such that $$$ x^k<(10)**10 $$$, I calculated the divisors using $$$O(\sqrt(x))$$$ method. Which apparently miserable fails for $$$k==2$$$ but works fine for all others
Can someone explain why is that giving TLE?
See this for finding divisors using prime factors.
Can someone tell me what is wrong in my coding approach for Power Products(D)
I am sorting the array and using two pointer approach to find possible pairsI
63471990
Check on this Tc:
5 2
1 1 1 1 1 It's answer is 10 and yours give 4.
Yeah, I guess because of the repeated numbers two pointers approach won't work. Thanks for checking it out.
Has the tutorial not been made or there is some bug.It is showing tutorial not available for problems D-G
Edit:resolved
The analysis is complete, but there is an issue with loading it from Polygon automatically. This usually resolves itself eventually.
It has not been uploading for me for about 30 mins now, could you please resolve it or tell how to resolve the same. Thanks!
in Problem E what is the best RSQ can be used with a few implementation cause i thought of segment tree so that we have n segment tree of base m and m segment tree of size n but it would be a lot of implementation so what do u think ?
In problem $$$C$$$, why does $$$n-kp$$$ has to be at least $$$k$$$ can someone please throw some light on it?
Because you’re writing it as sum of k power of 2s which are all bigger than or equal to 1
Thanks man! Got in now
because the number of digits in the binary representation of the max value can be
Please look upon the issue of editorial.It's showing that "Tutorial is not available"
can someone explain how to solve div2E/div1C , in editorial it's not clear about defination of D,R arrays?
It would be great if someone can explain me easier way solution of div2-C. I cant understand the solution and I,m not so fimiliar with binary numbers, bit cnt etc.
Thanks a lot. :)
Let the minimum number of $$$p$$$-binary numbers required to represent $$$n$$$ be $$$l$$$. We start from $$$l = 1$$$ and increment $$$l$$$, testing its possibility. If it's possible in $$$l$$$ $$$p$$$-binary numbers, then that means that $$$n = (\text{sum of }l\ \text{powers of}\ 2) + lp$$$, because we get a $$$+p$$$ contribution from each of the $$$l$$$ $$$p$$$-binary numbers. So we need to check if $$$n - lp$$$ can be represented as a sum of $$$l$$$ powers of $$$2$$$, not necessarily distinct.
Now you can represent a number uniquely in any integral base greater than 1. It will result in a unique representation. Now given $$$n - lp$$$, you need at least $$$\lfloor log_2{(n-lp)} \rfloor + 1$$$ bits to represent $$$n$$$, and that is the binary representation of $$$n - lp$$$. So we get one condition that $$$l \geq \lfloor log_2{(n-lp)} \rfloor + 1$$$.
Consider the example: $$$n-lp = 2^2 = (100)_2$$$. We can write this as $$$2^2 = 2^1 + 2^1 = 2^0 + 2^0 + 2^1 = 2^0 + 2^0 + 2^0 + 2^0$$$ In each subsequent representation we are breaking a power of $$$2$$$ down and adding one term in the representation. This shows us that we can represent $$$2^a$$$ in $$$1$$$ to $$$2^a$$$ terms, therefore we can represent $$$\sum 2^a$$$ in $$$\sum 1$$$ to $$$\sum 2^a$$$ terms. If we choose $$$a$$$ from the binary representation of $$$n - lp$$$, $$$\sum 2^a = n-lp$$$ and $$$\sum 1 = \text{sum of bits in}\ n-lp = \sigma$$$ (say). So $$$l$$$ must satisfy $$$\sigma \leq l \leq n-lp$$$. In GCC,
__builtin_popcount(n-lp)
can be used that gives the value of $$$\sigma$$$ (sum of bits).Now $$$n \leq 10^9$$$ and $$$p = 1000$$$, so number of bits in $$$n-lp$$$ should be the same as that in $$$n$$$. A satisfactory upper bound should be 34. Start from $$$l = 1$$$ to $$$34$$$, and check if $$$\sigma \leq l \leq n-lp$$$; if it's true, then you have your value of $$$l$$$.
thau
thanks bro..you explained really well
My approach for D:
Let $$$f_{1}$$$ be a function such that $$$f_{1}(a)=b$$$ for $$$1 \le a \le 10^5$$$ where $$$b=p_{1}^{c_{1}}p_{2}^{c_{2}}...p_{m}^{c_{m}}$$$. Here $$$p_{i}$$$ is a prime and $$$c_{i}<k$$$.
Let $$$fr$$$ gives frequency of an element in given array. Hence for $$$1 \le i \le 10^5$$$ do $$$freq[f_{1}(i)]=freq[f_{1}(i)] + fr[i]$$$.
Now, let $$$f_{2}$$$ be a funtion such that $$$f_{2}(a)=b'$$$ where $$$b'=p_{1}^{k-c_{1}}p_{2}^{k-c_{2}}...p_{m}^{k-c_{m}}$$$.
The answer is ans
$$$ ans= \begin{cases} ans \enspace + \enspace freq[f_{1}(i)] \times freq[f_{2}(i)], & \text{if } f_{1}(i) \ne f_{2}(i)\\ ans \enspace + \enspace freq[f_{1}(i)] \times (freq[f_{2}(i)] - 1)/2, & \text{otherwise} \end{cases} $$$
Note: Chech if $$$f_{1}(i)$$$ has already been calculated as $$$f_{1}(i) = f_{1}(j)$$$ for $$$i \ne j$$$.
Link to code
Alternative solution to G:
Time complexity: 1200 ms.
So someone cheesed this problem after all, huh. Nice job!
With enough stress-testing I've managed to time out this solution very slightly with this test:
11
Main observation: the loop "for each set bit in v1, shift v2" allows a massive speedup if v1 has just one set bit, which is very often the case for small subsets. (I already tried your hack.)
Could anyone please explain "dumb" dp? I don't get what is the dp state there.
"Using a subset $$$S$$$ of the given numbers, can we create a number $$$j$$$?" The values of the states are 0/1, there are $$$O(2^N \sum a_i)$$$ of them.
Thanks! How do you end up with $$$N^{\alpha}$$$ in the complexity?
Choose $$$\alpha$$$ arbitrarily. Then, there's always $$$N^\alpha$$$ in any complexity. In this case, it's the exponential and sum that matter, so I didn't bother thinking what $$$\alpha$$$ is.
Alright, got it.
I waited for like 10 MINUTES and there was still no editorial. Can anyone who can see the editorial for Div. 1 B to Div. 1 F consider posting the editorial on somewhere else for others' convenience?
Still, Tutorial is not available ...
I got TLE in div2 B2 when contest final consequence came out.But accepted it after contest with exactly the same codes.
Is this an alternative solution to problem F(Div. 1)?
Again, solve it backwards.
Consider elements in [L, X] can reach X in no more than K steps. Then, elements in [L', X] can reach X in no more than K + 1 steps, where L' = min_i{pre[i], L <= i <= X} where pre[i] = the last occurance of ch[i] before i(ch[] is the string in the input).
Let's try to fix X. Then, the process above forms a tree structure, and what we need to compute is the sum on the path from X to the root.
Consider how does the tree change when 1 is added to X. The parent of an interval [[the minimal Y such that min{pre[Y...X]} >= pre[X]], X] will be modified to pre[X] while the other vertices of the tree remain unchanged. Put the intervals with the same parent together and we only need basic operations in dynamic trees to fix it.
Use Link Cut Tree or Euler Tour Tree(I'm not sure because I don't know ETT well) to solve the problem in O(n log n).
For Div2 C can someone explain the case when P is negative answer for K still won't cross 31
Let $$$p < 0$$$, then the maximum value of $$$n - 31p$$$ will be $$$10^9+31000$$$ which can be represented with 30 binary digits (less than 31). It's obvious that all the numbers less than $$$10^9+31000$$$ can also be represented with no more than 30 binary digits. So $$$k=31$$$ will always be possible.
But whose telling you to stop at 31p for p<0 ,I can still keep on subtracting it
We wish to find the minimum answer. So if we know that surely 31 is a possible answer, then we won't check for numbers greater than 31.
In solution of D there is a small mistake. It is given that 360 = 2^3 * 2^2 *5 but it should be 360 = 2^3 * 3^2 * 5
Could someone give me a elaborated explanation for problem Div2-C. The Edtiorial is so hard to grasp, especially the range of all $$$k$$$ value. Thanks
Thank you very much! Excellent Explanation.
But what happen if I let
x = n-1e9*p
? I am confused that: I want to represent $$$n-kp$$$ not just $$$n-31p$$$.The given case will come under one of the two cases mentioned
I got it, the reason we don't need a large k like that, we always can find the answer with k < 31.
Exactly
Hint : How to represent a number as exactly k powers of 2.
Hint cl
Why does https://codeforces.me/contest/1225/submission/63542673 give TLE using g++, but works with MSVC???
I just know why the code got TLE using g++. Because there may be 1e5 test case. And for each test case, the value of k can be 1e6. Then the code will run Line 24 1e5*1e6 times. It got TLE here.
In case(like me ) you are having a hard time implementing problem D tutorial (DIV 2) here is a implementation of the given approach
https://codeforces.me/contest/1225/submission/63557938
Can someone explain B2 to me..
Think in terms of sliding window u need to count minimum unique elements at a given window and keep sliding window till the end. See my submission
Thanks,doubt cleared....
Typo in ur editorial of D -> factorisation of 360 should be 2^3 3^2 5^1 u mistyped 2 in place of 3
Maybe it will be useful for users who will try to solve this task later. I've found that the following solution passes all authors' tests although it's incorrect: Let's consider DP[N][X][Y] — it is 1, if we can apply such consequence of operations to N-length prefix of an array so that last two numbers are X and Y, and 0 if we can't. Then DP[2][A[1]][A[2]] = DP[2][A[2]][A[1]] = 1, and for each i from 2 to N and X, Y from 1 to 2000 if DP[i — 1][X][Y] == 1 then DP[i][f(X+A[i])][Y] = DP[i][Y][f(X+A[i])] = DP[i][X][f(Y+A[i])] = DP[i][f(Y + A[i])][X] = DP[f(X+Y)][A[i]] = DP[A[i]][f(X+Y)] = 1. So in the end we just have to check if for some X, Y such that f(X+Y)=1 DP[i][X][Y] == 1, and restore the answer. The problem is that in general it's not true that f(f(a+b)+c) = f(a+f(b+c)). Test that breaks this solution: 8 4 39 39 51 13 38 66 98 86
I found it interesting that my friend skip1978 solved div1 E using the random method.
I wonder how high the correct rate of this method is.
63493030
Very, very high at least without trying to design a countertest. It took me many hours of runtime to find a test where it fails — specifically, where the probability that a random sequence of operations works is low enough... although maybe I could buy processing power in the cloud and find more. And that's still just because it reshuffles $$$N$$$ times. With some optimisations, finding a test where it fails would be near impossible because $$$N$$$ is so low.
Can someone please tell me what is wrong with my prime factorization in this code for D : Code 1
Also , after changing it I got ac Code 2
Thanks in advance !
I think the code is wrong because of Line 16. The end value of x may be 2 when the begin value of x is 2. Then it will not think 2 has the prime factor 2. the code will be wrong if there is 2 in the input.
Oh I see! Got ac in that too now. Thanks a lot! :D
I cant understand in D one thing. What if we have ones? This solution doesn"t work in this case.
1 is just the empty list.
Can somebody tell me how to solve div2 B2 in O(n) as maintaining count with array will give TLE?
use map
Then it will be O(nlogn)
Use unordered_map, then it's O(n)
I just figured out with help of my friend (shivang) to store accessed elements(O(n)) in a vector and then assign value 0 to those location present in vector. link to my submission:
https://codeforces.me/contest/1247/submission/63850376
Can someone explain problem E to me?
In the task D how can we find factorization of every number in the sequence with sqrt(max ai) or log2(max ai) complexity?__
Perhaps it means sqrt(max a[i]) for each number separately so total of n*sqrt(max a[i]) (or nlog(max a[i]))
I am unable to understand E's editorial. please help.
Thanks for Fast Editorial.
In problem D, we don't need to store the whole list. We know that each list gives us unique number so we just store that number and its frequency.
My $$$O(n^\frac{5}{3})$$$ code works for D, just thought it was interesting and curious that it got accepted.
On a second look, I think it can be hacked easily. The test cases for D were quite weak.
233245894
Why don't the dickhead authors provide their own code ?