Please read the new rule regarding the restriction on the use of AI tools. ×

Error_Yuan's blog

By Error_Yuan, 17 months ago, In English

1869A - Make It Zero

Author: Error_Yuan

Hint 1
Hint 2
Solution
Implementation
Rate the problem

1869B - 2D Traveling

Author: programpiggy

Hint
Solution
Implementation
Rate the problem

1868A - Fill in the Matrix

Author: Error_Yuan

Hint 1
Hint 2
Solution
Implementation
Rate the problem

1868B1 - Candy Party (Easy Version)

Author: Error_Yuan

Hint 1
Hint 2
Hint 3
Solution
Implementation
Rate the problem

1868B2 - Candy Party (Hard Version)

Author: Error_Yuan
Please, read the tutorial for B1 first.

Hint 4
Hint 5
Hint 6
Solution
Implementation
Rate the problem

1868C - Travel Plan

Author: programpiggy

Hint 1
Hint 2
Hint 3
Hint 4
Hint 5
Solution

$$$\mathcal O(\sum(m\log n+\log^3n))$$$ solution by programpiggy:

Implementation

$$$\mathcal O(\sum \log^3n)$$$ solution by sszcdjr:

Implementation

$$$\mathcal O(\sum \log^2n)$$$ solution by sszcdjr:

Implementation

$$$\mathcal O(\sum m\log n)$$$ solution by MatrixGroup:

Implementation
Rate the problem

1868D - Flower-like Pseudotree

Author: sszcdjr

Hint 1
Hint 2
Hint 3
Hint 4
Hint 5
Solution
Implementation
Rate the problem

1868E - Min-Sum-Max

Author: duck_pear
Huge thanks to Kubic for the development of this problem!

Hint 1
Hint 2
Hint 3
Hint 4
Fun Fact
Solution
Implementation (by Artyom123)
Rate the problem

1868F - LIS?

Author: Error_Yuan

Hint 1
Hint 2
Hint 3
Solution
Implementation
Bonus
Hint for Bonus

Bonus solution by duck_pear:

Implementation
Rate the problem
  • Vote: I like it
  • +26
  • Vote: I do not like it

| Write comment?
»
13 months ago, # |
  Vote: I like it -50 Vote: I do not like it

First Comment!!!

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

thanks for fast tutorial

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

wtf!! 4 months ago?

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

    They prepare the blog before

»
13 months ago, # |
  Vote: I like it +6 Vote: I do not like it

anyone knows edge case of test case 3 of problem b?? my sumbission :- https://mirror.codeforces.com/contest/1869/submission/222740219

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

ORZ fast tutorial

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

Typo in B1, should be $$$\implies a_i<a_j$$$

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

