Wind_Eagle's blog

By Wind_Eagle, 3 years ago, In English

Will we, will you...
Can we, can you, can we change?

1562A - The Miracle and the Sleeper

Hint 1
Hint 2
Solution
Code C++ (Wind_Eagle)

1562B - Scenes From a Memory

Hint 1
Hint 2
Solution
Code C++ (Wind_Eagle)
Additional Problem 1
Solution of Additional Problem 1
Additional Problem 2
Solution of Additional Problem 2

1562C - Rings

Hint 1
Hint 2
Solution
Code C++ (Wind_Eagle)
Additional Problem 1
Solution of Additional Problem 1
Additional Problem 2
Solution of Additional Problem 2

1562D1 - Two Hundred Twenty One (easy version)

Hint 1
Hint 2
Hint 3
Solution
Code C++ (Wind_Eagle)

1562D2 - Two Hundred Twenty One (hard version)

Hints 1-3
Hint 4
Hint 5
Solution
Code C++ (Wind_Eagle)
Interesting question

1562E - Rescue Niwen!

Hint 1
Hint 2
Hint 3
Solution
Code C++ (Wind_Eagle)
Interesting question

1562F - Tubular Bells

Hint 1
Hint 2
Hint 3
Hint 4
Hint 5
Solution
Code C++ (Wind_Eagle)
  • Vote: I like it
  • +158
  • Vote: I do not like it

| Write comment?
»
3 years ago, # |
  Vote: I like it +14 Vote: I do not like it

Thanks for the great contest and the fast editorial :)

»
3 years ago, # |
Rev. 2   Vote: I like it -39 Vote: I do not like it

Wish all div2 contest were like this. Quite standard contest.

»
3 years ago, # |
  Vote: I like it 0 Vote: I do not like it

Can you still provide code for problem F? Even though it might be incomprehensible, it might be used to stress test our solutions. Or maybe you can provide some participant's code which is more readable.

»
3 years ago, # |
  Vote: I like it +16 Vote: I do not like it

Unable to parse markup [type=CF_MATHJAX] error in D1

»
3 years ago, # |
  Vote: I like it +14 Vote: I do not like it

Thank you for the nice round! The problems were very interesting, and C's cases using the zeroes was pretty tricky in particular. However, D1's solution was pretty easily noticed by me and some others because of the samples (the observation that all answers were either 0, 1, or 2). Maybe giving less samples would "hide" this fact?

Problem statements were clear and concise, and from what I did, problems are roughly in increasing order of difficulty!

Again, thanks for the round, and I hope you write another one soon! (pikachu-themed plsssss :D)

  • »
    »
    3 years ago, # ^ |
      Vote: I like it +13 Vote: I do not like it

    I've thought about that, but left this sample because I have worried about the difficulty of D1. I decided to make it easier doing this.

»
3 years ago, # |
  Vote: I like it -34 Vote: I do not like it

Damn, I found out that in problem D1, there are only 0, 1, 2 but I forgot casting it to abs

»
3 years ago, # |
  Vote: I like it 0 Vote: I do not like it

Unable to parse markup [type=CF_MATHJAX]

  • »
    »
    3 years ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    I will fix it soon.

    • »
      »
      »
      3 years ago, # ^ |
        Vote: I like it 0 Vote: I do not like it

      Thank you for the nice round and the fast fixing.Your round and editorial will benefit us a lot !

»
3 years ago, # |
  Vote: I like it +3 Vote: I do not like it

What's more,In D2,the hint was corresponding to "C1" ,which should be D1

  • »
    »
    3 years ago, # ^ |
      Vote: I like it +3 Vote: I do not like it

    Addition:the Solution We will use the facts already obtained, given in the solution of problem C1.-->D1

»
3 years ago, # |
  Vote: I like it +1 Vote: I do not like it

How will we solve B for , what is the minimum number of digits that can be removed from the number so that the number becomes not prime,

  • »
    »
    3 years ago, # ^ |
      Vote: I like it +24 Vote: I do not like it

    This task is harder than checking is the number prime.

»
3 years ago, # |
  Vote: I like it 0 Vote: I do not like it

Can someone help me figure out why my O(n + q*logn) solution failed for D2? The time complexity should be same as the editorial solution

