Блог пользователя YouKn0wWho

Автор YouKn0wWho, 3 года назад, По-английски

The problem names are based on my favorite characters out there. Yes, 1554E - You are my most favorite character UwU.

I have tried to make the editorials as interactive as possible. Enjoy.

Tutorial is loading...
Code(C++)
Code(Python)
Tutorial is loading...
Code(C++)
Code(Python)
Tutorial is loading...
Code(C++)
Code(Python)
Tutorial is loading...
Code(C++)
Code(Python)

If you are wondering(as you always do 。^‿^。) about the checker:

Checker
Tutorial is loading...
Code(C++)
Разбор задач Codeforces Round 735 (Div. 2)
  • Проголосовать: нравится
  • +328
  • Проголосовать: не нравится

»
3 года назад, # |
  Проголосовать: нравится +24 Проголосовать: не нравится

Nice contest :)

  • »
    »
    3 года назад, # ^ |
      Проголосовать: нравится +8 Проголосовать: не нравится

    I laughed so hard when saw that B's statements were updated and the only update was replacement of 2 with a 1 at the end ;))

»
3 года назад, # |
  Проголосовать: нравится -23 Проголосовать: не нравится

A < C < D < B < E

»
3 года назад, # |
  Проголосовать: нравится +14 Проголосовать: не нравится

Such thinkforces B

»
3 года назад, # |
  Проголосовать: нравится +62 Проголосовать: не нравится

Kudos from India man. I really liked your problems. Looking forward to more Bangladeshi rounds.

»
3 года назад, # |
  Проголосовать: нравится +66 Проголосовать: не нравится

Nice contest, solving every problem costs a lot of thinking and observation!

»
3 года назад, # |
  Проголосовать: нравится +26 Проголосовать: не нравится

Like these problems, but don't like the order of the problems.

»
3 года назад, # |
  Проголосовать: нравится +23 Проголосовать: не нравится

It appears a lot of people misread E (I thought the order of operations mattered, and the total count would be n!). Did none of the testers get this confusion? I feel like different sequences should have been in bold.

»
3 года назад, # |
  Проголосовать: нравится +123 Проголосовать: не нравится

Thanks for the nice problems and the quick editorial!

»
3 года назад, # |
  Проголосовать: нравится +10 Проголосовать: не нравится

The contest was a BIT difficult

»
3 года назад, # |
Rev. 2   Проголосовать: нравится +7 Проголосовать: не нравится

Observation forces

No doubt problems were very good.

»
3 года назад, # |
  Проголосовать: нравится -26 Проголосовать: не нравится

Problems were very cool this contest!

»
3 года назад, # |
  Проголосовать: нравится +39 Проголосовать: не нравится

The gap between D and E is a bit large.

»
3 года назад, # |
Rev. 2   Проголосовать: нравится +1 Проголосовать: не нравится

Nice contest, I'm fool.

»
3 года назад, # |
  Проголосовать: нравится +5 Проголосовать: не нравится

Read the solution for B and wonder where is my brain ::.

»
3 года назад, # |
  Проголосовать: нравится +160 Проголосовать: не нравится

»
3 года назад, # |
  Проголосовать: нравится +3 Проголосовать: не нравится

Really liked the problems. Thanks!

»
3 года назад, # |
Rev. 3   Проголосовать: нравится +3 Проголосовать: не нравится

Very Nice Contest!

Spoiler
»
3 года назад, # |
  Проголосовать: нравится +12 Проголосовать: не нравится

I cannot believe this solution passed system test 124170859 on problem D.

  • »
    »
    3 года назад, # ^ |
      Проголосовать: нравится +8 Проголосовать: не нравится

    Similar Solution: 124179999

    I don't think, it can be hacked, although I don't have a proof of upper-bound on no. of characters used is less than 27. (Worst case calculations give upperbound as 3*log3(n))

»
3 года назад, # |
Rev. 2   Проголосовать: нравится +3 Проголосовать: не нравится

Fast Editorial!

It's a great contest,I love it.