Why I am getting pretest failed in Problem A ? Here is the code

  • »
    »
    13 months ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    try the case

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

    when you do the last one, you are just replacing $$$a_{n}$$$ with $$$a_{n}$$$.

    • »
      »
      »
      13 months ago, # ^ |
        Vote: I like it 0 Vote: I do not like it

      I am replacing a[n] with XOR of a[n] and a[n] which is 0 as p and r can be equal(given in the question's constraint)

      • »
        »
        »
        »
        13 months ago, # ^ |
          Vote: I like it 0 Vote: I do not like it

        l and r . Sorry for the typo

        • »
          »
          »
          »
          »
          13 months ago, # ^ |
            Vote: I like it 0 Vote: I do not like it

          You are replacing a[n] with a[n]. When you do the xor for only one number, you don't get the xor of 2 numbers. To make it more clear, assume the operation was multiplication in stead of xor. When you want to find the product of the numbers from l to r, where l = r = n, your answer is a[n], not a[n] * a[n]. I hope this approach helped you visualise your mistake.

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

        The problem said you replace each $$$a_i$$$ with $$$a_l\oplus a_{l+1}\oplus\cdots\oplus a_r$$$, for $$$l\le i\le r$$$.

        So for example,

        • if $$$l=1$$$ and $$$r=3$$$, you set each $$$a_i=a_1\oplus a_2\oplus a_3$$$.

        • if $$$l=1$$$ and $$$r=2$$$, you set each $$$a_i=a_1\oplus a_2$$$.

        • if $$$l=1$$$ and $$$r=1$$$, you set each $$$a_i=a_1$$$.

        Do you see it now?

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

          Yesh got it now...btw awesome explanation

»
13 months ago, # |
Rev. 4   Vote: I like it +2 Vote: I do not like it

Here is my solution using dijkstra's if anyone wants to have a look. Please check it here Great solution in the tutorial by the way, will get there one day.

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

Quick question, in 2D Traveling how are we making sure that there are 2 major cities in between source and destination?

edit — got it, it doesn't matter!!

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

    In the shortest path, there are either 2 major cities between source and destination, or none.

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

    Well we don't have to verify that there are 2 cities.

    Think of it like this, both cities A and B have a closest major city, except if k=0 in which case the answer is just the direct flight from A to B.

    Using the fact that both A and B have a closest major city, we can calculate for both A and B which major city is closest to them, just by iterating over all major cities and calculating the distance and keeping track of the shortest distance.

    Now we know that we can go from any major city to any other major city for 0 cost, and even if both A and B are closest to the same city, our solution still works.

    Then we can simply say ans=min(AtoMAJOR+BtoMAJOR, AtoB).

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

How to aproach MEX problems? i rarely got solve them

  • »
    »
    13 months ago, # ^ |
      Vote: I like it 0 Vote: I do not like it
    1. Practice more problems ...

    2.(Might be silly tip):Use Pen and Paper while you do rough work especially for math ones.

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

got wa in b just because of taking max value for mins = 1e9

»
13 months ago, # |
  Vote: I like it +8 Vote: I do not like it

Any simpler explanation for B2? I can't quite comprehend the way mentioned in the editorial lol

»
13 months ago, # |
  Vote: I like it +159 Vote: I do not like it

In D1B, I wonder how many people proved (before submitting) that we can always choose a starting point, or at least noticed that it needed a non-trivial work to prove... I think this part is the hardest part of the problem so I feel like it is "the more you think, the more you lose points" problem.

  • »
    »
    13 months ago, # ^ |
      Vote: I like it -12 Vote: I do not like it

    Yep, the conclusion is quite guessable, but it's really hard to prove.

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

    Same, I've spent 15 minutes after writing a solution trying to prove it, shouldn't have done that.

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

    Ah funny, I just commented a similar thing below. I noticed but gave up on proving. I tried to write a solution that doesn't assume that, but I think it's really hard/tedious because of the $$$a[i]$$$ which are already equal to the mean.

    I feel like this type of thing, where some proof detail is quite hard, happens somewhat often. It kind of destroys me psychologically in contest, because I don't believe in my solution anymore.

    But other people can reliably umm... not have this problem I guess. I would like to know how lol.

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

      For me it is a bit instinctual. Ideally, I'd like to prove it in my mind or on paper before submitting, but I think sometimes that is a waste of time. If I have convinced myself beyond reasonable doubt then I simply submit. Like in this problem, I didn't feel that I needed to prove it, it just felt very natural to me that it was possible.

      I think this really depends on if you are a very mathematical person or not. I'm somewhere in between but I've had students on either end of that spectrum and their method works for them, but is a bit too extreme for my taste.

»
13 months ago, # |
  Vote: I like it +38 Vote: I do not like it
1B1
»
13 months ago, # |
  Vote: I like it +4 Vote: I do not like it

My solution for Div1 B1/B2 was (I think?) a bit simpler than the editorials. Basically, similar to the editorials we can get two numbers a and b where we must give a and receive b. This can be transformed into, if we gained b, we send a. This is kind of like a graph where there are n edges, each representing a transfer that needs to happen. Then, to check if this graph is valid, it's quite easy. All you have to do is check if the graph can be turned into a bunch of cycles that do not reuse edges. It's very similar to finding an Eulerian circuit, and the restriction for that (for directed graphs) is that the indegree and outdegree must be the same. Something important is that in the case of the number equalling the average, the edge is a self-edge but can be placed anywhere, and as long as you visit a node, it works. Then, for B2, note that if the distance is a power of two then you can change two operations into one. The change to the degree array is +2 -1 or -2 +1 so you can loop downwards and apply changes when needed if possible.

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

in problem A div2, when n is odd , if I perform [n,n] once instead of performing [n-1,n] twice, it should give the correct answer right? as a[n] ^ a[n] = 0 .

  • »
    »
    13 months ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    Well no. Operation for [n, n] will do nothing. Think of it this way, operation[1, 2] is a[1] ^ a[2], operation[1,3] is a[1] ^ a[2] ^ a[3] then operation[1,1] will be a[1], that's it, no more xor taken from there. It is range, so range(1, 3) contains 3 elements, range(1,1) contains only 1 element.

  • »
    »
    13 months ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    n,n just means the xor of the subarray (n,n) and you are replacing an with an only not by an^an;

  • »
    »
    13 months ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    Nope, because you don't XOR a[n] twice. The XOR in the range [n, n] would just be a[n], leaving the array unchanged.

    • »
      »
      »
      13 months ago, # ^ |
        Vote: I like it -9 Vote: I do not like it

      why? check the definition that they gave: Let s=al⊕al+1⊕…⊕ar right? and they said l<=r suppose l==r s=al xor ar no?? I actually got two wrong answers because of this! please prove me wrong :)

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

        I see your point, but I think that's just standard mathematical notation: for example, I think you agree if I say that the sum of the numbers from 1 to n is n(n+1)/2, right? But according to your argument, for n = 1 it should be 1+1 = 2.

        • »
          »
          »
          »
          »
          13 months ago, # ^ |
            Vote: I like it 0 Vote: I do not like it

          if we put n=1 in the formula blindly we will get it equal to 1 , not the same with their definition

          • »
            »
            »
            »
            »
            »
            13 months ago, # ^ |
              Vote: I like it 0 Vote: I do not like it

            Yeah, but the formula is not what I focused on. I just wanted to point out that when we talk about the sum of the numbers from 1 to n we typically denote it as $$$1 + ... + n$$$. This notation means "1" and not "1+1" when $$$n=1$$$.

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

    Fill in the missing expression in the sequence!!! 95% fail!!!

    $$$\underline{\qquad}$$$, $$$1\oplus2$$$, $$$1\oplus2\oplus3$$$, $$$1\oplus2\oplus3\oplus4$$$, $$$\ldots$$$

    Hint: The answer is $$$\textbf{not}$$$ $$$1\oplus1$$$!