My approach was a little different from the editorial however 1) While precomputing I store for all prefix sum values v the indices of elements where the prefix sum is equal to v 2) in the binary search phase I calculate the prefix sum of the element to be removed (this will be midpoint of prefix sums of left and right boundary), and then binary search for an index with that prefix sum in the data structure from 1

https://codeforces.net/contest/1562/submission/127124443

»
3 years ago, # |
Rev. 2   Vote: I like it 0 Vote: I do not like it

why does this solution fail the pretest 2 :( 127132103, Problem C.

»
3 years ago, # |
  Vote: I like it +35 Vote: I do not like it

Thanks for the great problemset, really liked the fun constructives :D

»
3 years ago, # |
Rev. 4   Vote: I like it +58 Vote: I do not like it

I have an offline solution for D which works in O(N + Q). Precompute the prefix array as in D1. Then sort on the values by l (by bucket sort i.e. query[l].pb({r, q}), where q is the idx of this query). if sign variable sum is zero, then just continue. Now there are two cases.

Case 1: If r-l+1 is odd : We want to find an index idx, such that then the sign variable sum between l and idx-1 and idx+1 to r should be equal. Because when we remove idx, the sum after those elements just alternates. This can be written as pre_sum[idx — 1] — pre_sum[l-1] = pre_sum[r] — pre_sum[idx]. Now, we can rewrite this as pre_sum[l-1] + pre_sum[r] = pre_sum[idx] + pre_sum[idx-1]. So for a given l, r, we can find any idx such that l <= idx <= r and the above condition holds.

Case 2: if r-l+1 is even, we can remove r, do r-- and then it becomes case 1.

We can create an hash map of vectors to store the adjacent pre_sum's index. i.e. map[pre_sum[i-1] + pre_sum[i]].pb(i);

We also create an index hash map which stores for this key what index we are at in the vector hashmap. Then since the queries are sorted by l, we can just do like 2 pointer approach until we find index > l for the key in the vector hashmap. Here the key is sum[l-1] + sum[r].

Upd : added the sortig method to get O(n+Q) complexity.

  • »
    »
    3 years ago, # ^ |
      Vote: I like it +21 Vote: I do not like it

    Correct me if I'm wrong... But sorting in the very first step will take O(Nlog(N)) time.

    Until and unless you use some radix sort type of algorithm to sort but I think that would be an overkill.

    • »
      »
      »
      3 years ago, # ^ |
        Vote: I like it +8 Vote: I do not like it

      Just put the queries in buckets by $$$l$$$. Then loop over the indices and do the same above.

      I think I have an easier implementation. Let $$$ps$$$ be the prefix sum array. Notice that for each query $$$(l, r)$$$, we can determine $$$k$$$ and need to find some index $$$x$$$ such that $$$l \leq x \leq r$$$ and $$$ps_x = k$$$.

      Then we can have an offline solution to answer all queries $$$(l, r, k)$$$. Put the queries into buckets by $$$r$$$. Then loop over $$$1 \dots N$$$ and maintain last occurrence of each prefix sum value. Due to the proven existence of our target index, the last occurrence before $$$r$$$ must meet our requirement.

      Since $$$|ps_x| \leq N$$$, this solution works in $$$O(N + Q)$$$.

      • »
        »
        »
        »
        3 years ago, # ^ |
          Vote: I like it 0 Vote: I do not like it

        I think such simplification can not be done.

        Consider a sequence whose sum is 2m-1, m>0:

        We not only want $$$ps_x$$$ = m-1, $$$v_x=1$$$ is also required.

        • »
          »
          »
          »
          »
          3 years ago, # ^ |
          Rev. 2   Vote: I like it 0 Vote: I do not like it

          No, it is possible to solve problem D2 in $$$O(n + q)$$$ and I too have discovered the same solution with asymptotics $$$O(n + q)$$$ as mentioned aboved. Taking offline queries and storing them in a list of their corresponding $$$r$$$ values, can do it.

          Here's the link to my submission 127266077.

          Even tho it takes $$$483 ms$$$, whereas my $$$O(n + q.logn)$$$ takes $$$358 ms$$$. This might be because setter didn't included required test cases in the test sets in order to differentiate between the execution time of the two solutions. Or maybe there's some problem with the way I've implemented.

        • »
          »
          »
          »
          »
          3 years ago, # ^ |
            Vote: I like it 0 Vote: I do not like it

          A tricky question.

          Assume $$$m > 0$$$. Actually it can be shown that for the last occurrence where $$$ps_x = m - 1$$$, there must be $$$v_x = 1$$$, otherwise there will be another position $$$x < y < r$$$ such that $$$ps_y = m - 1$$$. My in-contest solution made use of this conclusion, besides that I tried to find the first occurrence online.

          Another way to avoid this discussion, is to find the position where $$$ps_x + ps_{x+1} = 2m - 1$$$. This idea is already discussed in this comment, and you can see the implementation in this comment below.

          • »
            »
            »
            »
            »
            »
            3 years ago, # ^ |
              Vote: I like it 0 Vote: I do not like it

            Yes you are right.

            I only looked at your first claim, and didn't notice that the trick of finding the last occurrence will account for this.

            Thanks for the clarification!

  • »
    »
    3 years ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    Although it's O(N+QlgN), this approach made a very simple online solution :O

    https://codeforces.net/contest/1562/submission/127151337

  • »
    »
    3 years ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    I think you can use an arrary but not a hashmap, that will be faster.

  • »
    »
    3 years ago, # ^ |
      Vote: I like it +8 Vote: I do not like it

    Thank you for sharing this solution!

»
3 years ago, # |
  Vote: I like it +4 Vote: I do not like it

Loved this contest.

»
3 years ago, # |
  Vote: I like it +20 Vote: I do not like it

It looks like F editorial is slightly overcomplicated. For n > 100 it suffices to iterate with for loop and ask for pairs (1, a[i]) for min(5000, n) pairs. Then take maximum prime number that ever occured as divisor of lcm. Using this get whole array in n operations. Or can you hack it?

  • »
    »
    3 years ago, # ^ |
    Rev. 2   Vote: I like it +8 Vote: I do not like it

    I know that there exists very simple solution. Just explain to me please: if we have not the biggest prime number, but a prime number p such that p < r/2, how can we get the whole array using this prime? I really don't know how to do this. But I know that this can be done somehow.

    • »
      »
      »
      3 years ago, # ^ |
        Vote: I like it 0 Vote: I do not like it

      If n > 5000 it should be clear that we have very high chance of getting at least one prime > r / 2. Else we know all the primes and it is well known that there always exists prime between x and 2x for natural x, so it can't happen that the biggest prime is < r / 2.

      • »
        »
        »
        »
        3 years ago, # ^ |
        Rev. 3   Vote: I like it +13 Vote: I do not like it

        A way to improve your chances more with the same approach is to first assume the permutation is randomly permuted. Than asking query(1,2), query(3,4), ..., query(9999,10000). (Or less, if n<10000)

        The biggest prime that's a divisor of one these queries is kept, and the pair where it was found. Now this big prime could be at either position i or i+1, we use one extra query to determine which one.

        Only if all the "big" ( > r/2) primes are not in the first 10000 elements of the permutation this will fail. The number of big primes is always more than $$$\frac{n}{200}$$$, because the largest prime gap under the constraints is less than 100. $$$P(fail) = P(\textrm{All big primes not in first 10000 elements}) \leq (1-\frac{10000}{n})^{n/200}$$$. For $$$n \in [10000,100000]$$$, this probability is always less than $$$10^{-22}$$$. (Actual probability is even lower).

        • »
          »
          »
          »
          »
          3 years ago, # ^ |
          Rev. 3   Vote: I like it 0 Vote: I do not like it

          Sorry, stll don't understand why there are more than $$$\frac{n}{200}$$$ big primes.

          • »
            »
            »
            »
            »
            »
            3 years ago, # ^ |
            Rev. 3   Vote: I like it 0 Vote: I do not like it

            Because $$$n=r-l+1$$$, $$$r$$$ is greater or equal than $$$n$$$. So the range where big primes could exist is $$$r- \frac{r}{2} = \frac{r}{2} \geq \frac{n}{2}$$$. For all numbers less than 200000, The biggest gap between two adjacent primes is 86. This means that after you move from some number 100 places to the right, you're guaranteed to get at least one prime. So the number of primes in the good region is at least $$$\frac{n}{2} \cdot \frac{1}{100} = \frac{n}{200}$$$.

            For my full solution:

            For $$$n<86$$$ it's not guaranteed that the region [l,r] contains a prime. So for this case, you query all pairs. If you want to know the number on position a_i, you can take $$$gcd(q_{i,1}, q_{i,2},...,q_{i,n})$$$. Only for n=3, there's a special case, where this doesn't work.

            For $$$n \geq 86$$$, you query pairs of positions like I described. Then you know the position and the value of a big prime. For all the other a_i's you can just put $$$a_i = \frac{q_{i,\textrm{position of big prime}}}{\textrm{big prime}}$$$

            Submission: AC

            • »
              »
              »
              »
              »
              »
              »
              3 years ago, # ^ |
                Vote: I like it +8 Vote: I do not like it

              Thank you, got it! Very short and nice solution :)

