74TrAkToR's blog

By 74TrAkToR, history, 21 month(s) ago, translation, In English

Thanks for the participation!

Tutorial is loading...
Tutorial is loading...
Tutorial is loading...
Tutorial is loading...
Tutorial is loading...
Tutorial is loading...
Tutorial is loading...
  • Vote: I like it
  • +21
  • Vote: I do not like it

| Write comment?
»
21 month(s) ago, # |
  Vote: I like it +136 Vote: I do not like it

Nice.

Spoiler
»
21 month(s) ago, # |
  Vote: I like it 0 Vote: I do not like it

Wow, so fast editorial, thanks!

»
21 month(s) ago, # |
  Vote: I like it +36 Vote: I do not like it

As a tester, I solved problem E with complexity $$$O(100(n+q)\log n)$$$: write the formula as $$$f_i=a_ib_i/\gcd^2(a_i,b_i)$$$. Let's maintain the answer by maintaining segments of same $$$a$$$-s together. It's easy to see that the segments only change $$$O(n+q)$$$ times. In queries, we specially manage the segments the query crosses (i.e. it contains $$$l$$$ or $$$r$$$) and the segments in the middle can be maintained with segment tree.

Now, we essentially have to calculate $$$f(l,r,x)=\max_{l\le i\le r} x\cdot b_i/\gcd^2 (x,b_i)$$$ for $$$O(n+q)$$$ times. Let's enumerate all divisors of $$$x$$$ and try it as a candidate for $$$\gcd(x,b_i)$$$. It's easy to see that we should select the maximum $$$b_i$$$ that is a multiple of $$$x$$$. To maintain largest $$$b_i$$$ in a segment that is a multiple of $$$x$$$, we can use a sparse table or a segment tree for each $$$x$$$. The sum of sizes of the tables is $$$100n$$$, since numbers in $$$[1,50000]$$$ have at most 100 divisors.

177649266

»
21 month(s) ago, # |
  Vote: I like it +7 Vote: I do not like it

queryforces

»
21 month(s) ago, # |
  Vote: I like it +5 Vote: I do not like it

How to solve C1? I understand f(l,r) <= f(l,r+1), but I am not getting how binary search will help here

  • »
    »
    21 month(s) ago, # ^ |
    Rev. 2   Vote: I like it +3 Vote: I do not like it

    finally got it.

    Note= maximum cost will always be sum(arr) - xor_sum(arr). because of f(l,r) <= f(l,r+1).So we need to find the minimum segment length which will give us this cost.

    • For every index i find the nearest index j for which f(i,j) == cost.
    • We can use binary search to find this position j as function f is increasing with increasing value of j.

    My solution is not clean. Especially binary search part but still :=; 177667352

  • »
    »
    21 month(s) ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    Since $$$f(l,r) <= f(l,r+1)$$$ that means that for some $$$1 <= i <= n$$$ the maximum value of $$$f(i,r)$$$ will be for $$$r = n$$$ since the function is increasing. Now the problem asked for the minimum segment therefore we need to find if there is some $$$r$$$ such that $$$i <= r <= n$$$ such that $$$f(i,r) = f(i,n)$$$ and it should be the minimum one, so therefore to find the minimum $$$r$$$ we can use binary search.

»
21 month(s) ago, # |
  Vote: I like it +116 Vote: I do not like it

I think you should explain time complexities properly instead of ending the editorial with

Therefore, this solution will work quite quickly.

It might not be obvious to some of us.

»
21 month(s) ago, # |
  Vote: I like it 0 Vote: I do not like it

Can someone explain D2 problem, I can't understand, the author explanation.

  • »
    »
    21 month(s) ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    Same, solved it but I can't understand the author's intended solution as well.

»
21 month(s) ago, # |
Rev. 3   Vote: I like it +20 Vote: I do not like it

Alternative solution for E (it's just worse than what's in the editorial, but wotever, it got AC):

To do range assign and point get in A, a VEBTree over "important" indices can be used to get O(log log n) updates and queries.