»
13 months ago, # |
  Vote: I like it +19 Vote: I do not like it

Video Editorial for problem A,B,C,D1

»
13 months ago, # |
  Vote: I like it +39 Vote: I do not like it

Why does only taking good interval give the min amount of operations on F?

»
13 months ago, # |
  Vote: I like it +23 Vote: I do not like it

It appears that there are some typos in the editorial for B2. I believe these are the correct formulas:

For $$$x \leq cntDS_i$$$:

  • $$$cntS_i := cntS_i + x$$$
  • $$$cntS_{i+1} := cntS_{i+1} + cntDS_i - x$$$
  • $$$cntT_i := cntT_i + cntDS_i - x$$$

For $$$x \leq cntDT_i$$$:

  • $$$cntT_i := cntT_i + x$$$
  • $$$cntS_{i-1} := cntS_{i-1} + cntDT_i - x$$$
  • $$$cntT_i := cntT_i + cntDT_i - x$$$
»
13 months ago, # |
  Vote: I like it 0 Vote: I do not like it

Can anyone explain why does the solution to problem A (Div. 2) works?

  • »
    »
    13 months ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    For this problem I first considered if each of the $$$a_i$$$ are either $$$1$$$ or $$$0$$$, since it helps to think about the most extreme cases first sometimes.

    Then notice that $$$1\oplus 1\oplus\cdots\oplus 1 = 0$$$ if the number of $$$1$$$'s is even, otherwise it's equal to $$$1$$$.

    Also notice that $$$0\oplus 0\oplus\cdots\oplus 0 = 0$$$ for any number of $$$0$$$'s.

    So clearly, if $$$r-l+1$$$ is even, then performing the operation on $$$a_l,a_{l+1},\dots,a_r$$$ will either make them all equal to $$$0$$$, or $$$1$$$, and then performing the operation again must always make $$$a_l=a_{l+1}=\cdots=a_r=0$$$.

    But then the same must be true for any values of $$$a_i$$$, not only if they are in $$$\{0,1\}$$$, since the same will happen for all of the bits of the numbers.

    So if $$$n$$$ is even, then we can just do the operation twice on the entire subarray.

    If $$$n$$$ is odd, we perform the operation twice on the first $$$n-1$$$ elements, and then twice on the last $$$n-1$$$ elements to ensure that all the numbers in the array are $$$0$$$.

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

For 1869A — Make It Zero, why couldn't you do something like cout<<n<<" "<<n<<endl; ?
Edit: I didn't see the posts above my bad

  • »
    »
    13 months ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    That doesn’t do anything. It replaces the last element just by the last element itself. We need to replace it by 0.

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