»
3 years ago, # |
Rev. 3   Vote: I like it 0 Vote: I do not like it

Thanks for the nice Round. But in problem F case $$$100 <n \le 10000$$$,why the biggest prime divisor we found must be in the sequence?

Forgive my poor English.

»
3 years ago, # |
  Vote: I like it 0 Vote: I do not like it

Excuse me, but how can you prove (in problem D2) that by such binary searching we are always making a right move?

»
3 years ago, # |
  Vote: I like it +1 Vote: I do not like it

D1 problem was very unfair. Like it was not suitable for D1. So many people are there who could not solve B and C but still solved D1 .Just because it was so evident from the example cases that the answer can only be 0 1 or 2. Rest of the contest was very good but i think some more thought could have been put into D1. D2 was very good.

»
3 years ago, # |
  Vote: I like it 0 Vote: I do not like it

Thank you so much for fast editorial, the level of difficulty and question was excellent. I hope you will make more contest.

»
3 years ago, # |
  Vote: I like it +18 Vote: I do not like it

I got WA on test 3 of problem F, but the judger said wrong answer The answer is wrong! (test case 300). However it is guaranteed that $$$ t \leqslant 20 $$$ and the value $$$ t $$$ of test 3 is $$$ 20 $$$. Also I can pass data of test 3 on my own PC.