Divide the arrays into blocks of size R (constant we will fix later). Then inside each block, compute for every value $$$\leq 5 \cdot 10^4$$$ what is the smallest multiple of that value which occurs in the range.

Then to compute the answer when an entire block gets set to a value $$$v$$$, it's $$$\min(\texttt{smallest_multiple}[d] \cdot v / d^2 \enspace \vert \enspace d \vert v)$$$

When a an update or query touches but doesn't cover an entire block, just brute force.

$$$O(Rq \log \log n + nqd/R)$$$ where $$$d$$$ is the largest number of factors a number can have, which is something like $$$128$$$ for numbers this small. I chose $$$R=400$$$ from trial and error instead of calculating what block size would make sense.

submission

»
21 month(s) ago, # |
  Vote: I like it 0 Vote: I do not like it

Still don’t get A.. If a[n] mod n != 0, then why can we just check if gcd(g, n)? I mean if a[n] cannot be changed to n, then why checking gcd(g, n) is correct?

Sorry for my poor English in advance.

  • »
    »
    21 month(s) ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    Once you apply an operation on index N you are sure that it will contain only prime factors of number N. Similarly you can see for N-1. Now since N and N-1 won't have any common prime factors gcd(gcd(a[N],N),gcd(a[N-1],N-1)) also won't have any common prime factors. So the value gcd(gcd(a[N],N),gcd(a[N-1],N-1) is guaranteed to be 1.

»
21 month(s) ago, # |
  Vote: I like it +1 Vote: I do not like it

I still cant understand Question B, can somebody explain?

»
21 month(s) ago, # |
  Vote: I like it +8 Vote: I do not like it

In problem E, formula answer_x = min(answer_(x/p) * p) is just plain wrong, even with d not equal to x.

Let n = 1, x = 4, b_1 = 8, p = 2. Then answer_x = lcm(x, b_1) / gcd(x, b_1) = lcm(4, 8) / gcd(4, 8) = 8 / 4 = 2. BUt answer_(x/p) = lcm(x/p, b_1) / gcd(x/p, b_1) = lcm(4/2, 8) / gcd(4/2, 8) = lcm(2, 8) / gcd(2, 8) = 8 / 2 = 4. answer_x is not equal to p * answer(x/p), actually, answer(x/p) > answer_x.

Please show me where I am wrong.

»
21 month(s) ago, # |
  Vote: I like it +3 Vote: I do not like it

Managed to solve both C2 and D2, lost 16 rating.

»
21 month(s) ago, # |
  Vote: I like it +35 Vote: I do not like it

The complexity analysis for D1 and D2 are not so obvious for me. Can someone maybe provide a better explanation?

»
21 month(s) ago, # |
Rev. 2   Vote: I like it -9 Vote: I do not like it

unordered_set/map and gp_hash_table are uphacked.

»
21 month(s) ago, # |
  Vote: I like it +5 Vote: I do not like it

In editorial of D1,

"Note that if k is not one of the largest divisors of x, then x/k becomes greater than q"

Why?

»
21 month(s) ago, # |
  Vote: I like it +47 Vote: I do not like it

Does anyone have a correct proof to the solution of D1?

»
21 month(s) ago, # |
  Vote: I like it 0 Vote: I do not like it

Can anybody explain problem C2? I don't understand what does $$$A$$$ means in the editorial.

  • »
    »
    21 month(s) ago, # ^ |
      Vote: I like it +2 Vote: I do not like it

    $$$A$$$ means the maximum value in array $$$a$$$.

    • »
      »
      »
      21 month(s) ago, # ^ |
        Vote: I like it 0 Vote: I do not like it

      thus the value of the function will become smaller

      Can you explain this? How the function value becomes smaller, when it always increases or stays the same if we add a new element?

      • »
        »
        »
        »
        21 month(s) ago, # ^ |
        Rev. 4   Vote: I like it +2 Vote: I do not like it

        (My English may not be so good. ) I think it might mean this:
        When we're dealing with the query $$$[L,R]$$$, a simple and slow way is to calculate every nearest $$$r$$$ for all $$$l \in [L,R]$$$. However, when the value of $$$[l,R]$$$ is less than the value of $$$[L,R]$$$, we can just end and print the answer, because $$$\forall i \in [l,R]$$$, there's no subsegment of $$$[i,R]$$$ can affect the answer since we want to maximize value first.
        Then consider the time we have calculated before we break, if and only if when we delete the current first element $$$a_{now}$$$, the value of $$$[now+1,R]$$$ is less than $$$[now,R]$$$. And the reduction of the value is because, "at least one of the bits of $$$a_{now}$$$ occurs in $$$xor(now+1,r)$$$". The worst case is the first $$$\log A$$$ elements of $$$[L,R]$$$ have one bit in binary representation respectively and the bit every element have is pairwise distinct. So we have time complexity $$$O(q \log A \log n)$$$ if we use binary search.

        Upd: There's something I forgot just now(
        The worst case is that, the first $$$\log A$$$ elements such that $$$\ne 0$$$ of $$$[L,R]$$$ ......(the condition)
        So we should check the first $$$\log A + 1$$$ elements such that $$$\ne 0$$$ to get the answer.
        If you're confused because of this, I'm sorry.

»
21 month(s) ago, # |
Rev. 2   Vote: I like it 0 Vote: I do not like it

C1 can be solved by brute force with optimization of skipping zeros with O = O(15*15) = 225, since any non-zero element is obliged to reduce the number of bits in the current xor. Thus C2 can be solved by adding a segment tree (to find the xor of segment) with O = (225+log(n))*n.

  • »
    »
    21 month(s) ago, # ^ |
    Rev. 2   Vote: I like it +1 Vote: I do not like it

    xor (l, r) = xor(1, r) ^ xor(1, l — 1), so you don't need to use segment tree. You can find xor with O(1) with prefix xor.

»
21 month(s) ago, # |
  Vote: I like it 0 Vote: I do not like it

What does Hack verdict 'Unexpected verdict' mean? Problem E's hacks have so many this type.

  • »
    »
    21 month(s) ago, # ^ |
      Vote: I like it +5 Vote: I do not like it

    In the system there are solutions that are marked as correct. If a hack is able to break one or more of those solutions (by either TLEing one of them, RTEing one of them, or making their output inconsistent/wrong) then the verdict of the hack will say Unexpected verdict.

    The times when I've triggered Unexpected verdict in the past, the most common reason is that I TLEd one of the Python solutions from the problem setters.

»
21 month(s) ago, # |
Rev. 2   Vote: I like it +15 Vote: I do not like it

This is related to the complexity analysis of $$$D1$$$ and $$$D2$$$:

If we have arrays $$$arr_1$$$ and $$$arr_2$$$, each of them has $$$N$$$ distinct values, where $$$1\le N \le 10^5$$$ and $$$1\le arr_1[i], arr_2[i]\le A_{max}$$$.

Then for each $$$arr_1[i]$$$, we iterate on its positive multiples in ascending order until the first multiple not in $$$arr_2[i]$$$. If $$$A_{max}=N$$$, then the total number of iterations can be calculated as $$$N\cdot \sum_{i=1}^{N}{\dfrac{1}{i}}=N\cdot H(N)=N\cdot log(N)$$$.

If $$$A_{max}$$$ is an arbitrary value larger than $$$N$$$, e.g., $$$10^{18}$$$, is there a way to prove the upper bound on the total number of iterations?

»
21 month(s) ago, # |
  Vote: I like it +1 Vote: I do not like it

has anybody solved C1/C2 with segment tree ? i would like to see how the segments are Merged and stored

»
21 month(s) ago, # |
  Vote: I like it 0 Vote: I do not like it

In C1 and C2, if I have a test like this : 0 8 2 0 and L = 1, R = 4

My output was "2 2" and Jury output was "1 1" and I got WA while segment [2,2] and [1,1] have the same length and f(l,r).

Could anybody explain to me why i'm WA, please :(

»
21 month(s) ago, # |
  Vote: I like it 0 Vote: I do not like it

Problem D2 : I couldn't understand the last part. How we can recalculate these set in the case of an add/remove operation? Can anyone explain? TIA

»
21 month(s) ago, # |
  Vote: I like it 0 Vote: I do not like it

74TrAkToR, In the editorial of D2 shouldn't it be:
*then we should already have added approximately $$$\sum\limits_{i = 1}^t\frac{x}{k_i}$$$.
At second to last line, since we are iterating over t divisors of x from $$${k_1}$$$ to $$${k_t}$$$.

»
21 month(s) ago, # |
  Vote: I like it 0 Vote: I do not like it

Can someone please explain about problem E: how do we count answers for each x in blocks? Would apreciate it

»
21 month(s) ago, # |
  Vote: I like it +8 Vote: I do not like it

Tried hard in D2 problem and at last accepted. I can't believe it was 2400 rated problem.

»
21 month(s) ago, # |
  Vote: I like it +9 Vote: I do not like it

I have an alternate solution for D2 that uses sqrt optimization. Store a block of at max size $$$\sqrt n$$$ delete operations. For all queries run through all the erased numbers in the current block, if $$$x$$$ divides a number in the block ($$$b$$$) just min the answer you had kept previously with $$$b$$$.

If the block reaches size $$$\sqrt n$$$, clear the block and run D1's solution from 0 for all currently stored queries. Complexity over queries amortized is $$$O(n \sqrt n \log(n) + n \log(n)) = O(n \sqrt n \log(n))$$$. Because the clear and reset operation runs at max $$$\sqrt n$$$ times the total time complexity of that is also the same $$$O(n \sqrt n \log n)$$$. Needed some gp_hash_table optimization to remove the $$$\log n$$$ factor and make it pass. 178023023

»
21 month(s) ago, # |
Rev. 2   Vote: I like it +3 Vote: I do not like it

Time limit on problem E is tooooooo tight. The overall complexity is still $$$\mathcal{O}(X\sqrt{X}\log X)$$$ where $$$X = 5 \times 10^4$$$. From the complexity perspective the fansy $$$\mathcal{O}(X\log \log X)$$$ optimization in the precalculation seems not necessary.

I've also tried a $$$\mathcal{O}(100n\log n)$$$ segment tree solution and it still can't pass the time limit.

»
21 month(s) ago, # |
  Vote: I like it 0 Vote: I do not like it

Anyone got a solution to C1 using two pointers? Would help a lot! Thanks in advance!

»
21 month(s) ago, # |
  Vote: I like it +1 Vote: I do not like it

In fact,I don't understand problem B and this tutorial o(╥﹏╥)o

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

There needs to be a proof for the upper bound time complexity on D1

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

Time complexity pf problem D1 should be O(qlogq). explanation : consider first q queries of insertion of 1 to q numbers and then for next q queries getting mex of 1 to q numbers . Insertion of 1 to q numbers takes O(qlogq) time . for finding mex of each element from 1 to q it will take (q/1+q/2+q/3 +q/4+....q/q)==qlogq Total time complexity : O(qlogq)+O(qlogq)==O(qlogq)

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

Honestly this is a very funny round if your rating does not depend on it.

The formal proof for D2 is really tedious, I could not normally prove it.

I passed E with a constant equal to 105, if it is 100 or 110 it TL's.

This is so fucking funny it is unbelievable.

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

Can someone please explain the proof for time complexity for problem D1. The editorial says If k is not one of the largest divisors of x, then x/k becomes greater than q. Therefore, this solution will work quite quickly

There could be case like x = 10^6 and y = 10. This could run for 10^5 times.

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

I did B quite differently,by iterating the string backwards and locating the 1st different element and doing the operation on that to make it equal to its predecessor and so on until i reach the "good" index from the starting,the good index from the starting would be the ind,until which string is already perfect.