I thought the contest would exercise my mind, but E was too difficult for me ...... :(

»
3 года назад, # |
Rev. 2   Проголосовать: нравится +11 Проголосовать: не нравится

Loved the problemset. But D was easier than both B and C. My solution: 124163494

i.m.o., the problem ordering should've been: A — D — B — C — E

»
3 года назад, # |
Rev. 2   Проголосовать: нравится +25 Проголосовать: не нравится

My solution to B is not dependent on k. We have all the value of array less than or equal to n. With this can what can iterate x from 1 to ceil(log2(n)) and assume x= (Ai|Aj). For each x we will find top 2 index with greatest value such the Ai is a sub mask of x.

124158918

  • »
    »
    3 года назад, # ^ |
      Проголосовать: нравится 0 Проголосовать: не нравится

    How do we know if x exists as OR of ai , aj? And you're not checking every sub-masks?

    Could you please explain?

    • »
      »
      »
      3 года назад, # ^ |
        Проголосовать: нравится +1 Проголосовать: не нравится

      "How do we know if x exists as OR of ai , aj?"

      you are correct. It will not exist for every x. But we have to maximize the answer. It may happen that we may end up calculating the candidate answer for certain x which does not exit. But since, we are going through every mask, we will calculate the answer for all submasks of x too. If that submask is actually possible for some (ai|aj) then it will override the answer as submask(x) < x.

      "And you're not checking every sub-masks?"

      I am checking every submask. The top 2 value I am picking are the maximum 2(if possible) index from all possible submasks. Let say mask y=101010. Then I have already calculated the top 2 value for all the value <y. When I process y I just check these masks (001010,100010,101000), Since these invidually conatins the best 2 indices of all their submask, I am able to get all best two from all submask of y. Also the mask =001000 will contribute to (001010,101000) therefore we may end up having a duplicate index. We have to take care of that.

»
3 года назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

Can't understand how binary search will apply for problem c

Help apricated

  • »
    »
    3 года назад, # ^ |
      Проголосовать: нравится 0 Проголосовать: не нравится

    Why do you need binary search for C??

    • »
      »
      »
      3 года назад, # ^ |
        Проголосовать: нравится 0 Проголосовать: не нравится

      I have seen some solution with binary search

      just curious to know but unable to understand how binary search property makes sense

  • »
    »
    3 года назад, # ^ |
      Проголосовать: нравится +6 Проголосовать: не нравится

    I did it using Binary search. So just try to understand the monotonic behaviour.

    Let Count(n,m, mid) is the function, that can give you the count of numbers that are less than or equal to mid from set of [n^0, n^1, n^2 ... n^m]; if(count(n,m, mid)==mid+1) it simply means our mex can't be less than or equal to mid+1.

    Now the only thing is how to build count() optimally. so it's a kinda digit dp problem. for more insights. u can visit my solution. https://codeforces.net/contest/1554/submission/124189939

»
3 года назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

Can anyone please explain B in some easy way??

  • »
    »
    3 года назад, # ^ |
      Проголосовать: нравится +9 Проголосовать: не нравится

    Well, my solution is different from the one in the editorial (and I don’t really think it’s simple), but here it is:

    If you fix the Ai | Aj part (let’s call it x from now on), you have to find 2 biggest indices i and j such that Ai | Aj = x, and then the solution is i * j / (k * x). Notice that 0 <= x <= 2 * n because Ai <= n. So, you can go through all x’s, and for every x, find the 2 biggest indices such that the numbers (bitmasks) on those indices are subsets of x (you can just go through all the subsets, check if they appear in the array and modify the max indices accordingly). But, the complexity of that is about n^2 if you’re not careful with implementation, so you have to use an optimization from this blog (look at the Suboptimal solution part, that optimization reduces the time complexity to 3^(log2(n))). And, I know I’m terrible at explaining things, so I suggest you to take a look at my code.

    Also, did anyone else have a similar approach? All the codes I’ve seen have an approach like the one in the editorial.

    • »
      »
      »
      3 года назад, # ^ |
        Проголосовать: нравится 0 Проголосовать: не нравится

      Yes, I solved it using SOS DP in O(NlogN) but still got TLE in system testing. And the same code was accepted in CPP 11 after the contest. :(

      https://codeforces.net/blog/entry/93321?#comment-822763

    • »
      »
      »
      3 года назад, # ^ |
        Проголосовать: нравится +6 Проголосовать: не нравится

      can u explain that we can be sure if x would present as Or of ai, aj. That is not any two subsets of x will give x on Bitwise Or.

      • »
        »
        »
        »
        3 года назад, # ^ |
          Проголосовать: нравится 0 Проголосовать: не нравится

        Yeah, that's true, but if we go through all possible x's, we'll definitely find the optimal solution, because, if some x is not present as an Or of Ai and Aj, then it's definitely not the best one (for some two numbers, their Or is the smallest number which contains them both as subsets, so all bigger numbers can be ignored). So, those x's won't affect the final solution.

      • »
        »
        »
        »
        12 месяцев назад, # ^ |
          Проголосовать: нравится 0 Проголосовать: не нравится

        It is actually better if max two subsets of x will not give x on bitwise or, as their bitwise or guaranteed to not exceed x.

  • »
    »
    12 месяцев назад, # ^ |
      Проголосовать: нравится 0 Проголосовать: не нравится

    Max value of $$$k(a_i\vert a_j)$$$ is $$$2kn$$$. So if you take a potential answer and see it is possible to increase $$$ij$$$ by more than $$$2kn$$$ you are guaranteed to arrive at a better answer. This rules out a significant portion of potential answers and you can brute force the rest in $$$\mathcal{O}(kn)$$$.

»
3 года назад, # |
  Проголосовать: нравится +6 Проголосовать: не нравится

Any meaning to the problem names?

»
3 года назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

for B I only checked all pairs for last K + 2 elements, instead of last 2K elements and still didn't FST. thanks

  • »
    »
    3 года назад, # ^ |
      Проголосовать: нравится 0 Проголосовать: не нравится

    Yeah, we can do it too. But we don't need to be precise, all we want is a good upper limit and AC.

»
3 года назад, # |
Rev. 2   Проголосовать: нравится +7 Проголосовать: не нравится
meme spoiler
»
3 года назад, # |
  Проголосовать: нравится -11 Проголосовать: не нравится

Hello I'm new to codeforces and also am a beginner I wrote this code for cherry problem but only pretests(2) are passed can someone explain me the reason?


#include <bits/stdc++.h> #define D 20 using namespace std; typedef long long int ll; int main() { ll T; cin>>T; while(T--) { ll n; cin>>n; ll a[n]; for(ll i=0;i<n;i++) cin>>a[i]; ll mx=INT_MIN; for(ll i=1;i<n;i++) mx=max(a[i]*a[i-1],mx); cout<<mx<<endl; } return 0; }
  • »
    »
    3 года назад, # ^ |
    Rev. 2   Проголосовать: нравится 0 Проголосовать: не нравится

    In the contest time, only two test cases will be judged and after the contest, other test cases will be judged that's why you can see pretests(2) passed.

    • »
      »
      »
      3 года назад, # ^ |
        Проголосовать: нравится 0 Проголосовать: не нравится

      ok thanks bro

      • »
        »
        »
        »
        3 года назад, # ^ |
          Проголосовать: нравится +5 Проголосовать: не нравится

        Hi akhilphenom

        provide code in spoiler so it takes lesser space.

        code
  • »
    »
    3 года назад, # ^ |
      Проголосовать: нравится +10 Проголосовать: не нравится

    Its better to leave now, than later.

»
3 года назад, # |
  Проголосовать: нравится +9 Проголосовать: не нравится

Pause_and_thinkforces

I had a hunch even before the contest that D was going to be relatively easy (didn't expect it to be this easy though). Only if I had believed in my instinct! Excellent (and a bit unusual) problemset.

»
3 года назад, # |
  Проголосовать: нравится +1 Проголосовать: не нравится

B can be easily done with sum over submask SOS Dp

see my sol

»
3 года назад, # |
Rev. 2   Проголосовать: нравится +1 Проголосовать: не нравится

Hey, can someone prove why this approach doesn't get TLEd? I'm not able to figure out.

Iterate on all the numbers in the array. Let's denote a number $$$a[i]$$$ special if there is no number $$$a[j]$$$ such that $$$j\gt i$$$ and $$$a[j]$$$ is a submask of $$$a[i]$$$. When reach and index $$$i$$$ in the array and $$$a[i]$$$ is special, we run a brute force for $$$j\lt i$$$. But we terminate the brute force loop when we find a number $$$a[j]$$$ such that $$$a[j]$$$ is a submask of $$$a[i]$$$ (but we do calculate $$$f(i,j)$$$ for this $$$j$$$).
Solution.

Or if someone could hack this solution :3.

»
3 года назад, # |
  Проголосовать: нравится +9 Проголосовать: не нравится

It is one of the best editorial because when i read every line i can connect with the thought process of the author and it is also beginner friendly to understand the concept. Thank You YouKn0wWho.

»
3 года назад, # |
Rev. 2   Проголосовать: нравится 0 Проголосовать: не нравится

My solution to Problem D which requires O(log(n)) different characters, which, unfortunately, does not enter(

Suppose we have a matching string s. Then the string s + x + s + y + s is also suitable, where x and y are symbols that have not been encountered before. After all, each substring in s occurs 3 * the past number, and a substring containing symbols x or y occurs 1 time. Also from s you can make a string from |s| + 1 characters just by adding x to the end. Thus, you can make an algorithm similar to fast exponentiation: Let gen (n) return a good string of n characters.

if n % 3 == 2 gen(n) = t + x + t + y + t, t = gen(n / 3) else gen(n) = gen(n — 1) + x

It can be seen that every 3 steps n will decrease at least 3 times, but this will require 4 new symbols. Therefore, you will need log_3(n) * 4 = 44 characters

P.S. I don't know English well and all the text was translated by google translate

  • »
    »
    3 года назад, # ^ |
      Проголосовать: нравится +4 Проголосовать: не нравится

    I wanted to elaborate on Your idea. Actually, I managed to pass the tests using recursive approach during contest 124173130. As You mentioned it would be convenient to think of the problem recursively. We want to make three copies (just two will not do) of the same string and then and then separate them, by some characters that not be use later in recursion. Each of those recursive string should also maintain task requirements. It is easy to see that if some substring of final solution is maintained entirely inside of one of these substrings then there are three copies of it.

    But we also have to be careful when it comes to substrings that are not entirely obtained in one of recursive areas. We aim for our separators to make them unique (or also have three copies).

    There three recursive cases. Let's $$$N$$$ be length of recursive call, and $$$A$$$ be the lowest character we are still able to use. Also lets name by $$$B$$$ second lowest character. We will show that it suffices only to use two characters for separation and then $$$2 \cdot \log_3{N} \le 26$$$ (which will allow us not to run out of letters)

    First case is $$$N \% 3 = 2$$$. This case is easy. If we mark recursive string of length $$$(N-2)/3$$$ by $$$R$$$, then we can create solution as follows:

    $$$S = R + A + R + B + R$$$

    Second case is a bit more tricky. We have $$$N\%3=0$$$. We are still able to create separators, but they will be lightly longer (also length of $$$R$$$ will now be $$$(N-6)/3$$$).

    $$$S = R + ABAA + R + BB + R$$$

    Last case was the most tricky one ($$$N\%3=1$$$). I used the following construction.

    $$$S = R + BA + R + B + R + B$$$

    Now we added something after the last recursive part, but it was necessary if we want to have total length of separators equal to 4 (7 is impossible, because one of the letters would be used even number of times, and 10 is quite long and I was not able to find any two separators that would solve this problem, and also we are not careful may run out of digits for base cases).

    The last thing is just to look at base cases of the recursion, but we can then use consecutive letters that are left (and there is at least 6 of them).

»
3 года назад, # |
Rev. 2   Проголосовать: нравится -7 Проголосовать: не нравится

I was so upset because of my bad contest day but the first line melted my heart -

»
3 года назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

As for me it isn't adequate to have at contest problems with rating: 800-1700-1800-1800-!2600!

Also I think, that order should be like A-D-B-C-E, or smth similar

But I really like each task separately, thnk u!

»
3 года назад, # |
  Проголосовать: нравится +17 Проголосовать: не нравится

E can be solved in $$$O(n \log^2 n)$$$ time if the product $$$\prod_{i=1}^{k} (a_i + b_i x)$$$ can be calculated in $$$O(k \log k)$$$ time.

Basically, if we let $$$f(k)$$$ be the ways to construct $$$a$$$ such that gcd is $$$k$$$, then then the mobius transform of $$$f$$$ can be calculated using dp (and fast polynomial products to calculate the dp values). After that, we can take the inversion.

I submitted the simple dnc code to calculate the product, which adds another log, and it passed.

Anyway, I thought the easter egg in E's naming was You = u = $$$\mu$$$. Seems like the intended one is different :P

»
3 года назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

If $$$a_i \leq n$$$ and $$$a_j \leq n$$$, then $$$(a_i|a_j) \leq 2n$$$.
Can someone, give me an example when $$$(a_i|a_j)$$$ is equal to $$$2n$$$.

  • »
    »
    3 года назад, # ^ |
      Проголосовать: нравится +5 Проголосовать: не нравится

    It can be shown that this inequality is strict.

    Multypling by 2 is bit shift to the left by one, adding zero, so if most significant bit of $$$n$$$ is $$$i$$$-th bit, for $$$2n$$$ it is $$$i + 1$$$-th bit, but if $$$x \leqslant n$$$, $$$x$$$ can't have $$$i + 1$$$-th bit.

    But there's an example where $$$x \leqslant n, y \leqslant n$$$ and $$$x \mid y = (2n - 1)$$$.

    Consider $$$n = 2^k$$$, $$$x = 2^k$$$, $$$y = 2^k - 1$$$. $$$x \mid y$$$ is equal $$$2^{k + 1} - 1 = 2n - 1$$$

    • »
      »
      »
      3 года назад, # ^ |
      Rev. 2   Проголосовать: нравится 0 Проголосовать: не нравится

      Yes, but quoting the editorial of B

      "since $$$0≤a_i≤n$$$, the maximum possible of value any $$$ai|aj$$$ is $$$≤2n$$$."

      $$$a_i|a_j = 2n$$$ is not possible.
      So shouldn't the symbol be $$$<$$$ instead of $$$\leq$$$ , in the last part ?

      • »
        »
        »
        »
        3 года назад, # ^ |
          Проголосовать: нравится 0 Проголосовать: не нравится

        consider $$$2n=00...001....$$$, where first 1-bit is k-th bit.

        now let's look at $$$n$$$. $$$k$$$-th bit will be set to zero, because dividing by 2 is equal to right-shifting by one.

        one of $$$a_i$$$ or $$$a_j$$$ must have k-th bit set to 1 (because $$$2n$$$ has). but that means than one of them are greater than n, because $$$2^k > 2^{k-1} + 2^{k-2} + ...$$$. this is impossible, so $$$a_i|a_j$$$ cant be equal to 2n.

        you are right

»
3 года назад, # |
Rev. 4   Проголосовать: нравится 0 Проголосовать: не нравится

Has anyone tried to solve B using SOS DP and got TLE in system testing, in C++ 17?

In the editorial it is mentioned that O(N*K) is allowed, so O(NlogN) shouldn't give TLE I guess, I mean K can be as large as 100 and logN cannot be more than 20.

What's more traumatic? The same code was accepted in C++ 11 after the contest. That too in 530 ms. Difference of few ms is fine but 470 ms is too much, if this is the case then there should be different time limits for C++17 and C++11, even 1.2 sec would have worked. :(

It would be great if someone can explain the reason behind this difference in time, and also if anyone can justify why O(N*K) works but O(NlogN) gives TLE. (Except advising for compiler optimizations, if it was so necessary then it should be mentioned in the announcements or in the problem statement, or at least a pretest should be there which fails without these optimizations. All I want to say is if O(NlogN) fails without these optimizations then O(N*K) shouldn't be accepted too. <;_;> )

Here are the submission links:

  • »
    »
    3 года назад, # ^ |
      Проголосовать: нравится 0 Проголосовать: не нравится

    Can you tell why changing the order of for loop is giving wrong answer? like this — rep(mask,0,N) rep(i,0,lg)

»
3 года назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

Can someone explain why k * (ai | aj) is O(100 n)? Wouldn't it still be n^2 because to compute (ai|aj) you need to cycle through every j for each i still

  • »
    »
    3 года назад, # ^ |
      Проголосовать: нравится 0 Проголосовать: не нравится

    I also had this confusion when I read it. It's not about time complexities, I don't know why they used $$$O$$$ notation. It's just talking about the order of the values. $$$i \cdot j$$$ could potentially go up to $$$n \cdot (n-1)$$$, while $$$k \cdot (a_i | a_j)$$$ can only go up to $$$100 \cdot (2n-1)$$$, which shows that $$$i \cdot j $$$ will be way bigger than $$$k \cdot (a_i | a_j)$$$ because of the constraint on $$$k$$$.

»
3 года назад, # |
Rev. 4   Проголосовать: нравится 0 Проголосовать: не нравится

deleted

»
3 года назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

Great prombles! ^ ^

»
3 года назад, # |
  Проголосовать: нравится +5 Проголосовать: не нравится

The problems are well-prepared, but I really wonder why the D is a constructive problem without any other algorithms. In my opinion, this one should be used as B(so I think swapping B and D is a good choice).

Although I know no one will vote for my comment, but I still want to say the suggestions as the writer may hold a round again in the near future.

»
3 года назад, # |
Rev. 3   Проголосовать: нравится 0 Проголосовать: не нравится

interesting E ...... (but too difficult TAT)

»
3 года назад, # |
Rev. 2   Проголосовать: нравится 0 Проголосовать: не нравится

Very short and nice statements. But when i see "mikasa", i expected some back story about author and this girl :)

»
3 года назад, # |
Rev. 3   Проголосовать: нравится 0 Проголосовать: не нравится

i think the B is wonderful !!

»
3 года назад, # |
Rev. 3   Проголосовать: нравится +1 Проголосовать: не нравится

In problem B, Code(C++), for the case n=6,k=1,a={0,0,0,0,100,100}, it returns -70. Isn't it exactly 12? but i forgot that a<=n. Sorry.

»
3 года назад, # |
  Проголосовать: нравится +1 Проголосовать: не нравится

why we shoule do this (if (m >> k & 1) ans |= 1 << k, n |= 1 << k;)operation at Problem C?

»
3 года назад, # |
  Проголосовать: нравится +71 Проголосовать: не нравится

Editorial for ABCD be like

»
3 года назад, # |
  Проголосовать: нравится +9 Проголосовать: не нравится

I think the solution of D is so wonderful , because I have a complex and strange solution which I have to proof it doesn't exceed 26 distinct character.

»
3 года назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

YouKn0wWho

There is a typo in the editorial for C:

If $$$n_i = p_i$$$ then we can set $$$k_i = 0$$$ as $$$n_i \oplus 0 = n_i <= p_i$$$.

At the very end it should be $$$n_i >= p_i$$$.

»
3 года назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

problem B: Cobb , are you mean domnick cobb?

»
3 года назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

Can someone have a look at my code for problem B? The runtime should also be O(n-k), but it timed out on test case 2. It really doesn't make sense... The intuition is that f(i,j)>f(n,n-1) is only possible when i,j >= sqrt(f(n,n-1)), which is similar to what is given in the tutorial

Thanks!!!

#include <bits/stdc++.h>

using namespace std;

int64_t task(vector<int> &nums, int k)
{
    int n = nums.size();
    int64_t ans = n * (n - 1) - k * (nums[n - 1] | nums[n - 2]);

    int least_i = 0;
    if (ans > 0)
    {
        least_i = sqrtl(ans) - 1;
    }

    for (int i = least_i; i < n; i++)
    {
        for (int j = i + 1; j < n; j++)
        {
            ans = max(ans, (int64_t)(i + 1) * (j + 1) - (int64_t)k * (nums[i] | nums[j]));
        }
    }

    return ans;
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int t;
    cin >> t;
    while (t--)
    {
        int n, k;
        cin >> n >> k;
        vector<int> nums(n);
        for (int i = 0; i < n; i++)
        {
            cin >> nums[i];
        }
        cout << task(nums, k) << '\n';
    }
}
  • »
    »
    3 года назад, # ^ |
      Проголосовать: нравится 0 Проголосовать: не нравится

    int64_t ans = n * (n - 1) - k * (nums[n - 1] | nums[n - 2]);

    You're running into an overflow here. Even though ans is a 64-bit int, n is 32-bit, and when computing n * (n - 1) the value is stored temporarily in a 32-bit int which causes an overflow.

    Try typecasting any values to 64-bit integers when you run the risk of overflows, like so - int64_t ans = (int64_t)n * (n - 1) - (int64_t)k * (nums[n - 1] | nums[n - 2]);

    Also, you should ideally either link to your code, or enclose your code in

    spoiler tags

    .

»
3 года назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

Is there an approximate value of $$$σ_0$$$ represented by Big O notation less than $$$O(\sqrt{n})$$$?

  • »
    »
    3 года назад, # ^ |
      Проголосовать: нравится 0 Проголосовать: не нравится

    $$$\mathcal{O}{(\sqrt[3]{n})}$$$

    • »
      »
      »
      3 года назад, # ^ |
        Проголосовать: нравится 0 Проголосовать: не нравится

      It is not proven fact(maybe it is wrong), but for all numbers less than $$$10^{12}$$$ it is barely true. But you shouldn't use this in asymptotics.

»
3 года назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

B should have been a little easier or A should have been a little more difficult!

»
3 года назад, # |
Rev. 2   Проголосовать: нравится 0 Проголосовать: не нравится

Hello, (in problem B) could someone explain why my this submission didn't pass while this similar solution does. Any effort will be appreciated.

Update: There was an integer overflow and it got accepted after fixing it. Accepted solution after fixing overflow. (Thanks)

»
3 года назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

An excellent contest which improve my understanding of the BIT problem, but the only pity is that I didn't attempt to have a look at the D I should have solved ,'casue I failed to solve the B and C.

»
3 года назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

i still not able to understand B(1554B — Cobb) Can anyone please explain B in some easier way

»
3 года назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

Ok so I overkilled B. But I have a very different solution for B. I used SOS dp for B, where the constraints on k does not matter at all. Just store for each mask the two highest indexes of its all submasks which can be easily calculated using SOS dp. Then just choose the maximum value among all masks.

»
3 года назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

I can't understand the calculation formula of Hk of problem E. Can someone explain it?

  • »
    »
    3 года назад, # ^ |
    Rev. 2   Проголосовать: нравится 0 Проголосовать: не нравится

    Problem E — hk calculation :

    fk = number of sequences divisble by k => this will include all sequences that are also divisble by 2k, 3k, 4k, 5k and so on;

    So, to get the number of sequences where the gcd is k, you can subtract sequences where gcd is greater than k and which were counted in fk

    So h(k) = f(k) — h(2k) — h(3k) — h(4k) ......h(ik) ---- until ik becomes > n;

    h(k) needs to be calculated from higher to lower values ofc.

    Hope this helps you

»
3 года назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

Well, my solution for B, is for every 1 <= j <= n, search every i in max(1, j-k) <= i < j, and try to use f(i, j) to update the answer. I know it isn't a correct solution, but I passed the system test...

»
3 года назад, # |
Rev. 3   Проголосовать: нравится +77 Проголосовать: не нравится

About Problem E,there is a similar solution with better Time Complexity.

Noticed that for any $$$k>1$$$,a sequence $$$a$$$ such that each $$$a_i$$$ is divisible by $$$k$$$,it can be proved that there will be at most one condition.

Then we can only check $$$x|n-1$$$ and $$$x$$$ is prime.And when we check whether a sequence $$$a$$$ such that each $$$a_i$$$ is divisible by $$$x$$$ can be build,we could find the exact gcd number at the same time.

It runs much faster than the code of Editorial.

The exact time complexity should be $$$\mathcal O(n\omega(n-1))$$$ while $$$\omega(x)$$$ is the number of prime number that can divide $$$x$$$.I think it is no more than $$$\mathcal O(n \log \log n)$$$

This is my code.

»
3 года назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

D is too overrated imao, but I'm glad that I read ALL PROBLEMS and quickly solved D. Wonderful contest!

»
3 года назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

Just Awesome

»
3 года назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

excuse me ,what does the problem E the last step h_k = f_k — \xi h_ik mean

»
3 года назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

Try to solve problem D if we consider subsequence instead of substring! It is an interesting problem.

»
3 года назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

Can someone explain problem E why two dfs with different roots can't form two different A sequences?

»
3 года назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

can anyone tell why i am getting tle here in D void solve() { ll n; cin>>n; ll i,k; string ans=""; if(n%2==0) { if(n==2) { cout<<"ab"<<endl; } else { k=(n-1)/2; for(i=0;i<=k;i++) { ans=ans+"a"; } ans=ans+"b"; for(i=0;i<k;i++) { ans=ans+"a"; } cout<<ans<<endl; } } else { if(n==1) { cout<<"a"<<endl; } else { k=(n-2)/2; for(i=0;i<=k;i++) { ans=ans+"a"; } ans=ans+"bc"; for(i=0;i<k;i++) { ans=ans+"a"; } cout<<ans<<endl; } } }

»
3 года назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

Thi is My approach For Problem C

we know the xor properties 0 xor 0 = 1 xor 1 = 0 1 xor 0 = 0 xor 1 = 1 so in this ques we have concluded the condition n^MEX>=(m+1)

we have to find MEX(as small as possible) so we will move from 31 st bit to 0th if we found ith bit of n and ith bit of (m+1) is same then will make ith bit of MEX is 0(keeping in mind that we r making MEX as small as possible)and if ith bit MEX is 0 and (m+1)'s ith bit is 1 then we will make ith of bit of MEX is 1 (if we take zero it becomes smaller than m+1) and finally if ith bit MEX is 1 and (m+1)'s ith bit is 0 then we can say thay MEX is already greater then will add zeroes in further position !

**MY CODE : **124203362

  • »
    »
    3 года назад, # ^ |
      Проголосовать: нравится 0 Проголосовать: не нравится

    why don't we start from 0-th bit instead of 30-th bit,since we want to find smallest k. starting from 0-th bit we can proceed as->for i-th bit from right we add 1<<i to temp(variable) and using another loop we add to temp every (1<<j) [∀j<i:n&(1<<j)==0].

    • »
      »
      »
      3 года назад, # ^ |
        Проголосовать: нравится 0 Проголосовать: не нравится

      Beacuse n^mex >= m+1, so starting from zero might not result in this condition

»
3 года назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

The Python code for B in this editorial (YOUR OWN CODE) is giving TLE on test case 10. https://codeforces.net/contest/1554/submission/124273841

»
3 года назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

How in 2nd statement of problem B maximum possible of value any ai|aj is ≤2n

as ai<=n

so ai=aj=n;

n|n==n

but how n|n==2n ??

»
3 года назад, # |
Rev. 2   Проголосовать: нравится 0 Проголосовать: не нравится

Can anyone explain the logic behind problem E observation 2 ?? Why will there be only 1 or no sequence for k>1??

  • »
    »
    3 года назад, # ^ |
      Проголосовать: нравится +1 Проголосовать: не нравится

    In observation 1 they describe an algorithm starting with: "Let's construct a sequence $$$a$$$ such that each $$$a_i$$$ is divisible by $$$k$$$."

    The idea is that by looking at the algorithm's steps, everything is essentially fixed. There's no place in the algorithm where you can choose from a variety of options. You can either complete the algorithm or you can't. If you can complete the algorithm for some k, then f(k) is 1. And if you can't, f(k) is 0.

    I would recommend you to take a couple of sample trees and trying out the algorithm by hand for constructing the sequence $$$a$$$ for a fixed $$$k$$$.

»
3 года назад, # |
Rev. 2   Проголосовать: нравится 0 Проголосовать: не нравится

E can be solved in $$$O(n \log \omega(n - 1))$$$ where $$$\omega(x)$$$ is the number of distinct prime divisors of $$$x$$$. There is a conclusion that $$$\omega(x) = O(\frac{\log x}{\log \log x})$$$, so the complexity can be written as $$$O(n \log \log n)$$$.

Code

»
3 года назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

Can someone explain the 2nd observation in the Editorial of last question?? " f(k) for k>1 is either 0 or 1."

  • »
    »
    3 года назад, # ^ |
      Проголосовать: нравится +1 Проголосовать: не нравится

    In observation 1 they describe an algorithm starting with: "Let's construct a sequence $$$a$$$ such that each $$$a_i$$$ is divisible by $$$k$$$."

    The idea is that by looking at the algorithm's steps, everything is essentially fixed. There's no place in the algorithm where you can choose from a variety of options. You can either complete the algorithm or you can't. If you can complete the algorithm for some $$$k$$$, then $$$f(k)$$$ is 1. And if you can't, $$$f(k)$$$ is 0.

    I would recommend you to take a couple of sample trees and trying out the algorithm by hand for constructing the sequence $$$a$$$ for a fixed $$$k$$$.

»
3 года назад, # |
Rev. 2   Проголосовать: нравится 0 Проголосовать: не нравится

Can somebody explain why in problem E the formula of $$$h_k$$$ is $$$h_k = f_k - \sum\limits_{i=2}^{\left\lfloor\frac{n}{k}\right\rfloor} h_{i\cdot k}$$$, but not for example $$$h_k = f_k - (h_{2k} + h_{3k} + h_{5k} - h_{6k} + \ldots)$$$ (like the inclusion-exclusion formula)?

UPD: Ok, I understood. That's because $$$h_k$$$ is the number of sequences that have gcd equal to $$$k$$$ (not gcd divisible by $$$k$$$).

»
3 года назад, # |
  Проголосовать: нравится +3 Проголосовать: не нравится

Problem E is very nice! Masterpiece of small observations!

»
3 года назад, # |
  Проголосовать: нравится +8 Проголосовать: не нравится

Awesome from problems to the turorial

»
3 года назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

Not sure if this is too obvious or has already been covered, but you don't really need dp. For each $$$k \gt 1$$$ you simply need to figure out if the tree can be split into stars with number of edges divisible by $$$k$$$. Instead of doing dp yourself, you can show by induction that this problem is equivalent to the following check. For each vertex, consider the sizes of its subtrees. If some are divisible by $$$k$$$, ignore them. For the rest, if there is one which is $$$\gt 1$$$ mod $$$k$$$, it is not possible. Otherwise count those which are 1 mod $$$k$$$, and their number should be divisible by $$$k$$$. This way you need to do only one dfs in the beginning to calculate subtree sizes. It seems more efficient overall...

»
2 года назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

What is the Binary Search solution for Problem C?

»
8 месяцев назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

Modified B- Given an array of integers and a value k. Find the maximum value of

F(i,j) = (i&j) -(k&(a[i]|a[j])

Constraint: n<=1e5,a[i]<=1e9,k<=1e9

  • »
    »
    5 месяцев назад, # ^ |
      Проголосовать: нравится 0 Проголосовать: не нравится

    Yup I have solved the same. keeping the maximum {i,j} saved for every possible OR value and Answering. Loop takes NLogN for iterating over all submasks who can lead to a given OR value.264097496

»
6 месяцев назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

I couldn't understand the solution for problem C T_T. Is there any reference or other similar problem to problem C ?