What's the meaning of the judger's comment?

»
3 years ago, # |
Rev. 2   Vote: I like it +8 Vote: I do not like it

I have a little better solution of B, which is less guessy and more easy to come up with.

1) Firstly if there is 1,4,6,8,9-> then you already got your answer.

2)Now, your string consists of 2,3,5,7 only. Now, if your string contains repeating characters, we are done since 22,33,55,77->all of them are divisible by 11.

3)Now since there are no repeating characters up till now, the maximum length of your string can be at most 4.(since contains only 2,3,5 and 7).So you can brute force to check all possible combinations in 2^4=16 steps.

4) I think this solution is better if there can be cases in the problem in which the answer doesn't exists.

»
3 years ago, # |
  Vote: I like it 0 Vote: I do not like it

https://codeforces.net/contest/1562/submission/127156841 can anyone help I m not getting that at which test case my code is failing?

  • »
    »
    3 years ago, # ^ |
      Vote: I like it +1 Vote: I do not like it

    you solution fail for case when {1, 4, 6, 8, 9} is present at 0th index in string for ex: for 15, 47, many more

»
3 years ago, # |
  Vote: I like it 0 Vote: I do not like it

Which Okami used string function to solve the E problem ?

string function can automatically compare the string in Lexicographic order. So we just run a simple LIS,that will Ok.

my code is down to the fourth point, I feel it is correct.

The link is as follow : test

This is my first asked question in the Codeforces, So maybe somewhere is wrong, %%%%%

  • »
    »
    3 years ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    I don't know where WA is, but your code will get TL sooner or later, as string comparasion works in O(n).

»
3 years ago, # |
  Vote: I like it 0 Vote: I do not like it

127118923 wrong answer Integer 61 violates the range [1, 6] (test case 54) test case please.

»
3 years ago, # |
Rev. 2   Vote: I like it +17 Vote: I do not like it

In problem E, I didn't quite understand the reasoning behind the fact that if the string $$$[l,r]$$$ is present in the LIS, the following ones ($$$[l,r+1],\, \dots,\, [l,n]$$$) must be present too so I want to share the proof that I came up with.

Firstly, we can observe that if $$$[l,r]$$$ and $$$[l,r+k]$$$ are present, all $$$[l,r+i],\ i<k$$$ must be present too. This is trivial since $$$[l,r+1]\ge [l,r]$$$. Furthermore, all these elements must be next to each other since that is the order that they follow in the sequence.

Now, we can prove the initial claim:

