AlFlen's blog

By AlFlen, 6 weeks ago, translation, In English

1493A - Anti-knapsack

Idea: AlFlen, 74TrAkToR

Tutorial
Solution (74TrAkToR)

1493B - Planet Lapituletti

Idea: AlFlen

Tutorial
Solution (74TrAkToR)

1493C - K-beautiful Strings

Idea: 74TrAkToR

Tutorial
Solution (74TrAkToR)

1493D - GCD of an Array

Idea: 74TrAkToR

Tutorial
Solution (74TrAkToR)

1493E - Enormous XOR

Idea: AlFlen

Tutorial
Solution (74TrAkToR)

1493F - Enchanted Matrix

Idea: 74TrAkToR

Tutorial
Solution (74TrAkToR)
 
 
 
 
  • Vote: I like it
  • +126
  • Vote: I do not like it

»
6 weeks ago, # |
  Vote: I like it +20 Vote: I do not like it

This fast :0

»
6 weeks ago, # |
  Vote: I like it -25 Vote: I do not like it

Why did 109265569 give Wrong answer for problem D. TLE would be given if time limit had exceeded. But why wrong answer?

  • »
    »
    6 weeks ago, # ^ |
    Rev. 2   Vote: I like it +2 Vote: I do not like it

    Numbers won't fit in the desired data type. We are multiplying each element by x in each query. Suppose x is like 2 * 10^5, even in 100 queries, x would become 10^105 which is so large.

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

      So how to solve that ?

    • »
      »
      »
      6 weeks ago, # ^ |
        Vote: I like it 0 Vote: I do not like it

      We just need to save the factors of x, they and their times are less than or equal to 2 * 10 ^ 5

»
6 weeks ago, # |
  Vote: I like it -26 Vote: I do not like it

