nifeshe's blog

By nifeshe, 15 months ago, In English
Rating predictions

2056A - Shape Perimeter

Hints
Solution
Code

2056B - Find the Permutation

Hints
Solution
Code

2056C - Palindromic Subsequences

Hints
Solution
Code

2056D - Unique Median

Hints
Solution
Code

2056E - Nested Segments

Hints
Solution
Code

2056F1 - Xor of Median (Easy Version), 2056F2 - Xor of Median (Hard Version)

Hints
Solution
F1 code
F2 code
  • Vote: I like it
  • +96
  • Vote: I do not like it

| Write comment?
»
15 months ago, hide # |
 
Vote: I like it +29 Vote: I do not like it

i feel so dumb after seeing B's solution because I used topological sort and then sorted all the elements with equal entry times in descending order

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

    same mistake tho. In the hindsight B is actually a great problem with multiple solutions.

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

    Here is another way to solve B -> We will construct the array by traverse each string and with each traversal we will get value at one index. permutation numbers : i = 1, 2, 3, ... Lets take i = 3. Now to find where we will place 3 in our array we simply traverse the third string and count the number of '1's before 3rd index in that string and number of '0's after third index. That gives us the index at which 3 will come. Why this works? Think Yourself gg:)

    Code

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

    did gpt tell u that

  • »
    »
    15 months ago, hide # ^ |
     
    Vote: I like it +5 Vote: I do not like it

    an easy solution that i came up with is start placing elements in increasing order. For each element $$$i$$$, count the number of connections $$$j$$$ such that $$$j \gt i$$$. for example $$$i=1$$$ , and it's connected to $$$j=3$$$ and $$$j=5$$$, so $$$count=2$$$ start from the back of the array to find the second empty position and place $$$1$$$ there. here is my submission https://mirror.codeforces.com/contest/2056/submission/301478898

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

      Hey, i thought of an almost same solution but there is something that i am getting wrong. I implemented it by checking for each index in increasing order, the place from the back of array where it should be placed based on the count, say j. But if index j has some value already placed there, keep checking if any index k, (k=j-1;k>=0;k--) is empty and place the number there. Basically, How to process when the count that we calculate is same for 2 different numbers??

      here is my submission,301471228

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

        What ur doing there is partially correct. Here is an example where it will fail

        3
        000
        001
        010
        

        this should output 2,3,1 but your code would yiled 3,2,1

        the problem is that, for example count(2) = 1, in my code it means "I need at least 1 zero after me" , but your code says "go to second position from the back and find me the first empty slot" replace your loop with this and i think it should work

                // get next available slot by having at least 'c' zeros
                ll j = n - 1;
                for(j=n-1;j>=0 && c;j--)
                    if(ans[j]==0) c--;
                // if slot is full, skip it
                while(j>=0 && ans[j]!=0)--j;
                ans[j] = i+1;
        
  • »
    »
    15 months ago, hide # ^ |
     
    Vote: I like it 0 Vote: I do not like it

    Exact same mistake, but I rewrote a recursive solution after the contest ended (something similar to Quick Sort I'd say).

    submission

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

    This is my solution without sorting. 335753224

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

    why does topo sort fail in B ?

»
15 months ago, hide # |
 
Vote: I like it +15 Vote: I do not like it

B killed me and C buried me :(

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

Why the B looks easy here:(.I've done converting the undirected graph in directed based on pi<pj and then i had applied topological sort .Feelin dumb man

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

How did every single person predict that B was lower rated than C? C was much easier IMO. I think we need more lower rated testers.

»
15 months ago, hide # |
 
Vote: I like it +17 Vote: I do not like it

C's solution can be put fairly simple:

Answer will be of the pattern:

[1, 1, 2, 3, 4, ..... ,n-2, 1]

then the max length f(a) is 3

and the count g(a) is: (n-2) + (n-3) = 2*n-5, which is greater than n for n >= 6.

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

    bro, you are fucking right

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

    Yes, it was somewhat obvious like this, but why the problem C is made like this...i thought we have to maximize this f(a). And that seems to be a problem...and idk.. plz share if anyone have idea how it gonna work in that case...

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

      if you maximize f(a) it will be equal to n like 1 1 1 1 1 1 1 1 1 you can insert 2 in between n is odd

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

        But maximizing f(a) like this doesn't guarantee to make g(a)>n and g(a) should always get 1 like this right? I meant maximizing f(a) while meeting the same conditions, like in sample 2 f(a) could be made 5 but as of now we solved it by keeping it as 3 only..!

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

          g(a) is no of palindromes with length==f(a) if you take f(a)=n then how will u find other palindrome of length n, g(a) will be always one and then for n>1 answer will be wrong as g(a) has to greater than n

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

          It turns out that we don't have to maximize f(a), which was what I thought first. It is just that f(a) is the length of the longest palindromic subsequence of the array you construct.

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

    yeah same approach :)

»
15 months ago, hide # |
 
Vote: I like it +52 Vote: I do not like it

The difficulty distribution of this match is simply a disaster.

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

Another solution for $$$C$$$ is for $$$n \gt 6$$$ construct the array $$$1,2,$$$ $$$[3...n - 2],$$$ $$$1,2$$$. Most elements will be part of two palindromes of length $$$3:$$$ $$$1,x,1$$$ and $$$2,x,2$$$. For $$$n = 6$$$ use the one in the example.

Edit: Nevermind I just realized this was mentioned in the editorial.

»
15 months ago, hide # |
 
Vote: I like it +1 Vote: I do not like it

In C, If you realise that g(a) is 3n-11 for 6, and notice that 11 is a constant, and for each additional n, it will increase by 3, you notice that using the first construction directly solves the problem.

1,1,2...1,2 works because it follows 3n-11.

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

It seems like i completely overcomplicated D, because i solved it in $$$O(nA^2 + A^4)$$$.

»
15 months ago, hide # |
 
Vote: I like it +12 Vote: I do not like it

For C, I just took sample solution with 15, it already gives 190 and just pushed numbers in the end like 16 17 18 ... n.

The same way, for 15 > n >= 9 I took sample solution for 9, as it gives 24.

For 6 they already gave answer.

So I only needed to solve by hand 7, 8, which I did on paper.

  • »
    »
    15 months ago, hide # ^ |
     
    Vote: I like it +5 Vote: I do not like it

    for 7, 8, you can also just assume adding 4 in the middle of the array for 6 will give at least 1 new palindrome, and adding a 5 after that will give at least 1 more palindrome, and you're guaranteed to not create a longer one

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

why lasts codeforces rounds are random ? rarely to find topics .. number Theory or graphs in first 3 problems ?!! can any one explain

»
15 months ago, hide # |
 
Vote: I like it +5 Vote: I do not like it

What's with the constraint of n in C? Why is it so small?

Also you can just put random distinct numbers at the end of the 3rd sample answer, as g(a)=190 which is >=100

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

Tried sort in B and failed, using another 30 min to ponder another graph solution (almost like dijkstra)... absolutely overkill for B.

Learned, though C is really too easy for some reason.

Still I conclude C << B.

»
15 months ago, hide # |
 
Vote: I like it +21 Vote: I do not like it

A different way to approach D:(Probably easier?)

Solution :

Solution

My submission

Hope you understand the solution, if you have any queries feel free to ask, and I'll try to help if possible.

  • »
    »
    15 months ago, hide # ^ |
     
    Vote: I like it +7 Vote: I do not like it

    I did this approach but for "good" subarrays and ended up with the subproblem:

    Given two arrays, Count all pairs i<j such that a[i] < a[j] and b[i]<b[j].

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

      The problem can be solved with CDQ D&C, however the time complexity is $$$O(An \log^2n)$$$

      I don't know what exactly your $$$a$$$ and $$$b$$$ is. But in my case, I found out that if i < j, then a[i] > a[j] and b[i] > b[j] can't happen at the same time. So the problem become "Count all pairs i,j such that a[i] < a[j] and b[i]<b[j]" and can be solved $$$O(An \log n)$$$ using BIT.

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

        Could you elaborate on your method? I first considered a fixed median x. Next, I defined ps[i] to be the prefix sum of the number of elements less than x (up to and including index i). I did this also for the number of elements greater than x.

        Now the condition I got was finding all pairs i<j such that ps'[j]<ps'[i] for both types of prefix sums where ps'[i] = ps[i]-i/2. Not sure where to go from here since it seems like a 2D inversion count problem.

        If possible, could you define what arrays a and b you got and show how to implement it with one BIT.

        • »
          »
          »
          »
          »
          15 months ago, hide # ^ |
           
          Vote: I like it +8 Vote: I do not like it

          Let's call the prefix sum of the number of elements <=x $$$ps1_i$$$, and for >=x, let's call it $$$ps2_i$$$.

          For a subarray $$$a_{i+1},...,a_{j-1},a_j$$$ (tha a in the problem statement) to be good and have a median x, $$$ps1_j-ps1_i, ps2_j-ps2_i \gt = \frac{j-i+1}{2}$$$ need to be satisfied.

          So we can define $$$A_i$$$ as $$$2ps1_i-i$$$ and $$$B_i$$$ as $$$2ps2_i-i$$$, and the problem becomes a 3D inversion count problem (count i<j, A_j<A_j, B_i<B_j). However, (i<j, A_i>A_j, B_i>B_j) can't happen because that means $$$ps1_j-ps1_i, ps2_j-ps2_i \lt \frac{j-i+1}{2}$$$ which contradict to the fact $$$ps1_j-ps1_i+ ps2_j-ps2_i \gt = j-i$$$. (equal happens when there is no x in the subarray)

          So i<j isn't necessary, and the problem becomes a 2D inversion count problem.

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

          301616593

          Of course not optimal for this task, but was curious to try.

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

Very nice problem F!(however probably too hard for div2)

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

    I think someone new to CP with strong math olympiad background can reasonably solve F1. And yeah, F2 is there to entertain out of contest reds even if it's not too much harder than F1 given enough CP experience

»
15 months ago, hide # |
 
Vote: I like it +4 Vote: I do not like it

I don’t understand the editorial for D. For even length subarrays, when we are testing for x as the median, the bad scenarios seems a lot more than what the editorial depicts.

For instance, if we are testing for 9, the array 1 1 1 9 is certainly bad, but the number of numbers less than or equal to 9 is 4, not 2 as in the editorial .

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

    However, the sum of the array [1,1,1,9] is not 0, it is -4. You only count arrays where sum is 0 and the number appears at least once.

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

    Let's name the [(r-l+1)/2]-th element X and [(r-l+1)/2 + 1]-th element Y.

    A bad array has X!=Y.

    The editorial enumerate the X from 1 to 10, and count the above bad array when X is enumerated as the [(r-l+1)/2]-th element.

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

Why we only update the cnt array when a[i] equal to chosen digit? I may think that when the conditieon is enough when we firstly seen the digit x? Like: n = 6, a = {1, 4, 4, 3, 1, 4} with chosen digit = 3. It only update when we at index 4 (a[4] = 3), so that we have {1, 3, 4, 4}. But there are also in the index 6, we can have an bad array {1, 1, 3, 4, 4, 4}, but in this case the author not update the cnt array.

Code:

if(a[i] == x) {
  while(j <= i) {
    cnt[pref[j]]++;
    j++;
  }
}
»
15 months ago, hide # |
Rev. 3  
Vote: I like it +3 Vote: I do not like it

The constraints in the question C were kind of redundant because, I solved directly from visible cases. The answer for n=15 the third case they have given is 198, so I directly gave the same array as output for n>=15 followed by 16, 17, 18... until the required length is achieved. And for n=9 => the answer was 24, so 9-15 range is also sorted. So, only ones remaining are 7,8, we can manually generate that by appending some numbers after the given array for n=6.

»
15 months ago, hide # |
 
Vote: I like it +4 Vote: I do not like it

In the solution of D, it's a little confused by using the term "median". It took me some time to realize "median" means the (r-l+1)/2-th smallest number here.

Also, this intended solution is interesting since the observation is apparent but useful, and it seems that only few contestants came up with it.

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

I did very dumb solution for C.

For n = [6...11] find answer by hand.

For example, I realized that the prefix of "AABCABCDCDD" where different characters stands for different number gives correct answer, and I used it. As you see, we just need 4 different numbers.

Now, divide n to small parts: many 6 and one x from range [6...11]. Solve for small parts separately, with different set of numbers. Then concatenate them to one big array. It's not hard to see it will give you correct answer.

My submission.

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

E is solvable with xor hashing as well: 301474893

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

in problem C 1 1 2 3 4 5 ... 1 the maximum f(a) is 3 the first and the last one will add n-2 and the second and last one will add n-3 so 2*n -5 it worked for n>=6

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

We can even solve D by counting the good subarrays for every fixed median and sum them up.

Here is my submission.

https://mirror.codeforces.com/contest/2056/submission/301477712

»
15 months ago, hide # |
Rev. 2  
Vote: I like it -7 Vote: I do not like it

5 00000 00010 00000 01000 00000 for this input jiangly's solution gives 5 3 4 2 1 while solution in editorial gives 5 4 3 2 1 and both solutions get accepted how is 'p' unique then for this case

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

    This is an invalid input as the question mentions that there exists a valid permutation for each test case. No permutation exists for your set of input, as there is an edge between 2 and 4 but no edge between 2 and 3 or 3 and 4. (no place can be determined for 3 here, as if 3 is after 2 then there should be an edge between 2 and 3 or if 3 is before 4 then there should be an edge between 3 and 4)

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

      Isn't the wording for the question stating that, "It can be proven that permutation p can be uniquely determined " is wrong as it clearly states that we can prove , but fails for given testcase

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

        It is guaranteed that there exists a permutation p which generates the given graph.

        This is what the question guarantees. You can't just create any random testcase and say that the permutation is not unique by making two permutations for the test case. In case you do so, the permutations would be wrong i.e. the permutations would generate a different graph than the one in the input. The testcase which As1236 mentioned is invalid, the two different permutations formed by the editorial's code and jiangly's code are both wrong (infact there doesn't exist any permutation that would generate this particular graph) as in in the first permutation "5 3 4 2 1" there should be an edge between 3 and 4 according to the permutation but in the given graph this does not follow, and for the second permutation "5 4 3 2 1" is wrong because there is no edge between 2 and 4 according to the permutation but in the given graph there is an edge between 2 and 4.

»
15 months ago, hide # |
 
Vote: I like it +4 Vote: I do not like it

Thanks for highlighting the unusual limits.

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

How to solve the C with Binary Search?

Thanks in advance!

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

    Waa... Why the downvotes? A few hours ago, I saw the BS tag and, out of curiosity, I asked. :(( Now the tag has changed, though. :(

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

From F:

For a fixed $$$\text{cnt}$$$, the number of ways to order a is $$$\binom{n}{\text{cnt}_0, \text{cnt}_1, \ldots, \text{cnt}_{m - 1}}$$$. By Lucas's theorem the contribution is odd iff for each set bit in n there is exactly one i such that $$$\text{cnt}_i$$$ has this bit set, and $$$\sum\limits_{i = 0}^{m - 1} \text{cnt}_i = n$$$. In other words, $$$\text{cnt}$$$ has to partition all set bits in $$$n$$$.

Can someone explain this more in detail? I can't connect the dots between Lucas's theorem and this formula.

  • »
    »
    15 months ago, hide # ^ |
     
    Vote: I like it +5 Vote: I do not like it

    $$$\binom{n}{\text{cnt}_0, \ldots, \text{cnt}_{m - 1}} = \binom{n}{\text{cnt}_0} \cdot \binom{n - \text{cnt}_0}{\text{cnt}_1} \cdot \binom{n - \text{cnt}_0 - \text{cnt}_1}{\text{cnt}_2} \cdot \ldots$$$

    So $$$\text{cnt}_0$$$ has to be a submask of $$$n$$$, $$$\text{cnt}_1$$$ has to be a submask of $$$n - \text{cnt}_0$$$, etc.

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

    By Luca's theorem we know $$$\binom{n}{k} \equiv 1 \pmod{2} \Leftrightarrow k$$$ contains subset of bits of $$$n$$$ in binary notation.

    Also we have $$$\binom{n}{cnt_0, cnt_1, \ldots, cnt_{m-1}} = \binom{cnt_0}{cnt_0} \cdot \binom{cnt_0 + cnt_1}{cnt_1} \cdot \binom{cnt_0 + cnt_1 + cnt_2}{cnt_2} \cdot \binom{cnt_0 + cnt_1 + cnt_2 + cnt_3}{cnt_3}\dots \cdot \binom{n}{cnt_{m - 1}}$$$, to make lhs an odd number, terms on rhs should all be odd numbers. Consider the last term $$$\binom{n}{cnt_{m-1}}$$$, $$$cnt_{m-1}$$$ should contains subset of bits of $$$n$$$, then consider the previous term before it $$$\binom{n-cnt_{m-1}}{cnt_{m-2}}$$$, $$$cnt_{m-2}$$$ should contains subset of bits of $$$n-cnt_{m-1}$$$ which is exactly bits in $$$n$$$ but not in $$$cnt_{m-1}$$$, then consider previous terms and so on.

    This process is essentially deleting bits from $$$n$$$ and distribute them to $$$cnt$$$, then it become quite intuitive that the above claim is true.

»
15 months ago, hide # |
 
Vote: I like it +1 Vote: I do not like it

you don't have to consider n = 6 / 9 /15 separately.

1 ,1 ,3 ,4 ,5 ,... ,n-1 ,1

has f(a) = 3

and 2*(n-3) + 1 = 2n-5 palindromes! so g(a) > n for n >= 6 which fits the constraints

301414951

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

For D, I was like with a median of x: |the number of elements larger than x — the number of elements smaller x|<|the number of element of x in the sequence|. And I cannot find a good algorithm. It was too counterintutive for me to count "bad subarrays".

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

i think i have a better solution for c, i hope you'll like it :D it only require hardcoding for n=6 i just messed it up during the contest in second for loop where i started it from n/2 and not n/2+1

anyways good contest ~~~~~~~~~~~~ //this is code

include <bits/stdc++.h>

using namespace std;

define fio ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL)

define ll long long

void solve() { int n; cin>>n; vectortemp={1 ,1 ,2 ,3 ,1 ,2}; if(n==6){ for(auto it:temp){ cout<<it<<" "; } cout<<endl; return; } vectorarr(n); int j=1; for(int i=0;i<=n/2;i++){ arr[i]=j; j++; } j=1; for(int i=n/2+1;i<n;i++){ arr[i]=j; j++; } for(auto it:arr){ cout<<it<<" "; } cout<<endl;

}

int main() { fio; ll t; cin >> t; while (t--) { solve(); } return 0; } //this is code ~~~~~~~~~~

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

I solved C differently. In sequence [1,2,3,…,n] I changed a[⌊(n+1)/2⌋]=1 and a[n]=1, so in this new sequence f(a)=3 and g(a)=n-3+n-2=2n-5 which is enough for n≥6. Here's my solution 301421526

»
15 months ago, hide # |
 
Vote: I like it +1 Vote: I do not like it

for c just create sequence such that length of longest palindrome is 3 , putting 1 ....1 1 here all elements in between create 3 length palindrome now we have (n-2) palindromes ready now do it with 2 it will always exceed n>

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

geeked on b

»
15 months ago, hide # |
 
Vote: I like it -8 Vote: I do not like it

I am too dumb for Smart contests.

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

I did so dumb for C.I never think that f(a) can be 3 for any input,I can't solve constructive problems:(

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

the wording of B's problem statement is extremely confusing, especially when the notes switch back and forth between i, j, pi, and pj

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

another correct solution for C was to print 1 1 2 3 1 2 3 1 2 3... didnt know that it worked lmao

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

    I also solve it like this,and I have a proof in Chinese...If you want to see,there is the link.Maybe there are some mistakes.

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

    Then I translate it into English (forgive me if my English is poor).

    We consider a sequence whick looks like $$$1123123\cdots1$$$ (it is ended with $$$1$$$). Let $$$3k+2$$$ be the length of it (k is a positive integer), so it has $$$k+2$$$ 1s.

    If $$$k+2$$$ is odd:

    It is easily to find that $$$f(a)=k+2$$$.

    Then we can calculate the number (isn't all context):

    $$$111...1...111$$$: $$$1$$$

    $$$111...2...111$$$: $$$2k$$$

    $$$111...3...111$$$: $$$2k$$$

    It has already been $$$4k+1$$$ now!

    If $$$k \gt 3$$$, it has already been more than $$$3k+2$$$ (even $$$3k+4$$$).

    else, you can calculate by hand.

    else:

    $$$f(a)=k+3$$$

    And $$$111...2/3...111$$$ has $$$2$$$ available.

    We exchange the pairs of $$$2$$$ (or the pairs of $$$3$$$) and the pairs of $$$1$$$, it has already been $$$2*2^{\frac{k}{2}}$$$! And it is big enough.

    Q.E.D

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

nice problem!but i think E is too simple

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

This is best contest for me. I became expert in it.

»
15 months ago, hide # |
Rev. 10  
Vote: I like it 0 Vote: I do not like it

for F2, it is useless to calculate SOSDP and can be computed in a linear time using bitwise arithmetic.

$$$O(k\log m)$$$ reference code, available more discussion were easily optimised to linear time :D

  • »
    »
    15 months ago, hide # ^ |
    Rev. 5  
    Vote: I like it 0 Vote: I do not like it

    I can't see your submission, it says I'm not allowed to view the requested page. I'm unable to understand the SOS-DP part of the editorial. Can you explain your method? (edit: I saw your code can't and I couldn't understand it either, any help would be would be appreciated, thanks in advance.)

    • »
      »
      »
      15 months ago, hide # ^ |
      Rev. 6  
      Vote: I like it +3 Vote: I do not like it

      For $$$0\le x \lt m$$$, we write out the formula and it is:

      $$$ (\sum_{k=1}^n\sum_{i=1}^{k-1}C(x,i)C(m-x-1,k-1-i)\sum_{a_1+...+a_k=n,1\le a_1\le a_2\le ...\le a_k} [a_1+...+a_i \lt med][a_1+...+a_{i+1}\ge med]C(n,a_1,a_2,...,a_k))\mod 2 $$$

      Simplifying gives:

      $$$ \sum_{k=1}^nC(x,k-1)Stirling_2(popcount(n),k)\\ $$$

      Enumerate the values of $$$k$$$ and then compute the xor sum of all $$$x$$$ such that $$$0\le x \lt m$$$ and $$$k-1$$$ is a bitwise subset of $$$x$$$. Then enumerate the first different position to the left of $$$x$$$ and $$$k-1$$$ and the xor sum can be easily computed.

      The complexity is $$$O(\log n\log\log n)$$$. It can be optimised to $$$O(\log n)$$$ using bitwise operations to find the first, second and third 0 of $$$k-1$$$ to the right.

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

there is a easier way to solve problem B sunbmission

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

D's editorial just blew my mind , such an elegant solution !

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

for D, i fixed the median $$$x$$$ ,and tried to count the number of good subarrays whose median is exactly $$$x$$$.
however i failed.
so i wonder could someone give me a solution to forementioned subproblem

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

Hi, I have an issue with problem B.

For the input:

1
4
0110
1011
1100
0100

there are several solutions that got AC but produce different results. For example:

These are the top 4 solutions. First of all, this contradicts the problem statement, which says "It can be proven that permutation p can be uniquely determined". Secondly, none of these "permutations" seem to resemble the original graph.

So what's happening here? Can someone help me understand what is wrong?

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

    The input you gave is not correct. To understand this, we can model the undirected graph as a directed one with edges directed from $$$i \rightarrow j$$$ if $$$i \lt j$$$.

    Now since we have edges between $$$p_i \rightarrow p_j$$$ if $$$p_i \lt p_j$$$ and $$$i \lt j$$$, this setup ensures the transitivity of edges, ie having edges between $$$i \rightarrow j$$$ and $$$j \rightarrow k$$$ certianly implies we must have an edge between $$$i \rightarrow k$$$.

    Hence in your input, there must be an edge between $$$1$$$ and $$$4$$$.

    Input:

    1
    4
    0111
    1011
    1100
    1100
    

    Answer 1 2 4 3

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

      Thanks for your answer. I understand the fact that writing the graph in form of a permutation makes it require the transitivity of edges. But the problem statement doesn't really have any restriction related to this for the input graph. That's why I got confused.

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

        It is guaranteed that there exists a permutation $$$p$$$ which generates the given graph.

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

          Wow, I've read the statement atleast 5 times and only now I see this, thanks.

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

in sollution D line 8 (this shoulld be if instead of iff) "iff ∑i=lrbi=0" ."

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

For anyone who is stuck trying to understand the solution to D:

When it says "If there is no x in [l,r], then the median of a[l,r] trivially can't be equal to x.", it is refering to an even array where the "median" is the left part of the median. Meaning that we want to find an array where the left median is x and the right is not x (making it a bad array). We do not need to check for cases like [5, 7] when x == 6 because it is caught when x == 5, therefore we are only concerned with cases of b[l, r] == 0 when there contains x.

A side note: the solution doesn't need to check for when x == 10 since the b array would always be full of -1 since the bounds of a[i] are always less than or equal to 10.

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

How to solve problem d using dp ?

»
15 months ago, hide # |
 
Vote: I like it +14 Vote: I do not like it

Alternative solution to question C (using segment Tree):

#include <bits/stdc++.h>

using namespace std;

const int N = 105;

int t[4 * N];

void upd(int p, int x, int tl, int tr, int v) {
    if (tl + 1 == tr) {
        return void(t[v] = x);
    }
    int tm = tl + tr >> 1;
    if (p < tm) {
        upd(p, x, tl, tm, v * 2 + 1);
    } else {
        upd(p, x, tm, tr, v * 2 + 2);
    }
}

int get(int p, int tl, int tr, int v) {
    if (tl + 1 == tr) {
        return t[v];
    }
    int tm = tl + tr >> 1;
    if (p < tm) {
        return get(p, tl, tm, v * 2 + 1);
    } else {
        return get(p, tm, tr, v * 2 + 2);
    }
}

signed main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    int tst;
    cin >> tst;
    while (tst--) {
        int n; cin >> n;
        upd(n - 1, 1, 0, n, 0);
        upd(n - 2, 1, 0, n, 0);
        for (int i = 0; i < n - 2; ++i) {
            upd(i, i + 1, 0, n, 0);
        }
        for (int i = 0; i < n; ++i) {
            cout << get(i, 0, n, 0) << " ";
        }
        cout << "\n";
    }
    return 0;
}
»
12 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

Great problems!!

I actually managed to solve my first RANDOM 1200