$$$ \text{If the string $$$[l,r]$$$ is present in the LIS, the following ones ($$$[l,r+1],  ...,  [l,n]$$$) must be present too} $$$

Let us assume that we have a LIS in which this is not true. Then there must be two adjacent elements in the LIS $$$a_1=[l_1,r_1],\ a_2=[l_2,r_2]$$$ such that $$$l_1<l_2$$$ and $$$r_1<n$$$.

  • If $$$a_1$$$ and $$$a_2$$$ have a common prefix, we can denote its longest common prefix as $$$p$$$. Then, we know that $$$a_1 = p+s_1$$$ and $$$a_2 = p +s_2$$$ where the $$$+$$$ represents concatenation and $$$s_1,s_2$$$ are some strings.
    • If $$$|s_1|> 0 $$$, since we know that $$$s_1<s_2$$$ (because $$$a_1<a_2$$$) and $$$s_1$$$ and $$$s_2$$$ do not share any common prefix (otherwise $$$p$$$ would not be the longest), the first character of $$$s_1$$$ must be smaller than the first character of $$$s_2$$$. In this case, we can add all the rest of the prefixes of the suffix $$$[l_1,n]$$$ since all of them will be smaller than $$$a_2$$$
    • If $$$|s_1|=0$$$, we know that $$$|s_2|$$$ cannot be we 0 (otherwise $$$a_1=a_2$$$). Therefore $$$|a_1|<|a_2|$$$ and we can delete all the prefixes of the suffix $$$[l_1,n]$$$ replacing them by the corresponding prefixes of the suffix $$$[l_2,n]$$$. A more detailed proof of why we will have enough prefixes to do this replacing operation is provided in the replies to this comment.
  • If they do not have a common prefix, $$$a_1[0]<a_2[0]$$$ and we can include all the remaining prefixes of $$$[l_1,n]$$$ in the LIS as they will all be smaller than $$$a_2$$$

By performing these changes a finite number of times we get a LIS that does not have less elements and fulfils the initial claim.