bad cones\

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

For this example in Q D1/B1

1 3 6 4 8

We are getting YES , can anyone tell me method of distribution of candies

  • »
    »
    13 months ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    Test case -> 1 N -> 3 [6,4,8]

  • »
    »
    13 months ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    Last person gives 4 candy to the first one; First person gives 4 candy to the second one; Second person gives 2 candies to the third one.

    First person: 6-4+4=6 Second person: 4-2+4=6 Third person: 8-4+2=6

    • »
      »
      »
      13 months ago, # ^ |
        Vote: I like it 0 Vote: I do not like it

      ohh okay got it.

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

      n=4 [8,16,13,12] how is this yes?

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

        I don't know why you think it's a yes? The total number of candies is 8 + 16 + 13 + 12 = 49 which is not divisible by n = 4. So it's impossible that everyone have the same number of candies after swaps.

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

In problem Div1 C what is $$$f_{i,j}$$$ (one end being $$$i$$$ — what is it?) and what does this mean: The only difference is that only one $$$f_{i,j}$$$ is not $$$0$$$ under this circumstance and we can solve it in $$$O(log^2n)$$$?

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

My approach to Div1B1/Div2D1 and Div1B2/Div2D2, with only 1D vectors and 1D maps and no graphs (though one can argue there is an implicit graph being considered):

Net Gain: The total sum never changes, so to make all values equal, each value must become equal to the average. If the average is not an integer, answer is NO. After calculating the average, we can easily determine, for each value, what number needs to be added/subtracted to reach the average. Each value has a required "net gain" to reach the average. For values above the average, the net gain is negative (since they actually need a net loss).

Validity of Net Gain: In order to reach the average, the net gain must be expressible as the difference between two powers of 2. For example, a net gain of 12 can be achieved by receiving 16 candies and giving 4 candies. But a net gain of 5 cannot be achieved. Checking whether a net gain value is valid, as well as determining what the respective powers of 2 are, is easy when considering the numbers in binary. Assuming $$$x > y$$$, then $$$2^x - 2^y = 2^y (2^{x - y} - 1)$$$ will have $$$(x - y)$$$ 1s in a row, followed by $$$y$$$ lagging 0s. Utilizing the __builtin_clz and __builtin_ctz functions can help in quickly determining whether a net gain value is valid or not, as well as what the corresponding powers of 2 are (but there are many other ways to do this as well). Note that we would also have to deal with scenarios for $$$x = y$$$ (net gain of 0) and $$$x < y$$$ (net gain is negative, but we can inspect the binary representation of the absolute/negated value instead).

Fulfilling all Net Gains (Easy Version): In the Easy version, if a net gain value is valid, i.e., expressible as $$$2^x - 2^y$$$, then the only way to achieve this net gain is to receive $$$2^x$$$ candies and give $$$2^y$$$ candies. To check whether this is possible for all values, I used a simple map mp, where for a positive integer p, an entry mp[k] = p indicates there are p values that want to give k candies, while an entry mp[k] = -p indicates that there are p values that want to receive k candies. For each value where net gain is non-zero, I determine $$$2^x$$$ and $$$2^y$$$, increment $$$mp[2^y]$$$ and decrement $$$mp[2^x]$$$. If all net gains can be fulfilled, then all map entries should be 0 at the end, since the number of people who want to give $$$k$$$ candies must match the number of people who want to receive $$$k$$$ candies, for all $$$k$$$.

Correctness: Having all map entries be 0 is a necessary condition for Yes, but is it sufficient? We don't have to worry about values with net gain 0, because we can simply have them pass a candy around to each other. Even if there is only one value with net gain 0, this person can be placed as a relay between someone who needs to give some candies to another person. The hard part was on checking whether there will always be someone who has enough candies to start the chain. Apparently this is always satisfied (according to the editorial), and while I don't have a proof either, I intuitively observed that the person with the largest number of candies in each cycle should have enough to start the chain.

Easy Submission: 222779990 (it has some artifacts from when I was trying to check whether it's always possible to start the chain, like sorting the values in reverse-order, and setting a flag when somebody has enough to do so, but this doesn't account for multiple independent chains)