Does Segment Tree + bignumber work for D?

  • »
    »
    6 weeks ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    Most likely you'll get TLE. The numbers can get huge if for example we have 1 number and multiply it by 2e5 every time.

  • »
    »
    6 weeks ago, # ^ |
      Vote: I like it +9 Vote: I do not like it

    i tried to use segment tree but it gave tle :(

    • »
      »
      »
      6 weeks ago, # ^ |
        Vote: I like it 0 Vote: I do not like it

      i tried using seg tree but it gives WA. i used this approach https://codeforces.com/contest/1493/submission/109260301

      • »
        »
        »
        »
        6 weeks ago, # ^ |
        Rev. 2   Vote: I like it +2 Vote: I do not like it

        Modifying it (segment tree) correctly can give AC. See this 109274205

        • »
          »
          »
          »
          »
          6 weeks ago, # ^ |
            Vote: I like it 0 Vote: I do not like it

          Thanks

        • »
          »
          »
          »
          »
          6 weeks ago, # ^ |
            Vote: I like it 0 Vote: I do not like it

          why storing factors in map ? we can not use gcd function? why this logic is not working ? https://codeforces.com/contest/1493/submission/109252075)

          • »
            »
            »
            »
            »
            »
            6 weeks ago, # ^ |
            Rev. 2   Vote: I like it +10 Vote: I do not like it

            gcd of a set of numbers is the number consisting of the intersection of the prime numbers of each number in the set. You just need to take the modulo remainder of any number from the set to ruin everything

            • »
              »
              »
              »
              »
              »
              »
              6 weeks ago, # ^ |
                Vote: I like it 0 Vote: I do not like it

              For example a = 10, b = 5, c = 35, mod = 4. GCD(a, b) = 5, 5 mod 4 = 1. gcd(1, 35) = 1. But, gcd(a, b, c) = 5. You can use segment tree, but you need to think in another key.

              • »
                »
                »
                »
                »
                »
                »
                »
                6 weeks ago, # ^ |
                  Vote: I like it 0 Vote: I do not like it

                It was a bad example, sorry. Correct example: a = 50, b = 25, c = 100, mod = 9. gcd(50, 25) = 25. 25 mod 9 = 7. gcd(7, 100) = 1. But, gcd(a, b, c) = 25. 25 mod 9 = 7.

        • »
          »
          »
          »
          »
          6 weeks ago, # ^ |
            Vote: I like it 0 Vote: I do not like it

          Can you explain, what exactly "addl" and "addr" is doing?

          • »
            »
            »
            »
            »
            »
            6 weeks ago, # ^ |
              Vote: I like it 0 Vote: I do not like it

            The map in each node of the tree contains the excess counts of various primes (i.e. information pertaining to which — left or right child of that node has excess).

            Now in order to update a node, we need to inform the node whether the left child has its gcd updated or the right child. This is communicated by calling addl() when the left child's gcd is multiplied by some factor (similarly addr()).

            Comprehensively, say some node's gcd has been multiplied by x, and it happens to be a left child. In this case, its parent will call addl passing x. addl will then factorise x and use these factors and the map to find the additional factors that the right child had which can be combined and used to updated the gcd here. The state of the map is also updated here.

            addr performs a similar task.

  • »
    »
    6 weeks ago, # ^ |
    Rev. 2   Vote: I like it +5 Vote: I do not like it

    a [i] can be equal to 10 ^ (10 ^ 5) and __gcd work in log (n). obviously it will be TLE

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

      Can you analyse my code's time complexity which got tle on pretest 4!!

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

        Each time you run over the common divisor of the sons of the vertex. but there can be a lot of them. -> This is to add time log (x)

        log (n) from tree, log (x) from multiset, and the number of common prime divisors of sons-> log (x) general asymptotics O (qlog (X) Log (x) log (n)) is TLE ~ 11sec

  • »
    »
    6 weeks ago, # ^ |
      Vote: I like it +12 Vote: I do not like it

    Bignumber will definitely TLE, because operations with bigint -> +-/* work in polynomial time relative to the length of the number.

  • »
    »
    6 weeks ago, # ^ |
      Vote: I like it +9 Vote: I do not like it

    I got an AC, 109274205, while using a segment tree (modified) which ran in <650ms. The idea was to have for each segment [l,r] store the gcd of the range and a map storing for each extra prime (which is in excess in either the left or right range) its frequency (negative or positive depending on which range has excess).

    Now, in order to update a tree node (query), you can prime factorize the value and compare prime factors with elements of the map, and update them along with the gcd.

    Can someone calculate a tight bound on the time complexity, as according to me its O(n log^3 n)? [log^3 -> at each level prime factorize and for each prime factor update a map value]

  • »
    »
    6 weeks ago, # ^ |
    Rev. 4   Vote: I like it +2 Vote: I do not like it

    I think use SegmentTree to solve D is easier. 109248519.

    We use a dynamic create point segment tree for each prime factor to maintain single point addition and global $$$\min$$$.

    Regarding how to update the answer, every time we add a single point to the segment tree of a certain prime factor and see if the global $$$\min$$$ of this segment tree has changed, just fastpower the answer to multiply if it changes.

    $$$ 2 \times 3 \times 5 \times 7 \times 11 \times 13> 2 \times 10^5 $$$, so we just modify at most 6 segment trees for a number change, so the time and space complexity are both It is $$$\mathcal O(6\times(n+q)\log a_i)$$$.

    Emm... I used $$$\mathcal O((n+q)\sqrt {a_i})$$$ prime factor,you can use $$$\mathcal O(n - (n+q)\log a_i)$$$ :P

    • »
      »
      »
      6 weeks ago, # ^ |
        Vote: I like it +6 Vote: I do not like it

      How is it easier? Instead of segment tree you can use multiset (as in editorial) since you only need the minimum of the full range everytime. Am I missing something?

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

    This comment should not be downvoted, it is a friendly and kind discussion.

»
6 weeks ago, # |
  Vote: I like it 0 Vote: I do not like it

Wow, This much fast.. :)

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

The editorial came out really fast, excellent!

I think this contest is as hard as I expected, and I only solve the first three problems.:(

I hope I won't get any fst. ples!

»
6 weeks ago, # |
  Vote: I like it -10 Vote: I do not like it

A very great contest.

Let me know how silly I am.

E is very easy but I wrote a very long and incorrect code :(

»
6 weeks ago, # |
  Vote: I like it +20 Vote: I do not like it

Why you just don't give transformations in B

  • »
    »
    5 weeks ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    n problem B there is one test case 51 3 30:01 (8th case) How is answer 50:00? shouldn't the answer be 00:00? as if 50:00 then 00:05 isn't a valid time...plz explain someone

    https://codeforces.com/contest/1493/submission/109793069 here is my submission Can you plz help me out? is the jury's answer wrong?

    • »
      »
      »
      5 weeks ago, # ^ |
        Vote: I like it 0 Vote: I do not like it

      You forgot to consider the fact that mirror image of 5 will be 2, So this is valid time.

»
6 weeks ago, # |
  Vote: I like it +1 Vote: I do not like it

Not so easy round! xD

»
6 weeks ago, # |
  Vote: I like it 0 Vote: I do not like it

Such a FAST update! It really helps me because I can't wait to learn the solutions of the problems!

»
6 weeks ago, # |
Rev. 3   Vote: I like it -34 Vote: I do not like it

Waiting for another contest from you :)) !

  • »
    »
    6 weeks ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    Implementation heavy contest. But I think questions were not that much tough.

»
6 weeks ago, # |
  Vote: I like it 0 Vote: I do not like it

I hastily read the problem statement for C and solved it for exactly k occurrences. Feel so dumb now. Also this contest seemed more on the implementation side.

»
6 weeks ago, # |
  Vote: I like it 0 Vote: I do not like it

Can someone explain how to estimate the time complexity of D?

  • »
    »
    6 weeks ago, # ^ |
    Rev. 4   Vote: I like it +4 Vote: I do not like it

    (n + q)log(max(X))

    we can get answer for each request in log (x) using Eratosthen

    UPD: i missed log from mutiset

»
6 weeks ago, # |
Rev. 3   Vote: I like it -9 Vote: I do not like it

Thanks for contest

»
6 weeks ago, # |
  Vote: I like it 0 Vote: I do not like it

So fast

»
6 weeks ago, # |
  Vote: I like it +8 Vote: I do not like it

Thank you for the contest!

»
6 weeks ago, # |
  Vote: I like it +46 Vote: I do not like it

I had a slightly different approach to D which didn't require the use of multiset, first we calculate the gcd after processing all the queries and after that we process the queries in reverse order where instead of multiplying we divide the index with the number given and if the number occurrences of a prime factor becomes less than the number of occurrences in the current answer we change the answer accordingly.

»
6 weeks ago, # |
  Vote: I like it -10 Vote: I do not like it

There were some difficult problems but still a great, well put together round after all!

»
6 weeks ago, # |
  Vote: I like it -11 Vote: I do not like it

Nice round and fast editorial

»
6 weeks ago, # |
  Vote: I like it 0 Vote: I do not like it

Anyone having tough times understanding C?

»
6 weeks ago, # |
  Vote: I like it 0 Vote: I do not like it

implementForces :(

»
6 weeks ago, # |
  Vote: I like it -10 Vote: I do not like it

very fast editorial!!!!!

»
6 weeks ago, # |
  Vote: I like it -10 Vote: I do not like it

The solutions came out fast!!!

»
6 weeks ago, # |
  Vote: I like it 0 Vote: I do not like it

I made the logic of C problem in approx 30 minutes, but for implementation It took totally 1 hour, but the logic was correct. due to one silly mistake not able to get ac. :(

»
6 weeks ago, # |
  Vote: I like it -18 Vote: I do not like it

can someone explain d?why answer wont dec it can be 1 also sometimes..

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

    GCD is really the smallest power of each prime multiplied together. So after multiplying a value x, for each prime, its power is not going to decrease.

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

I do not think this is true for problem C: "If the string s is beautiful, then s itself is the answer." Because the length of s can be smaller than n as I it does not state otherwise in the problem statement. Otherwise a great tutorial. I had the exact same idea but took me too long to implement it sadly:(

  • »
    »
    6 weeks ago, # ^ |
      Vote: I like it +14 Vote: I do not like it

    length of s is always n, as it says in the input section of the statement

»
6 weeks ago, # |
  Vote: I like it 0 Vote: I do not like it

probelm B: https://codeforces.com/contest/1493/submission/109275855 Im not able to figure out the mistake.

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

    You are setting "a" to 2 and two lines below you are setting the same 2 to 5. Same for var b. Those if should have been if-else. I don't know if there are more problems, but at least that is.

»
6 weeks ago, # |
  Vote: I like it +1 Vote: I do not like it

I used segment tree in D and it worked well. Just add new nodes dynamically so as not to get a TLE.

»
6 weeks ago, # |
  Vote: I like it 0 Vote: I do not like it

I cannot get the mistake in my Problem C's code. (WA on test 3 (272th line).

Could someone help?

Code link

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

    Maybe you need to increase the amount of occurences of 'a' on suffix to make sure that the length of answer equals n instead of adding the letter *st.begin() .

    • »
      »
      »
      6 weeks ago, # ^ |
        Vote: I like it 0 Vote: I do not like it

      Thank you, now it is accepted as that was the only error.

»
6 weeks ago, # |
  Vote: I like it 0 Vote: I do not like it

Thank you for fast tutorial!

»
6 weeks ago, # |
  Vote: I like it 0 Vote: I do not like it

According to the editorial, I think it would be better if you used -1 for not calculated states. Using dp=2 is a little bit confusing, because as you said in the editorial, number of r is just the sum of dp... and etc. Just some advice.

»
6 weeks ago, # |
  Vote: I like it 0 Vote: I do not like it

QD

until now i don't know why segment tree got MLE, i think because of recursion

here is my impl. if you wanna chick it

https://codeforces.com/contest/1493/submission/109276549

»
6 weeks ago, # |
  Vote: I like it 0 Vote: I do not like it

Why this logic is not working in problem D can anyone tell me please? Link : https://codeforces.com/contest/1493/submission/109252075

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

    You can't take modulo like that

    For example if (mod = 3)

    array = {4,6,8}, gcd(array) = 2

    then if we get modulo for them

    array = {1,0,2}, gcd(array) = 1

»
6 weeks ago, # |
  Vote: I like it 0 Vote: I do not like it

Am getting Runtime Error on TC 4
Submission Link: https://codeforces.com/contest/1493/submission/109286557

I have taken the variable names as intuitive as possible in case you decide to help me.
Please tell me why am I getting this error, what mistake have i made in my code.

Thanks in Advance !!

  • »
    »
    6 weeks ago, # ^ |
      Vote: I like it 0 Vote: I do not like it
    // find and update in set
    auto it = factor_to_freq_index[factor].find({prev_freq, i});
    if (it != factor_to_freq_index[factor].end())
            factor_to_freq_index[factor].erase(it);
    

    I am not particularly sure, but in a rough glance this seems to stand out. If previously there were no factors for $$$a_i$$$, prev_freq will be $$$0$$$, and you will be erasing some random element from the factors frequency set.

    • »
      »
      »
      6 weeks ago, # ^ |
        Vote: I like it 0 Vote: I do not like it

      Hi, i don't think thats an issue,coz:-
      Am storing for each prime factor its power/frequency for all indexs in factor_to_freq_index map so all elements will be distinct.

      ith factor -> has elements {power of ith factor on jth index ,jth index}

      I hope this makes it clear.
      Anyways, thanks for trying and please do let me know if incase you find any issue.

»
6 weeks ago, # |
Rev. 2   Vote: I like it +16 Vote: I do not like it

Problem F: you can check if $$$k$$$ is a period in $$$3$$$ queries.

This is equivalent to check if $$$x = n/k$$$ "blocks" of $$$k$$$ rows are equal.

Let $$$[l, r]$$$ be the segment of blocks from $$$l$$$ to $$$r$$$. Let $$$y = \lfloor (x-1)/2 \rfloor$$$.

It's enough to check if

  • $$$[1, y] = [y + 1, 2y]$$$
  • $$$[1, y] = [y + 2, 2y + 1]$$$
  • either $$$x$$$ is odd, or $$$[1, x/2] = [x/2 + 1, x]$$$

This was enough to get AC with some dirty randomization. 109275723

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

    I also used kind of the same approach, but without randomization it also passed. 109267700. I tested my approach locally against all pairs of $$$r,c \leq 1000$$$ with the worst case for my program (when all queries return 1, all elements are equal). For all r and c my approach was under the query limit.

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

    You need to cut only by primes. And if cut fails don't try same prime again. 109297822

    I did check that n blocks are same: if n == 2 just compare 0 and 1, otherwise if n is prime then it's odd, so:

    • check [0,(n-1)/2-1] = [(n-1)/2,n-2]
    • check [1,(n-1)/2] = [(n-1)/2+1,n-1]
    • check [0,1] = [1,0] if necessary (now it looks like ababababa, and with n = 3 you already know a = b)
    • »
      »
      »
      6 weeks ago, # ^ |
      Rev. 2   Vote: I like it +21 Vote: I do not like it

      Regarding to number of checks. Factorization of N has at most $$$\log_2(N)$$$ factors, for 2 it performs 1 check, for 3 it performs 2 checks, each factor >= 5 it performs 3 checks. For any M with prime factors >= 5 there is N < M with prime factors replaced into 5 with same worst case checks amount. In other words, worst checks count is maximum for some number $$$N = 2^a3^b5^c$$$, then checks $$$a+2b+3c$$$ and $$$\log_2(N) = a+b\log_2(3)+c\log_2(5)$$$. So, we want to maximize $$$a+2b+3c$$$ over constraint $$$a+b\log_2(3)+c\log_2(5) \leq \log_2(N). a, b, c >= 0.$$$ We can apply linear programming knowledge. For real values a,b,c maximum is bigger than any integer solution. Vertices gives $$$\log_2(N)$$$, $$$2\log_2(N)/\log_2(3)$$$, $$$3\log_2(N)/\log_2(5).$$$ So, winner is $$$\log_2(N)\cdot 3/\log_2(5)$$$ which is approximately $$$1.29203\cdot \log_2(N)$$$.

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

        You can also do this: We only do one dimension of the grid at a time. Call this dimension n. Then the prime factorization of $$$n = p_0^{k_0}\cdot p_1^{k_1} \dots$$$. Do queries for each distinct prime factor. So for $$$p_i^{k_i}$$$ We need to find the biggest $$$c \leq k_i$$$ such that the grid can be divided in $$$p_i^c$$$ blocks. We do this incrementally. We can check first if the grid is divisible by p blocks. Than we check if the first out of these blocks is again divisible by p. We do this procedure recursively c times. For odd primes we can do this in 2 queries per divisibility check. For the only even prime $$$2$$$ we only have to do one query. So the worst case queries is # factors of 2 + 2* #factors of all other primes. The worst case is either $$$log_2(n)$$$ queries or $$$2 * log_3(n)$$$, the smallest odd prime. So the worst case for one dimension for this approach is $$$\frac{2}{log_2(3)} log(n) \approx 1.262 log(n)$$$

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

          how can you check with two queries for odd primes >= 5?

          • »
            »
            »
            »
            »
            »
            6 weeks ago, # ^ |
              Vote: I like it 0 Vote: I do not like it

            oh, I see now. it's above. [1,y]=[y+1,2y], [1,y]=[y+2,2y+1].

  • »
    »
    6 weeks ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    I think $$$2$$$ queries are enough. If $$$x$$$ is odd, check the first two points and if it's even, check the first and the last points. Here's a submission using $$$2$$$ queries.

  • »
    »
    6 weeks ago, # ^ |
    Rev. 3   Vote: I like it 0 Vote: I do not like it
    • I can check if k is a period in 2 queries.
    • if x = [n/k] "blocks" and x2 = [x/2]
    • I call {L,R} is blocks from L to R
    • if x odd you will check: {1,x2} = {x2 + 1,2 * x2} and {1,x2} = {x2 + 2,2 * x2 + 1}
    • if x even you check: {1,x2} = {x2 + 1,2 * x2} and {1,x2 — 1} = {x2,2 * x2 — 2}
    • This is my code: https://codeforces.com/contest/1493/submission/109450681
»
6 weeks ago, # |
  Vote: I like it 0 Vote: I do not like it

Can anyone tell why my solution to D will not exceed the memory limit. As in my accepted solution I am creating a map of multiset of the number of each prime that I am getting. and in worst case, if a prime is present in all n elements then the size of this map of multiset will be (2*1e5)*20000 memory (as there are more than 20000 primes from 2 to 2e5), which is too huge to pass. But I am not sure how it is getting accepted?

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

    This applies for any solution which stores only non-zero prime powers for each element. Any number less than 2e5 is made of $$$<18$$$ unique primes. So initially, we have at max $$$18*n$$$ {prime, position} pairs. In each update, we are are multiplying by $$$x$$$ which can bring at most 18 more unique {prime, position} pairs into the map. So, in the end the map should not have more than $$$18(n+q)$$$ {prime,element} pairs, which is $$$O((n+q)log(max))$$$ memory complexity.

»
6 weeks ago, # |
  Vote: I like it 0 Vote: I do not like it

What should be the result for problem B for the following input

1 51 3 30:01

The official tests say it should be 50:00 whose mirror image is 00:05. 00:05 is invalid since our minutes are only till 3

»
6 weeks ago, # |
Rev. 3   Vote: I like it +22 Vote: I do not like it

Another way of proof 1493E - Enormous XOR.

very long proof
»
6 weeks ago, # |
  Vote: I like it 0 Vote: I do not like it

Those who tried to solve B in contest we missed to convert 2 to 5,5 to 2

»
6 weeks ago, # |
  Vote: I like it -10 Vote: I do not like it

https://codeforces.com/contest/1493/submission/109287327

Problem — D Please tell me, where I am getting wrong. I have used a segment tree to solve this problem.

Thanks in advance!

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

    Your solution is wrong, because you can't just take modulo. For example, if $$$n=2$$$ and $$$a[1] = a[2] = 2*10^5$$$, for query $$$i=1$$$ and $$$x=2*10^{5}$$$, you will multiply first number of array by $$$2*10^{5}$$$ and take modulo $$$10^{9}+7$$$, that's wrong, because $$$gcd(4*10^{10} \, mod \, (10^{9}+7),\, 2*10^{5}) = 1$$$ is not equal to $$$gcd(4*10^{10},\, 2*10^{5}) = 2*10^{5}$$$.

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

      Can you please tell me then how should I overcome this situation, here?

»
6 weeks ago, # |
  Vote: I like it 0 Vote: I do not like it

In the editorial of problem B, I think the context should be

"you need to look over all the moments of time from the given one"

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

Could someone please tell why my submission in problem D giving TLE , I have used same idea as given in editorial . 109312305 .

Edit : I figured out , i was making mistake in calculating the sieve.

»
6 weeks ago, # |
  Vote: I like it +2 Vote: I do not like it

Video Editorial For problem C- K-Beautiful Strings: https://youtu.be/bCeBtoho8II

»
6 weeks ago, # |
  Vote: I like it 0 Vote: I do not like it

Thank you for the editorial :)

»
6 weeks ago, # |
Rev. 2   Vote: I like it +1 Vote: I do not like it

Can someone explain why does the solution given in editorial for D does not exceed memory limit? In the multiset cnt, every i from 2 to maxn can be of size n, therefore memory required will be O(n^2), which will be too much. Am I missing something?

  • »
    »
    5 weeks ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    the number of prime factors of n is bounded by $$$O(logn)$$$ ,each number can only increase the size of cnt by $$$logn$$$ ,in total you process n numbers from the initial array and q queries so the size of the multiset is bounded by $$$O((n+q)*log(2e5))$$$

»
6 weeks ago, # |
  Vote: I like it 0 Vote: I do not like it

How is Problem C implemented with binary search? There is the tag.

»
6 weeks ago, # |
  Vote: I like it 0 Vote: I do not like it

Please tell me why I get time limit exceeded with this ?

https://codeforces.com/contest/1493/submission/109323707

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

    in the update, you run through the divisors of sons every time. but there can be A LOT of them -> from this you get TLE.

»
6 weeks ago, # |
  Vote: I like it +11 Vote: I do not like it

May I ask if there are some problems in problem F's example?

Through the Q & A in the example we can not sure that the matrix is like that...

What if the matrix is

1 2 1 2
1 2 1 2
1 2 1 2

Then the answer will be $$$2 \times 3 = 6$$$ and not $$$2$$$.

  • »
    »
    6 weeks ago, # ^ |
      Vote: I like it +19 Vote: I do not like it

    Sorry I get it...

    The example needn't to prove the matrix is like this

    It only needs to let the answers of the asks conform to this matrix...

    asdfadsf.jpg

»
6 weeks ago, # |
  Vote: I like it 0 Vote: I do not like it

This contest is very helpful for me and Editorial is also very nice !!

»
6 weeks ago, # |
  Vote: I like it +1 Vote: I do not like it

Please help me. Why I get time limit exceeded ?

Submission : https://codeforces.com/contest/1493/submission/109325566

»
6 weeks ago, # |
  Vote: I like it 0 Vote: I do not like it

In the editorial solution for C, is there a specific reason for not just using 'return' incase the given string is already beautiful or the case when no beautiful string is possible? They used 'continue' and a flag to skip the 'for loop'.

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

In question C (K-beautiful strings), I had a doubt in the tutorial statement:

"If sum<suff, then lets increase the amount of occurences of a on suffix by suff−sum."

After adding extra a's, how will it be ensured that the occurance count of 'a' is still divisible by k? Can anyone point what I am missing?

  • »
    »
    6 weeks ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    Overall length $$$n$$$ is a multiple of $$$k$$$. Every letter appears some multiple of $$$k$$$ times in the the first $$$pref + 1$$$ and the last $$$sum$$$ positions combined (because of the way we are constructing the suffix). Hence the remaining number of positions should also be a multiple of $$$k$$$, which we fill all with as.

    • »
      »
      »
      6 weeks ago, # ^ |
        Vote: I like it 0 Vote: I do not like it

      Yes I get it now. It was quite a simple thing, I just over complicated it. Thanks for help!

»
6 weeks ago, # |
Rev. 2   Vote: I like it -8 Vote: I do not like it

Can someone please tell why my code for C is giving Memory limit exceeded on test case 3 Link to the code: https://codeforces.com/contest/1493/submission/109341765 I have done according to the logic in editorial.

GOT IT :)

»
6 weeks ago, # |
  Vote: I like it -63 Vote: I do not like it

Fuck you AlFlen. it's one of the badest contest

  • »
    »
    6 weeks ago, # ^ |
      Vote: I like it +35 Vote: I do not like it

    No need to curse ;(

    I can't even see round 705 in your contest list.

    Can you elaborate why is that round one of the "badest contest"?

  • »
    »
    6 weeks ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    Don't personal attack plz...

»
6 weeks ago, # |
  Vote: I like it 0 Vote: I do not like it

Could someone give me a hint on why the upper bound on the query count is true for 1493F - Enchanted Matrix given that I use the strategy in the tutorial?

  • »
    »
    6 weeks ago, # ^ |
      Vote: I like it +16 Vote: I do not like it

    The editorial was updated, now it contains a more accurate upper bound and a quick proof

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

Can someone clarify the below statement
**__gcd(a, b) % c == __gcd(a % c, b % c) % c** ?

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

Concerning the tutorial to Problem C:

"A detail of realization: we will consider iterated letter at position pref+1 in the array cnt."

I might be wrong but I don't think this sentence is correct. The Russian version seems to be on point though.

»
6 weeks ago, # |
Rev. 3   Vote: I like it +5 Vote: I do not like it

Haven't read the editorial's proof of E (because I'm too lazy :D) but I found a simple one which is probably different, so here's a (very) informal proof:

Suppose that $$$n \geq 2$$$ and that we're dealing with the "interesting" case (the most significant $$$1$$$ bit is shared in $$$l$$$ and $$$r$$$.) We can immediately use $$$r$$$ as a lower bound for $$$f(l, r)$$$. Note that we must choose $$$x$$$ and $$$y$$$ with the same parity, or else $$$g(x, y) < r \leq f(l, r)$$$ (because there'd be an even number of most significant bits). Therefore, their binary representations must either be $$$(...1, ...1)$$$ or $$$(...0, ...0)$$$.

In the first case, all of the bits in $$$g(x, y)$$$, except the least significant one, are the same as those in $$$x$$$ (by a symmetry argument).

In the second case, all of the bits in $$$g(x, y)$$$, except the least significant one, are the same as those in $$$y$$$ (by a similar argument).

In either case, the substring consisting of these bits in $$$g(x, y)$$$ is lexicographically smaller than or equal to the same substring in $$$r$$$. Therefore, we can always set these bits in $$$x$$$ or $$$y$$$ (depending on case) to be equal to those bits in $$$r$$$ (let's call an assignment of $$$x$$$ and $$$y$$$ which satisfies this as the bruh condition). So what's left is determining if we can make the one bit of $$$g(x, y)$$$ to be on or not.

If $$$r$$$ is odd, we can make it on by setting $$$x = y = r$$$ (this is definitely maximal because it satisfies the bruh condition and has the one bit set).

If $$$r$$$ is even, we must set $$$y = r$$$, or else the bruh condition wouldn't be satisfied. If possible, setting $$$x = r - 2$$$ is maximal because of the same reason as the odd $$$r$$$ case. Otherwise, it's easy to see that setting $$$x = y = r$$$ is the best we can do.

  • »
    »
    5 weeks ago, # ^ |
    Rev. 5   Vote: I like it +8 Vote: I do not like it

    Thanks.

    I don't understand all of the non-one bits at first, but soon i got the key ideas and solved it. My explanation of the proof:

    • If both $$$x$$$ and $$$y$$$ are odd ($$$...1$$$), then all of the bits(except the least significant bit) in $$$g(x,y)$$$ are the same as $$$x$$$, so $$$g(x,y) = [x-1, x]$$$. That's because $$$g(x,y) = x \oplus (x+1 \oplus x+2) \oplus (x+3 \oplus x+4) \dots$$$ and all of the bits(except the last bit) in $$$(x+2k-1,x+2k)$$$ are the same.
    • If both $$$x$$$ and $$$y$$$ are even ($$$...0$$$), then all of the bits(except the least significant bit) in $$$g(x,y)$$$ are the same as $$$y$$$, so $$$g(x,y) = [y, y+1]$$$. The proof is similar.

    So for every $$$y$$$, the maximal value of $$$g(x,y)$$$ is $$$y$$$ (if $$$y$$$ is odd) or $$$y+1$$$ (if $$$y$$$ is even).

    • If $$$r$$$ is even and $$$r - l \geq 2$$$, then the answer is $$$r + 1$$$, and it's the maximal possible answer;
    • Otherwise, the answer is $$$r$$$, because $$$\max(g(\dots,r)) = r$$$(because $$$r$$$ is odd or $$$r - l < 2$$$) and $$$\max(g(\dots,l\sim r-1)) \leq r$$$.
    • »
      »
      »
      5 weeks ago, # ^ |
        Vote: I like it +5 Vote: I do not like it

      ah, despite my best efforts, I now realize that "all of the non-one bits" was terribly phrased LOL

      glad that that actually helped someone tho!

    • »
      »
      »
      4 weeks ago, # ^ |
        Vote: I like it 0 Vote: I do not like it

      Great proof and explanation! Thank you.

»
6 weeks ago, # |
  Vote: I like it 0 Vote: I do not like it

Problem C: Test 3:wrong answer There is a nice line smaller than the given answer (test case 272) Can anyone tell me "test 3 case 272"

»
6 weeks ago, # |
  Vote: I like it 0 Vote: I do not like it

Never thought passing an ArrayList to a function can be taking so much time. Costed me TLE and hell lot of time to debug

https://codeforces.com/contest/1493/submission/109385847 — AC

https://codeforces.com/contest/1493/submission/109362908 — TLE

just instead of passing Arraylist passed the same array

»
6 weeks ago, # |
Rev. 3   Vote: I like it +5 Vote: I do not like it

Another (easier?) way to prove E: note that $$$4k \oplus 4k+1 \oplus 4k+2 \oplus 4k+3$$$ is $$$0$$$. So there are atmost 6 "alive" terms in XOR of any range (a prefix of length atmost $$$3$$$ and a suffix of length atmost $$$3$$$ ).

Your 4 paragraph proof of E comes down to two lines if you just observe this fact :P

»
6 weeks ago, # |
Rev. 2   Vote: I like it +46 Vote: I do not like it

Shock! A Candidate Master rank 8000+ but gained +77 rating points and became MASTER!!1

Standings , and you can see rating changes => LYC_music's Profile

Need I to @ Mike ?

  • »
    »
    6 weeks ago, # ^ |
    Rev. 4   Vote: I like it +10 Vote: I do not like it

    .

  • »
    »
    6 weeks ago, # ^ |
      Vote: I like it +19 Vote: I do not like it

    Because these two competitors cheated in this contest and the rating have not rolled back yet.

  • »
    »
    6 weeks ago, # ^ |
      Vote: I like it +30 Vote: I do not like it

    Maybe it will roll back soon...?

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

      After four days.  I think it's a bug in website, or website maintainer forget to change rating.

  • »
    »
    6 weeks ago, # ^ |
      Vote: I like it +14 Vote: I do not like it

    I think cheating people's ratings should be lower instead of just cancel the rating changes of this contest.

»
6 weeks ago, # |
  Vote: I like it 0 Vote: I do not like it

Can someone explain to me why (in the solution for problem C) the suffix receives a letter a until it has the appropriate size? Couldn't that make the number of occurrences of a not divisible by k?

  • »
    »
    6 weeks ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    Can I get the full test data of question B and C ?qaq... Can not find where I get wrong...

  • »
    »
    5 weeks ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    As n and (pref + 1 + suff) are both multiples of k, the difference n — (pref + 1 + suff) is also multiple of k, so fill the gap with these additional pref 'a' won't influence the correctness.

»
6 weeks ago, # |
  Vote: I like it 0 Vote: I do not like it

I think the solution code of question C may be wrong. I use following data to test: 2 20 4 bacefbbcceafddeacbeacabce 21 3 bacefbbcceafddeacbeacabca

correct answer may be: bacefbbcceafeaabceff bacefbbcceafddeacccdf

but it gives the result as: bacefbbcceafeaacccff bacefbbcceafeaaabbccf

the number of some letter's occurences can't be divided by k

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

Is it possible to solve problem_D with Segment tree?

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

In problem B there is one test case 51 3 30:01 (8th case) How is answer 50:00? shouldn't the answer be 00:00? as if 50:00 then 00:05 isn't a valid time...plz explain someone

https://codeforces.com/contest/1493/submission/109793069 here is my submission

  • »
    »
    5 weeks ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    haha, you make the mistake that the reflection of 5 is 2, not 5 itself.I firstly made the wrong mistake as you did.

»
5 weeks ago, # |
  Vote: I like it 0 Vote: I do not like it

For problem C tutorial, I had k — x % k only, why do we modulo again by k?

»
5 weeks ago, # |
  Vote: I like it 0 Vote: I do not like it

in Anti knapsack what is the name of the formula given here.

»
4 weeks ago, # |
  Vote: I like it 0 Vote: I do not like it

MikeMirzayanov Did you forget to roll back the rating?

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

AlFlen In tutorial of problem F, the last paragraph

The worst case is when we divide current minimal r by 3 with 2 queries.

I think the worst case should be when r is divided by 5 with 3 queries, because $$$3 / \log_2 5 > 2 / \log_2 3$$$.