Edit: Changed the conditions in the proof following maomao90's suggestion to clarify the proof

  • »
    »
    3 years ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    As your solution,the second situation "if $$$|s1|<|s2|...$$$" and maybe "The first character of $$$s1$$$ must be smaller than the first character of $$$s2$$$." in this situation also is right, so the rest of the prefixes of the suffix $$$[l_1,n]$$$ must smaller than $s2$,they can make contributions and not need delete.

    I understand other parts, It’s very good, it’s easier to understand than the solution, at least I understand it.

    Please answer my doubts,thanks

    • »
      »
      »
      3 years ago, # ^ |
        Vote: I like it 0 Vote: I do not like it

      I'm not sure if I understand your doubt correctly but I think there are some things that I could clarify.

      What we actually want to prove is that there is a LIS of maximum length in which the "initial claim" holds. To do so I can assume that the LIS of maximum length does not fulfil this claim. In that case, I can take that LIS and modify it so that it fulfils the claim. Therefore I have reached a contradiction and there is a LIS of maximum length that fulfils the claim.

      Keep in mind that there might be other LIS of maximum length that do not follow that structure at all. All we need to know is that there is one that does.

  • »
    »
    3 years ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    Hi, thank you for taking the time to write such a nice detailed proof. There's a part of your it that I don't understand, I'd really appreciate it if you could explain it to me. If |s1| < |s2|, my understanding is that we get rid of all the prefixes of [l1,r1] that existed in the LIS, so a maximum of r1 — l1 + 1 elements removed from the LIS. Afterwards, we add [l2, r2 + 1], [l2, r2 + 2] ... [l2, n], so n — r2 new elements added in. 1) How do you know that n — r2 > r1 — l1 + 1 ? 2) How do you know that these newly added in elements won't be in conflict with some other elements that came after [l2,r2] in the original LIS, creating the need for more removals. Or maybe I'm misunderstanding your proof. What exactly are you removing from the LIS and what are you replacing each removed element with?

    • »
      »
      »
      3 years ago, # ^ |
      Rev. 2   Vote: I like it 0 Vote: I do not like it

      Regarding your questions:

      1. The fact that $$$|s1|<|s2|$$$ should be enough because $$$r1-l1+1=|p|+|s1|$$$ and $$$r2-l2+1 =|p|+|s2|$$$ (just because of how $$$a_1$$$ and $$$a_2$$$ were split into the common prefix and "something else"). Now I want to replace all the prefixes of the suffix $$$[l_1,n]$$$ with prefixes of $$$[l_2,n]$$$ that are smaller than $$$[l_2,r_2]$$$. I can pick as many as I need from $$$[l_2,l_2], [l_2,l_2+1], \dots [l_2,r_2-1]$$$. All of those are valid since they will be greater than or equal to the corresponding ones from $$$[l_1,r_1]$$$ and are smaller than $$$[l_2,r_2]$$$. I should have enough because there are at most $$$r_1-l_1+1$$$ prefixes of $$$[l_1,n]$$$ in the LIS, this list has $$$r_2-l_2$$$ elements and $$$r_1-l_1+1 < r_2-l_2+1 \implies r_1-l_1+1 \le r_2-l_2$$$.
      2. They might be in conflict. If they happen to be I can repeat the process and delete the ones that I added (along with some more). Each time I delete and add elements I will get rid of a position in which there are two adjacent elements in the LIS with a different beginning such that the first one does not reach to the end of the string (does not end at $$$n$$$). Therefore we can just keep repeating the process until there are no such positions and then the LIS will adhere to the claim.
      • »
        »
        »
        »
        3 years ago, # ^ |
          Vote: I like it 0 Vote: I do not like it

        Why n — r2 + 1 = |p| + |s2|?

        • »
          »
          »
          »
          »
          3 years ago, # ^ |
            Vote: I like it 0 Vote: I do not like it

          Yup, that was wrong. Hopefully, I got it right this time.

          • »
            »
            »
            »
            »
            »
            3 years ago, # ^ |
              Vote: I like it 0 Vote: I do not like it

            Alright, now I get it! Thanks a lot for the help.

  • »
    »
    3 years ago, # ^ |
    Rev. 2   Vote: I like it 0 Vote: I do not like it

    I didn't understand why you were assuming $$$a_1$$$ is strictly less than $$$a_2$$$. In LIS, as much as I know, it's enough for elements to be increasing not strictly increasing. So I guess $$$a_1 \leq a_2$$$ should be correct.

    • »
      »
      »
      3 years ago, # ^ |
        Vote: I like it +5 Vote: I do not like it

      Sure, but if they are equal you can simply replace $$$a_1$$$ and all of its prefixes with $$$a_2$$$ and all its prefixes since they will all be equal. I was probably thinking of a strictly increasing LIS when I wrote the proof

      • »
        »
        »
        »
        3 years ago, # ^ |
          Vote: I like it 0 Vote: I do not like it

        Well, lets say $$$a_1$$$ equals c and $$$a_2$$$ equals c as well. And notice that there is no force for $$$l_2$$$ to be next to $$$l_1$$$. So in this case we have had selected $$$[l_1, l_1 + 1]$$$ and then $$$[l_2, l_2 + 1]$$$ and all of its suffixes. So what should we replace in this case?

        • »
          »
          »
          »
          »
          3 years ago, # ^ |
            Vote: I like it 0 Vote: I do not like it

          Yeah, you’re right. There is no substitution that we can make without decreasing the size of the LIS.

          But I have revised my submission and the solution in the editorial and the LIS has to be strictly increasing (which I didn’t remember last night when I wrote the previous answer) so we shouldn’t run into this problem.

          • »
            »
            »
            »
            »
            »
            3 years ago, # ^ |
              Vote: I like it 0 Vote: I do not like it

            Thanks for your response. I do agree that both editorial and your proofs are valid for strictly LIS. However, I see no clue in the problem statement for LIS to be strictly increasing. At this point, my guess is both increasing and strictly increasing LIS will have the same total answer in the problem.

  • »
    »
    3 years ago, # ^ |
      Vote: I like it +5 Vote: I do not like it
    If $$$|s_1|\ge |s_2|, \ldots$$$
    If $$$|s_1|<|s_2|, \ldots$$$

    I think this is confusing and it took me some time to understand it, so can I suggest that you change it to

    If $$$|s_1|>0, \ldots$$$
    If $$$|s_1|=0, \ldots$$$

    This is because as long as $$$|s_1|>0$$$, the first character of $$$s_1$$$ has to be smaller than the first character of $$$s_2$$$, so the only case this doesn't hold is when $$$s_1$$$ is an empty string.

    Thank you!

    • »
      »
      »
      3 years ago, # ^ |
        Vote: I like it +5 Vote: I do not like it

      At first I thought that changing the conditions would make it harder to realize why we do not run out of prefixes during the substituion step. But after rewriting that part I think it did end up being easier to understand so... thanks for the suggestion!