Hard Version: If a valid net gain, $$$2^x - 2^y$$$ cannot be be written as $$$\pm 2^z$$$ for integer $$$z$$$, then the only way to achieve this net gain is through receiving $$$2^x$$$ candies and giving $$$2^y$$$ candies, which we have already dealt with in the Easy version. But if $$$2^x - 2^y = \pm 2^z$$$, then there are actually two options. Without loss of generality, if $$$2^x - 2^y = 2^z$$$, then we can either (A) receive $$$2^x$$$ and give $$$2^y$$$, or (B) simply receive $$$2^z$$$ and give nothing. Note that, in this case, we must have $$$x = z + 1$$$ and $$$y = z$$$.

How do we decide which of the two options to choose? My approach was to first deal with the values that have only one option (like Easy Version) and stores the values with two options in a separate vector to handle later. The map mp may have some non-zero entries at this point. For the remaining net gains (which are powers of 2, or their negations), I sorted them from highest absolute value to lowest absolute value. Let's say the largest value has a net gain of $$$2^z$$$. I consult the map to see if anybody else wanted to give $$$2^{z + 1}$$$ candies. If yes, then choose option A, i.e., receive the $$$2^{z + 1}$$$ and give $$$2^z$$$. If there is no such person, then choose option B, i.e., receive $$$2^z$$$ only and give nothing. The case of net gain $$$-2^z$$$ is handled similarly. In any case, we update the map and move on to the next value.

Correctness: The sorted descending order is crucial. When we process the value with net gain $$$2^z$$$, if there really is some value that wants to give $$$2^{z + 1}$$$ candies, then the only valid recipients are those with net gain $$$2^z$$$, since the remaining values afterwards would have smaller powers of 2, and cannot receive $$$2^{z + 1}$$$ candies. So option A is always valid in such a scenario.

But what about the scenario where we process a value with net gain $$$2^z$$$ and nobody wants to give $$$2^{z + 1}$$$ candies? Sometimes, option A might be valid here, i.e., receive $$$2^{z + 1}$$$ and give $$$2^z$$$, but this requires that there is a $$$-2^z$$$ value later on who will also choose option A, i.e., give $$$2^{z + 1}$$$ candies, but such a value would also have to receive $$$2^z$$$ candies, so these two people can simply swap with each other only. This is equivalent to both people choosing option B. Therefore, choosing option B is always guaranteed to work in this scenario (whereas option A would fail if there is no $$$-2^z$$$ later).

Hard Submission: 222851644 (still has the artifacts from Easy)

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

No matter what I do, I can't find the bug in my problem 1C. This is the first time I am completely unable to understand where my mistake is, even though my code can't pass the sample. I'm confused because the first three examples passed and there were no issues with overflow or out of bound or anything when I submitted it to Codeforces. Please, can someone help me take a look? I've been working on it all day. 222871376

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

Thanks for the great contest!

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

I posted a video editorial of problem C from Div. 2, I hope you enjoy it and find it interesting.

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

D2 is great

»
13 months ago, # |
  Vote: I like it +6 Vote: I do not like it

thanks for clear editorial ^^;

Nice E

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

dX ain't so happy 'bout problem D&F... felt it's actually okay:)

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

B2's tutorial needs a fix. Should be $$$a_i + 2^{x_i}$$$

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

老子真草了,题出这么难干什么啊?

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

写题解不写完整是吧,证明留给读者,我真艹了你*了

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

这D2的代码和题解真的弄的是一道题?后面的公式全是错的,真的,不想写可以不写的

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

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

Would anyone like to help me find any logical errors in my code for 1868C?

Here is my code: https://mirror.codeforces.com/contest/1868/submission/230789950

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

You should say two distinct indices l and r. other ways when n is odd, cout<<1<<" "<<n-1<<endl;; cout<<1<<" "<<n-1<<endl;; cout<<n<<" "<<n<<endl; cout<<n<<" "<<n<<endl; is also true. 231544042

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

im not able to understand make it zero question please help

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

The code in Editorial getting wrong result for the first test case in Make it zero problem.

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

I don't get it, why is it in problem A "make it zero" that when we take the xor operation twice for even values of "r-l+1" do we get zero no matter what the values x1,x2,x3... are?

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

    Let's assume the size of the array is even and the values are x1,x2,x3,x4,x5,x6 When we take xor of all these values some y would be calculated then replace all entries in the array from x1 to x6 with y Now the array would be y,y,y,y,y,y as the xor of two same numbers is zero, take xor you will get 0.

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

in div1 B1 n=4 [8,16,13,12] how is this yes?