»
3 years ago, # |
  Vote: I like it 0 Vote: I do not like it

Thanks for the great contest!

»
3 years ago, # |
  Vote: I like it 0 Vote: I do not like it

I can't understand this sentence:then we can «drop» the prefixes of the suffix $$$[l1 . . n]$$$

Are $$$[l1,n]$$$ or $$$[l1,l1+1],[l1,l1+2],[l1,l1+3]...[l1,n]$$$ discarded in the solution

  • »
    »
    3 years ago, # ^ |
      Vote: I like it -6 Vote: I do not like it

    Yes, since $$$|s_1| \le |s_2|$$$, we can get a better answer.

    • »
      »
      »
      3 years ago, # ^ |
        Vote: I like it 0 Vote: I do not like it

      So from what I understand we are trying to prove that If the largest increasing subsequence has a substring [l_2 ... r_2], then it also has a substring [l_2 ... n].

      and in this step we move all suffixes of [l_1 ... n] included in a theoretical longest common prefix to [l_2 ... n]. But how do we know that we took the prefix [l_2 ... n]?

      • »
        »
        »
        »
        3 years ago, # ^ |
          Vote: I like it 0 Vote: I do not like it

        It just proved this property that if the string $$$[l,r]$$$ is present in the LIS, the following ones $$$([l,r+1], ..., [l,n])$$$ must be present too.

        It's proof by contradiction. Assume the optimal answer doesn't meet this condition, we can get a better answer by removing all prefixes of $$$[l_1, n]$$$ and adding the prefixes of $$$[l_2, n]$$$, so there is a contradiction. Taking the prefixes of $$$[l_2, n]$$$ is part of the proof, it doesn't mean we must take prefixes of $$$[l_2, n]$$$, or taking prefixes of $$$[l_2, n]$$$ can lead to the optimal answer.

        • »
          »
          »
          »
          »
          3 years ago, # ^ |
          Rev. 2   Vote: I like it 0 Vote: I do not like it

          Ok I was still a bit confused so I just tried to write everything up, the main point I was missing was that $$$s_1$$$ is a substring of $$$s_2$$$ so your method will work. Maybe you were just doing it a different way though since there quite a few different details.

          • Suppose we have two consecutive elements $$$s_1 = [l_1, r_1]$$$, $$$s_2 = [l_2, r_2]$$$ in a longest increasing sequence (In particular, $$$s_1 < s_2$$$ lexicographically) with $$$l_1\neq l_2, r_1\neq n$$$. We will show that there is another optimal sequence without this property.
          • If $$$s_{2}' = [l_1, r_1 + 1] \leq s_2$$$ lexicographically, we can replace $$$s_2$$$ with it to get another LIS. Do this while possible.
          • Thus $$$s_1 = [l_1, r_1] < s_2 < [l_1, r_1 + 1] = s_2'$$$. This implies that $$$s_1$$$ is a substring of $$$s_2$$$.
          • Since $$$s_1$$$ is a substring of $$$s_2$$$, we can do like you explained and move prefixes of $$$s_1$$$ to $$$s_2$$$.
»
3 years ago, # |
  Vote: I like it 0 Vote: I do not like it

in problem why cannot be b1>0 and bn>0 or b1<0 and bn<0 please explain.

  • »
    »
    3 years ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    let's define f(l,r) = a[l] — a[l + 1] + ... -1 ^ (r — l) * a[r] then b1 = f(2 , n) , bn = f(1, n — 1) since we know that n is odd, that means that the last element in f(2,n) will be with a — in front of it, so

    b1 = f(2, n- 1) — a[n] bn = a[1] — f(2 , n — 1)

    to make typing easier, f(2 , n — 1) = x

    case 1) we say a[1] = -a[n], in which case b1 * bn = (a[1] — x) * (a[1] + x) = a[1] ^ 2 — x ^ 2 = 1 — x ^ 2 and since we know that x can't be even, that means b1 * bn will be either 0 or negative. If it's 0, then either b1 or bn are 0, and if it's negative that means that b1 and bn have opposing signs. case 2) we say a[1] = a[n] then: b1 = x — a[1] bn= a[1] — x b1 = -bn

    I hope this helped!

»
3 years ago, # |
  Vote: I like it 0 Vote: I do not like it

Alternative in F to find a big prime. Pick a random triple x,y,z. Find gcd(Query(x,y), Query(x,z)). Call the gcd g. If g is prime and g>n/2 do Query(y,z). Then $$$a_{x}=g$$$ if g does not divide Query(y,z).

»
3 years ago, # |
  Vote: I like it 0 Vote: I do not like it

Loved Dream Theater references

»
3 years ago, # |
  Vote: I like it 0 Vote: I do not like it

Can anyone explain why I'm getting TLE in E? https://codeforces.net/contest/1562/submission/127401115

»
3 years ago, # |
  Vote: I like it +5 Vote: I do not like it

what is NOC in solution of problem F? To do this, we ask all the NOCs of the number p and the other numbers.

  • »
    »
    3 years ago, # ^ |
    Rev. 3   Vote: I like it 0 Vote: I do not like it

    Sorry, it is a bad translation from Russian.

    In Russian НОК (наименьшее общее кратное) is lcm (least common multiple).

»
3 years ago, # |
  Vote: I like it +8 Vote: I do not like it

I found another solution for D2:

Let $$$P_i$$$ be the prefix sign variable sum up to $$$i$$$. Let the answer to an odd-sized query $$$[l, r]$$$ be $$$m$$$. The old sign-variable sum of $$$[l, r]$$$ is $$$\pm(P_r - P_{l-1})$$$ and after removing $$$m$$$, the new sign-variable sum is $$$\pm(P_{m-1} - P_{l-1} + P_m - P_r)$$$. So, $$$m$$$ needs to satisfy $$$P_{m-1} + P_{m} = P_{l-1} + P_r$$$, and it can be located by maintaining a std::set of all possible $$$m$$$ for each value of $$$P_{m-1} + P_m$$$ and using lower_bound.

»
3 years ago, # |
  Vote: I like it 0 Vote: I do not like it

My explanation for F (which I feel is simpler) :- we can actually find any index in 20 queries so we find 5000/20 = 250 numbers and then the probability that some number > (l+r)/2 and is prime is fairly high. my submission

  • »
    »
    3 years ago, # ^ |
      Vote: I like it +8 Vote: I do not like it

    Nice solution :)

  • »
    »
    3 years ago, # ^ |
    Rev. 2   Vote: I like it 0 Vote: I do not like it

    Mine is quite similar! Repeatedly query all pairs between $$$3$$$ random indices $$$i, j, k$$$. A pair of sufficient conditions for $$$a_i$$$ being detected as prime are that $$$a_i$$$ is prime, and $$$a_j$$$ and $$$a_k$$$ are coprime (we can guess that $$$a_i = \gcd(lcm(a_i, a_j), lcm(a_i, a_k))$$$. And we can do the same thing for detecting whether $$$a_j$$$ and $$$a_k$$$ are prime. So the hope is again to find a large enough prime number.

    After some independence assumptions, prime gap blahblahblah, it seems like a pessimistic lower bound for the success of this on a single test is 99.99% but probably much better for most tests (and in retrospect can be improved with the TLE trick!).

    Awesome problem nonetheless though!

»
2 years ago, # |
  Vote: I like it 0 Vote: I do not like it

Funny enough, after getting so many TLE's I finally get accepted with $$$O(n^{2}log(n))$$$ algorithm in problem E.

  • »
    »
    2 years ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    You did use suffix array and LIS finding using lower_bound, right?

    Great work, I really amazed. Suspected that this is actually possible, but haven't seen any successful realizations.

    Thank you for solving my contest!

»
2 years ago, # |
  Vote: I like it 0 Vote: I do not like it

Why 21 does not work for testcase 1 Problem B;

https://codeforces.net/contest/1562/submission/179461212

  • »
    »
    20 months ago, # ^ |
      Vote: I like it +1 Vote: I do not like it

    Because we have to remove maximum number of digits so that the number becomes not prime, that is, either composite or equal to one. Thus, we can remove both 2's from the number 221 to make the resulting number equal to 1 which is a non-prime number.

»
20 months ago, # |
  Vote: I like it 0 Vote: I do not like it

D2 — is the example of bad editorial

»
18 months ago, # |
Rev. 2   Vote: I like it 0 Vote: I do not like it

c was satisfying to solve