Блог пользователя ace5

Автор ace5, история, 2 года назад, По-русски

Привет, Codeforces!

Я и ooaa рады пригласить вас принять участие в Codeforces Round 922 (Div. 2), который состоится во Jan/30/2024 17:35 (Moscow time).

Этот раунд будет рейтинговым для участников, чей рейтинг ниже 2100. Участники с более высоким рейтингом могут принять участие вне конкурса.

Вам будет предложено 7-8 задач и 2 часа на их решение. Мы советуем вам прочитать все задачи. В раунде может встретиться 1 или более интерактивных задач. Рекомендуем прочитать этот пост.

Мы хотим поблагодарить:

Всем удачи на раунде и высокого рейтинга!

UPD. Разбалловка: $$$500 - 1000 - 1250 - 2000 - 2500 - 3000 - 3250$$$.

UPD2. Поздравляем победителей!

Div. 2

  1. alice_ssoi

  2. JaredGoff

  3. ppltn

  4. sunc_mgu_govno

  5. 1926_yes

Div. 1+2

  1. arvindf232

  2. SSerxhs

  3. alice_ssoi

  4. natofp

  5. JaredGoff

Поздравляем участников, заславших первые решения по каждой задаче:

UPD3. Разбор.

  • Проголосовать: нравится
  • +575
  • Проголосовать: не нравится

»
2 года назад, скрыть # |
 
Проголосовать: нравится +114 Проголосовать: не нравится

As a tester, it's the first time I tested an actual Codeforces round!

»
2 года назад, скрыть # |
 
Проголосовать: нравится +43 Проголосовать: не нравится

As a tester,the problemset is incredible!Hope you enjoy it :)

»
2 года назад, скрыть # |
 
Проголосовать: нравится +19 Проголосовать: не нравится

As a tester, it’s my first round that I tested, good luck to everyone!

»
2 года назад, скрыть # |
Rev. 2  
Проголосовать: нравится +5 Проголосовать: не нравится

As a tester, it is very good round! Good luck!

»
2 года назад, скрыть # |
 
Проголосовать: нравится +10 Проголосовать: не нравится

Lets goooo , its time i become pupil

»
2 года назад, скрыть # |
 
Проголосовать: нравится +19 Проголосовать: не нравится

I loved testing the round, problems are of high quality. Good luck!

»
2 года назад, скрыть # |
 
Проголосовать: нравится -30 Проголосовать: не нравится

5-6 or 7-8 tasks

»
2 года назад, скрыть # |
 
Проголосовать: нравится +5 Проголосовать: не нравится

Score Distribution??

»
2 года назад, скрыть # |
Rev. 3  
Проголосовать: нравится +10 Проголосовать: не нравится

Score Distribution?? Edit : Very Balanced Score Distribution according to toughness..

»
2 года назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

Hoping to stay cyan

»
2 года назад, скрыть # |
 
Проголосовать: нравится -8 Проголосовать: не нравится

As a tester, I hope you enjoy the round as much as I did.

»
2 года назад, скрыть # |
 
Проголосовать: нравится -8 Проголосовать: не нравится

As not tester, idk

»
2 года назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

As a tester, the problems are very good. I encourage you do participate in the round!

»
2 года назад, скрыть # |
Rev. 2  
Проголосовать: нравится +4 Проголосовать: не нравится

2 hours and 7 tasks :O

»
2 года назад, скрыть # |
 
Проголосовать: нравится -8 Проголосовать: не нравится

How to reach Expert?

»
2 года назад, скрыть # |
 
Проголосовать: нравится -8 Проголосовать: не нравится

How to reach expert ?

»
2 года назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

53 points to Master. Hope to be a master tonight!

»
2 года назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

53 points to master. Hope to be a master tonight!

»
2 года назад, скрыть # |
 
Проголосовать: нравится +6 Проголосовать: не нравится

As a tester, good luck to everyone! It's the first time i tested a round.

»
2 года назад, скрыть # |
 
Проголосовать: нравится +1 Проголосовать: не нравится

Score distribution?

»
2 года назад, скрыть # |
 
Проголосовать: нравится -6 Проголосовать: не нравится

Hopefully I move to green this time! Excited for this round! Btw which rating should I be to become a problem setter / tester?

»
2 года назад, скрыть # |
 
Проголосовать: нравится +13 Проголосовать: не нравится

What will be the score distribution?

»
2 года назад, скрыть # |
 
Проголосовать: нравится +9 Проголосовать: не нравится

waiting for that tree based div 2 D since forever

»
2 года назад, скрыть # |
 
Проголосовать: нравится +21 Проголосовать: не нравится

Knowing Anton, I will be very surprised to see a segment tree in any of his problems

»
2 года назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

Lost 50 pt in previous div2. Hope to recover

»
2 года назад, скрыть # |
 
Проголосовать: нравится +13 Проголосовать: не нравится

are the round writers siblings?

»
2 года назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

All the best guys! Hoping to reach 1300 today.

»
2 года назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

ace5 will the score distribution be announced?

»
2 года назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

hope to become CM in this contest. Now only 72 rating.

»
2 года назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

As a participant, I hope I can get non negative delta again.

»
2 года назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

Hope not to drop down to pupil, spec is fine

»
2 года назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

GLHF

»
2 года назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

they write to read about interactive problems but dont give any, hope to see one today (ofc i wont be able to solve it)

»
2 года назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

good luck!

»
2 года назад, скрыть # |
 
Проголосовать: нравится +16 Проголосовать: не нравится

Is D that easy? 1000+ solves and I am not able to figure out from where to begin? :(

»
2 года назад, скрыть # |
Rev. 6  
Проголосовать: нравится +1 Проголосовать: не нравится

I have no idea how to start thinking about D!

Binary search? NO

Two Pointers? NO

DP? NO

Gready? NO

Graphs? NO

Range queries? NO

Math? NO

  • »
    »
    2 года назад, скрыть # ^ |
     
    Проголосовать: нравится +8 Проголосовать: не нравится

    What is going through your head??? Why are you discussing problems before the end of the contest???

  • »
    »
    2 года назад, скрыть # ^ |
     
    Проголосовать: нравится +27 Проголосовать: не нравится

    The funniest thing is that D is actually binary search with dp (not sure about the intended solution, but I've solved it this way)

    • »
      »
      »
      2 года назад, скрыть # ^ |
       
      Проголосовать: нравится +1 Проголосовать: не нравится

      I also solved it that way.

    • »
      »
      »
      2 года назад, скрыть # ^ |
      Rev. 2  
      Проголосовать: нравится +1 Проголосовать: не нравится

      Binary search on answer?

      If so how to check if If the cost can be less than or equal to x? I was stuck at this point

      • »
        »
        »
        »
        2 года назад, скрыть # ^ |
         
        Проголосовать: нравится 0 Проголосовать: не нравится

        DP, DP[i] is the minimum sum of blocked elements such that you covered all elements from 1 to i, i used segment tree to query minimums.

      • »
        »
        »
        »
        2 года назад, скрыть # ^ |
         
        Проголосовать: нравится +1 Проголосовать: не нравится

        Binary search the max sum of the segments. The best answer happens when the max of all segments is close to the sum of blocked elements.

      • »
        »
        »
        »
        2 года назад, скрыть # ^ |
         
        Проголосовать: нравится 0 Проголосовать: не нравится

        Let's suppose we want to check, is it possible to make $$$cost \le x$$$.
        We must erase some elements such that all remaining subarrays have $$$sum \lt = x$$$, and the sum of erased elements must be $$$\le x$$$.
        So, we calculate $$$dp[i]$$$ = minimal sum of erased elements such that there is no range with $$$sum \gt x$$$ in $$$a[0..i]$$$. Then, $$$cost \le x \leftrightarrow dp[n - 1] \le x$$$.

        • »
          »
          »
          »
          »
          2 года назад, скрыть # ^ |
           
          Проголосовать: нравится +3 Проголосовать: не нравится

          can you also explain how you are finding the value of dp[i]?

          • »
            »
            »
            »
            »
            »
            2 года назад, скрыть # ^ |
            Rev. 2  
            Проголосовать: нравится +1 Проголосовать: не нравится

            My solution is a bit complicated (i believe there is a simpler one), but here it is:

            First, if $$$x \lt max(a)$$$, there is no solution.

            Let's define $$$dp[i][0]$$$ same as $$$dp[i]$$$ above, but with additional constraint: $$$a[i]$$$ is erased. $$$dp[i][1]$$$ is essentialy the opposite: $$$a[i]$$$ is not erased.

            Base cases are: $$$dp[0][0] = a[0], dp[0][1] = 0$$$.
            We calculate $$$dp[i][0]$$$ just as $$$min(dp[i - 1][0], dp[i - 1][1]) + a[i]$$$, since when we erase $$$a[i]$$$, we don't care about the range which ends before, we just know that it's sum $$$\le x$$$.

            Finding $$$dp[i][1]$$$ is another task. We have the following relation:
            $$$ dp[i][1] = min_{j} dp[j][0]$$$, where $$$j \lt i$$$ and $$$\sum_{k=j+1}^{i} a_i \le x$$$, since if we don't erase $$$a[i]$$$, it must be the end of a certain range (e.g. the entire range $$$[j + 1..i]$$$, because it's sum is less or equal than $$$x$$$).

            The least suitable $$$j$$$ can be maintained during dp calculation with two pointers, and the desired value is just segment minimum of $$$dp[j][0]$$$, which can be found with segment tree (or minimum queue). The complexity of calculating such dp is clearly $$$O(n)$$$ or $$$O(n \log n)$$$, depending on data structure you use.

            Code: 244130581

            • »
              »
              »
              »
              »
              »
              »
              2 года назад, скрыть # ^ |
               
              Проголосовать: нравится +3 Проголосовать: не нравится

              Got it. THanks for the explanation.

              • »
                »
                »
                »
                »
                »
                »
                »
                2 года назад, скрыть # ^ |
                Rev. 2  
                Проголосовать: нравится 0 Проголосовать: не нравится

                why in transition state of dp[i][1] no contribution of dp[j][1]?

                and i did not understand why a[i] must be end of certain range , plz explain this also

                as if a[i] is end element of some segment , then a[i+1] must be blocked element , how we assume this

                are_you_tilted

                • »
                  »
                  »
                  »
                  »
                  »
                  »
                  »
                  »
                  2 года назад, скрыть # ^ |
                  Rev. 2  
                  Проголосовать: нравится 0 Проголосовать: не нравится

                  When we calculate $$$dp[i]$$$, we consider only the prefix of $$$a$$$, which ends in $$$a[i]$$$. That's why in $$$dp[i][1]$$$ there's always a range which ends in $$$a[i]$$$ (because it's the last element so far, and it is not erased).

                  Why don't we use $$$dp[j][1]$$$? Consider any $$$j$$$ such that $$$\sum_{k=j+1}^{i} a[i]$$$ <= $$$x$$$. If we make transition from $$$dp[j][1]$$$, we continue a range which ends in $$$j$$$ now. But we actually don't know where this range starts, and we don't know, will it's sum be still less or equal than $$$x$$$ after continuing in up to the $$$i$$$.

                  For better understanding, consider the array $$$d$$$ built on a certain sequence of operations, where $$$d[i] = 0$$$ if we erased $$$i$$$th element, and $$$1$$$ otherwise.
                  For example, $$$d = [0, 1, 1, 0, 0, 1, 1]$$$. In terms of $$$d$$$, when we calculate $$$dp[i][1]$$$, we want to choose the start index of a consequtive segment of ones, end of which will be in $$$i$$$. That is, our current transition looks like "choose a zero $$$j$$$, then fill $$$d[j + 1..i]$$$ with ones — once we've created a range of ones, we don't extend it to the right. Maybe now it is more clear, why it suffices.

  • »
    »
    2 года назад, скрыть # ^ |
     
    Проголосовать: нравится 0 Проголосовать: не нравится

    The first three are actually YES. (And maybe 6th too, depending on your implementation)

»
2 года назад, скрыть # |
 
Проголосовать: нравится +2 Проголосовать: не нравится

Thanks a lot for this round! Problems are really interesting, especially E with it's idea of solution(just asking questions as in quicksort?).

  • »
    »
    2 года назад, скрыть # ^ |
     
    Проголосовать: нравится 0 Проголосовать: не нравится

    Can you explain your solution?

    • »
      »
      »
      2 года назад, скрыть # ^ |
       
      Проголосовать: нравится +2 Проголосовать: не нравится

      Let's understand comparing an element $$$a[i]$$$ to all others for ~$$$3n$$$ questions. first we will ask about this element $$$a[i]$$$ until $$$X$$$ is equal to a[i]. (this will happen since $$$X$$$ goes sideways each time to the number it is being compared to). Now we have $$$X = a[i]$$$. Now to compare $$$a[i]$$$ and $$$a[j]$$$ we just need to ask the question about $$$a[j]$$$ first. This is how we know the answer.($$$a[i] \gt a[j]$$$ or vice versa). And now ask about $$$a[i]$$$ again (to make $$$X$$$ equal to $$$a[i]$$$ again). We have learned how to compare this element with all the others. But this is the same as quick sorting!!! We are comparing an element and sorting all the smaller ones and all the bigger ones. the number of queries $$$~O(n log n)$$$ which hopefully will pass.

  • »
    »
    2 года назад, скрыть # ^ |
     
    Проголосовать: нравится 0 Проголосовать: не нравится

    I had thought of a solution, where LIS + LDS of a permutation has certain minimum lower bound. I had tried to implement with that logic, but timed-out.

»
2 года назад, скрыть # |
 
Проголосовать: нравится +6 Проголосовать: не нравится

Is D really this easy? or am I just dumb? 1k+ already solved. It's a recursion problem I know that but somehow not able to form the code ughhhhhhhh :D

»
2 года назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

Ternary search in D?

»
2 года назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

Guys why my this code is wrong for codeforces question 3 xor distance one

#include <bits/stdc++.h>
using namespace std;

#define ll long long

void solve()
{
    ll a, b, r;
    cin >> a >> b >> r;
    if (r == 0)
    {
        cout << abs(a - b) << endl;
        return;
    }

    vector<int> a1(64, 0), b1(64, 0);
    int greater = 0;
    for (int i = 0; i <=63; i++)
    {
        if ((a & (1LL << i)))
        {
            a1[i]++;
            greater = i;
        }
        if ((b & (1LL << i)))
        {
            b1[i]++;
            greater = i;
        }
    }

    ll min1 = LLONG_MAX;
    for (int i = 0; i <=greater+1; i++)
    {
        for (int j = 0; j <=greater+1; j++)
        {
            ll k = (1LL << i) + (1LL << j);
            ll o = (1LL << i);
            ll p = (1LL << j);
           

            if (k > r)
                break;
            min1 = min(min1, abs((a ^ k) - (b ^ k)));
            min1 = min(min1, abs((a ^ o) - (b ^ o)));
            min1 = min(min1, abs((a ^ p) - (b ^ p)));
            
        }
    }
    if (min1 == LLONG_MAX)
        min1 = 1;
    cout << min1 << endl;
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);

    ll t;
    cin >> t;
    while (t--)
        solve();

    return 0;
}
»
2 года назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

Do we use divide and conquer on E?

»
2 года назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

how C?

»
2 года назад, скрыть # |
Rev. 2  
Проголосовать: нравится 0 Проголосовать: не нравится

Oh god, I'm so lucky. I freakin stared at monitor looking for overflow errors in D, but couldn't find anything, since locally everything works ok. Decided to go ooga-booga mode and wrote #define int long long, and it freakin passed. After it passed I realized the error. No -Wconversion moment, shame on me

»
2 года назад, скрыть # |
 
Проголосовать: нравится +49 Проголосовать: не нравится

This is a cool contest with a cool problemset ☝☝☝☝

»
2 года назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

How C?

»
2 года назад, скрыть # |
Rev. 2  
Проголосовать: нравится 0 Проголосовать: не нравится

is C brute force?

from topbit(r) to 0, if we can flip current bit then copy it and compute abs(a^r — b^r) to determine bit should be flipped or not.

had 10 WA pretest2 still no clue

»
2 года назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

Can someone please explain, how to solve D?

how to manage the states, within the constraints

»
2 года назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

Man, I was struggling with C :( TLE or MLE was troubling me? Can anyone give the solution?

  • »
    »
    2 года назад, скрыть # ^ |
    Rev. 8  
    Проголосовать: нравится +1 Проголосовать: не нравится

    basic steps to solve C problem
    1 -> find maximum(mx) and minimum(mn) among a and b.
    2 -> ignore common bits because they didn't affect the answer.
    3 -> ignore the first missmatch bit of mx(1) and mn(0)
    4 -> traverse from MSB -> LSB whenever this condition reached that bit of mx is set and bit of mn is unset try to transfer this bit form mx to mn(if possible).

    lets take an example
    7 4 3
    7 -> 1 1 1
    4 -> 1 0 0
    ind-> 2 1 0
    mx = 7,mn = 4
    2nd bit -> ignore because both are same
    1st bit -> first time occur 1 in mx 0 in mn
    0th bit -> try to transfer this bit from mx to mn.

    how to transfer ?
    if (curr bit is set in mx and unset in mn) and we set this bit in x, then after xor with x, curr bit of mx will be unset and curr bit of mn will be set.
    so check whenever this(curr bit is set in mx and unset in mn) condition reach and after setting this bit in x if x <= r then set this bit otherwise ignore this and move on next bit.

»
2 года назад, скрыть # |
 
Проголосовать: нравится +15 Проголосовать: не нравится

Spent 1h+ on C because wrote 1<<i instead of 1ll<<i =(

The problems are really interesting!

»
2 года назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

B is similar to ARC149B, and I think they probably have somthing in common.

»
2 года назад, скрыть # |
 
Проголосовать: нравится +2 Проголосовать: не нравится

Today i solved 3 problems, and enjoy this contest, Thankyou

»
2 года назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

Can someone please explain, how to solve D?

how to manage the states, within the constraints

»
2 года назад, скрыть # |
 
Проголосовать: нравится -8 Проголосовать: не нравится

Oh bad I spent 1:10 and almost 100 lines of code C Why are solutions from my room so short...

»
2 года назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

Was the intended solution for F sth like: sort the sons for each node by greatest depth of node in its subtree, then do dfs in that order and maybe get the profit of jumping from each node on the trampoline when you traverse the tree in dfs order, and take the best profits? I did that without having an actual proof or something and got WA on test 27, but maybe I was missing something.

»
2 года назад, скрыть # |
 
Проголосовать: нравится +22 Проголосовать: не нравится

Please stop create monkey-problems like B

»
2 года назад, скрыть # |
 
Проголосовать: нравится +3 Проголосовать: не нравится

Can someone please tell me what's wrong in this submission for C? Spent over an hour but I couldn't find anything :( Submission

»
2 года назад, скрыть # |
Rev. 2  
Проголосовать: нравится +21 Проголосовать: не нравится

Thanks to preparing the contest! I enjoeyed A,B,C, and G That's how I solved G

Spoiler
»
2 года назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

I'm just curious. To solve G, I have worked out the cases when n is even. But when n is odd, I have completely no idea.

I wonder if we randomly choose numbers from {-3,-2,-1,1,2,3}, is is possible to "random" out a possible permutation?

»
2 года назад, скрыть # |
 
Проголосовать: нравится +3 Проголосовать: не нравится

did 1<<i instead of 1ll<<i :(

»
2 года назад, скрыть # |
 
Проголосовать: нравится +6 Проголосовать: не нравится

did 1<<i instead of 1ll << i :(

»
2 года назад, скрыть # |
 
Проголосовать: нравится -27 Проголосовать: не нравится

i hate bitmask problems a little bit

»
2 года назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

My solution for problem D

We will binary search on the answer. Let's call the currrent value we are deal with is X Let's call dp[i] : Consider position 1 to i, if we take element i, what will be the sum of blocked elements So : - dp[i] = dp[j] + a[i] - sum from j + 1 to i — 1 must be <= X. We can find the range of j by binary search and get the minimum value by segment tree simutanously. - The function check on binary search return true if there is exist an indice i such that : sum(i + 1, n) <= X && dp[i] <= x Hope it make sense

»
2 года назад, скрыть # |
Rev. 7  
Проголосовать: нравится +11 Проголосовать: не нравится

My solution for problem D

We will binary search on the answer. Let's call the currrent value we are dealing with is X Let's call dp[i] : Consider position 1 to i, if we take element i, what will be the sum of blocked elements. So :

dp[i] = min(dp[j] + a[i]) and sum from j + 1 to i — 1 must be <= X. We can find the range of j by binary search and get the minimum value by segment tree simutanously. The function check on binary search return true if there is exist an indice i such that : sum(i + 1, n) <= X && dp[i] <= x Hope it make sense

»
2 года назад, скрыть # |
 
Проголосовать: нравится -46 Проголосовать: не нравится

C is stolen from codechef just expanded the constraints https://www.codechef.com/problems/XORDIF

»
2 года назад, скрыть # |
 
Проголосовать: нравится +7 Проголосовать: не нравится

Did someone prove that in B we are getting the best number of inversions by just sorting one of the permutations? That is not that intuitive for me...

  • »
    »
    2 года назад, скрыть # ^ |
     
    Проголосовать: нравится +1 Проголосовать: не нравится

    Consider index $$$i, j$$$ If $$$a_i \lt a_j$$$ and $$$b_i \lt b_j$$$ or $$$a_i \gt a_j$$$ and $$$b_i \gt b_j$$$ , then eliminating inversion in $$$a$$$ eliminates inversion in $$$b$$$.

    If $$$a_i \lt a_j$$$ and $$$b_i \gt b_j$$$ then in any configuration you must have 1 inversion due to this pair, thus sorting will eliminate all the inversions pairs of type 1 and 1 inversion is anyway there in type 2 for any configuration

  • »
    »
    2 года назад, скрыть # ^ |
     
    Проголосовать: нравится 0 Проголосовать: не нравится

    Consider two indices, $$$i$$$ and $$$j$$$ and $$$i \lt j$$$.

    If the order is different in the arrays:

    • $$$a_i \lt a_j$$$ and $$$b_i \gt b_j$$$, or
    • $$$a_i \gt a_j$$$ and $$$b_i \lt b_j$$$

    this means if it becomes $$$i \gt j$$$ in the answer array, the sum of inversions will not change, because if the inversion disappears in a, it reappears in b and vice versa.

    However, if both of the arrays contain inversion with indices $$$i$$$ and $$$j$$$, meaning

    • $$$a_i \gt a_j$$$ and $$$b_i \gt b_j$$$

    Then if the indices $$$i$$$ and $$$j$$$ become somehow $$$i \gt j$$$ in the final array, sum of inversions will decrease by 2.

    If:

    • $$$a_i \lt a_j$$$ and $$$b_i \lt b_j$$$

    then their order should be preserved, in other words $$$i \lt j$$$ should hold after reordering.

    so we want to swap preserve all $$$ai \lt aj$$$ and remove as much $$$ai \gt aj$$$ as we can. because the array $$$b$$$ doesn't contribute anything (look at the cases). so the operation that accomplishes this is sorting.

  • »
    »
    2 года назад, скрыть # ^ |
     
    Проголосовать: нравится +16 Проголосовать: не нравится

    you can use bubble sort to understand. Consider what happens when you swap 2 consecutive numbers

  • »
    »
    2 года назад, скрыть # ^ |
     
    Проголосовать: нравится +14 Проголосовать: не нравится

    Consider optimal answer by score (number ov inversions in $$$a$$$ + number of inversions in $$$b$$$). If there are more than one optimal answers consider one with lexicographically smallest array $$$a$$$.

    $$$Claim:$$$ array $$$a$$$ will be sorted in such an answer.

    $$$Proof$$$ $$$by$$$ $$$contradiction:$$$ assume it's not. Then there is an index $$$i$$$ such that $$$a_i \gt a_{i+1}$$$. Let's make operation with $$$i$$$ and $$$i+1$$$, i.e $$$swap(a_i, a_{i+1})$$$ and $$$swap(b_i, b_{i+1})$$$. Number of inversions in array $$$a$$$ decreased by one after a swap, and number of inversions in array $$$b$$$ increased by no more than one, since $$$b_i, b_{i+1}$$$ is the only pair of elements whose relative order was changed in $$$b$$$. Therefore number of inversions in $$$a$$$ + $$$b$$$ $$$\bf{not}$$$ $$$\bf{increased}$$$ after a swap, but array $$$a$$$ became lexicographically smaller. But we chose array $$$a$$$ as lexicographically smallest $$$\to$$$ contradiction, array $$$a$$$ is sorted in optimal answer.

»
2 года назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

Can someone explain the statement of problem B, please?

»
2 года назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

Is there a non-random solution for E?

  • »
    »
    2 года назад, скрыть # ^ |
    Rev. 2  
    Проголосовать: нравится +32 Проголосовать: не нравится

    Yes — you can do parallel binary search to find all values in worst case $$$O(n \log n)$$$ queries. My code (244112756) is very messy and might FST; I have a proven, more efficient version that I haven't yet submitted and I'll clean up the code. I'll probably post a comment on the editorial about my solution with a proof of the number of queries.

  • »
    »
    2 года назад, скрыть # ^ |
     
    Проголосовать: нравится 0 Проголосовать: не нравится

    Firstly you can request X=1 (I think by 2n queries)

    Secondly supporse you have $$$k$$$ indices of consecutive numbers $$$L \ldots R$$$ ($$$R-L+1=k$$$). Find position of $$$m=(L+R)/2$$$ (likely it can be done by $$$O(R-L)$$$ queries). Then split indices to two groups and solve recursively.

    Start call from $$$L=1$$$, $$$R=n$$$, indices = $$$1 \ldots n$$$.

»
2 года назад, скрыть # |
 
Проголосовать: нравится +1 Проголосовать: не нравится

Where is the Editorial?

»
2 года назад, скрыть # |
 
Проголосовать: нравится +3 Проголосовать: не нравится

Is Carrot extension not working?

»
2 года назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

How to solve E?

»
2 года назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

My B solution uses just bubble sort, but I get TLE anyways. Could someone give me some hint?

»
2 года назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

I spent a lot of time on B. I think it's too difficult for people without prior knowledge like me. I don’t know how to prove the correctness of my ideas. ;(

»
2 года назад, скрыть # |
 
Проголосовать: нравится +22 Проголосовать: не нравится

My E solution got TLE for java. Had to use chat gpt to convert to c++. Time constraints too tight?

»
2 года назад, скрыть # |
 
Проголосовать: нравится +10 Проголосовать: не нравится

Is there a proof for randomised solution for E?

»
2 года назад, скрыть # |
 
Проголосовать: нравится +5 Проголосовать: не нравится

I think E is too tight. I got TLE. However, someone got AC using same idea (maybe just a different select point). too sad~.

  • »
    »
    2 года назад, скрыть # ^ |
     
    Проголосовать: нравится +8 Проголосовать: не нравится

    Looking at the output for the failed test, it seems that it was actually a WA due to exceeding the query limit, but since the program failed to handle the WA input and exit, it was judged a TLE.

»
2 года назад, скрыть # |
 
Проголосовать: нравится +3 Проголосовать: не нравится

Next contest coming in 3 weeks? Why is it taking so long? or am I missing something.

»
2 года назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

when can i submit after the contest

»
2 года назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

Can someone explain me why this is TLE ?Code

»
2 года назад, скрыть # |
 
Проголосовать: нравится +6 Проголосовать: не нравится

Top5 are always smurfs :)

»
2 года назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

Is there no hacking phase?

»
2 года назад, скрыть # |
 
Проголосовать: нравится +5 Проголосовать: не нравится

rating updates ?

»
2 года назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

"Submissions have been scheduled for rejudge on the next testset." This notification came after the system tests were over. What does this mean?

»
2 года назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

Can anyone explain the intuition behind why, for problem C, you need to avoid swapping the bits between a and b until the first time the bits differ?

  • »
    »
    2 года назад, скрыть # ^ |
     
    Проголосовать: нравится 0 Проголосовать: не нравится

    Because you don't accomplish anything by adding that bit in x. Example: a = 1, b = 1, a⊕0 — b⊕0 = a⊕1 — b⊕1.

    • »
      »
      »
      2 года назад, скрыть # ^ |
       
      Проголосовать: нравится 0 Проголосовать: не нравится

      @blaze Right, but I'm trying to figure out why this is the case. For the case of 9 and 6, for example, you can notice setting X to 1001 rather than 0001 (or just 1) ends up making it so that, if a > b before this, a < b afterward. I think this is the key insight, but I'm trying to figure out why this is only the case until the first bit differs.

      • »
        »
        »
        »
        2 года назад, скрыть # ^ |
         
        Проголосовать: нравится 0 Проголосовать: не нравится

        Don't look at the numbers a and b as "numbers", separate them bit by bit and look at them that way. You can assume that a > b because $$$|a \oplus x - b \oplus x| = |b \oplus x - a \oplus x|$$$. You don't want to toggle unnecessary bits in x so that it can be <= r. During subtraction of $$$a \oplus x - b \oplus x$$$ notice that the bits that are the same don't affect the result, xoring them with something won't make those bits different.

        • »
          »
          »
          »
          »
          2 года назад, скрыть # ^ |
           
          Проголосовать: нравится 0 Проголосовать: не нравится

          Thanks for the reply but I don't think we are talking about the same thing. I understand the bits that are the same between a and b should not have anything xor'd with them. But in correct solution, you skip not only the positions where a and b have the same bit, but also the first position where a and b's bits differ, even if that position has a 1 bit for a and a 0 bit for b. That is the part I am confused on.

          • »
            »
            »
            »
            »
            »
            2 года назад, скрыть # ^ |
             
            Проголосовать: нравится 0 Проголосовать: не нравится

            we skip first bit because if we swap the MSB, we would have to add that bit to our cost, i.e., r, instead we let it be as it is. best explained with an example:

            suppose these are two numbers in binary:

            110011 001010

            now, in this case we would avoid swapping the first bit because it alone costs 2^5, which would be higher than any cost we would incur to swap subsequent bits however we like. suppose r = 100000 (in binary) in this case.

            then, if had we swapped the first bit, we could not swap any further bit and new numbers would be 010011 and 101010

            notice the third bit from the left would have been better in first number but we don't have any r left but, if we did not swap the first bit, we could do anything later on in this case because r is sufficient.

            if any doubt ask me.

            • »
              »
              »
              »
              »
              »
              »
              2 года назад, скрыть # ^ |
               
              Проголосовать: нравится 0 Проголосовать: не нравится

              Thanks for your help! I understand if you swap the MSB it comprises the whole cost, but I'm having trouble understanding why this means we shouldn't use it. After all, it makes the biggest change in the numbers, and thus brings them closer together, right?

              However, here the correct X to use is 010001. If instead we used 100000, which is what you get if you don't skip the MSB, you end up subtracting too much from the bigger number and adding too much to the smaller number, which results in not getting an optimal solution.

              What I am trying to understand is, why is this only a problem for the MSB? Why do we always avoid swapping only for the MSB, but we can always do the swaps for any other bit?

              • »
                »
                »
                »
                »
                »
                »
                »
                2 года назад, скрыть # ^ |
                 
                Проголосовать: нравится 0 Проголосовать: не нравится

                Because Suppose n has msb, now the later bits, we are trying to push to m to make n-m as smaller as possible. As m increases and n-m decreases.

                we are greedily avoiding first msb in case a solution existed in which we could switch the first msb then later on we would get the best answer, suppose like this 2 numbers 1111, 0000 and r is 1000 in this case we can switch msb to get best answer but its clearly possible avoid msb and switch rest bits in lesser cost.

                Did i answer your question? If not, i dont think i understand your doubt

          • »
            »
            »
            »
            »
            »
            2 года назад, скрыть # ^ |
            Rev. 3  
            Проголосовать: нравится 0 Проголосовать: не нравится

            approach is like this ->> (without loss of generality, assume n>m) avoid swapping first bit, and later on try to get significant bits to m. since, n>m, first bit will be in n and getting bits to m would make n-m smaller and smaller.

»
2 года назад, скрыть # |
 
Проголосовать: нравится +5 Проголосовать: не нравится

This contest be like:

»
2 года назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится
»
2 года назад, скрыть # |
Rev. 2  
Проголосовать: нравится 0 Проголосовать: не нравится

My Solution for problem D https://mirror.codeforces.com/contest/1918/submission/244169954

#include <bits/stdc++.h>
using namespace std;

// shortcuts
#define M 1000000007
#define ll long long
#define lld long double
#define vi vector<int>
#define vll vector<ll>
#define mx 1e18
#define mn INT_MIN

// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
ll find_min(vector<ll> &segment , ll q_left , ll q_right , ll left , ll right , ll segPos)
{
    if(q_left <= left && right <= q_right) return segment[segPos];
    if(q_left > right || left > q_right) return mx;

    ll ans = mx;
    ll mid = (left + right) / 2;
    ans = min(ans , find_min(segment, q_left, q_right , left , mid , 2*segPos+1));
    ans = min(ans , find_min(segment, q_left, q_right , mid+1 ,right , 2*segPos+2));
    return ans;
}

void update(vector<ll> &segment , ll left , ll right , ll segPos , ll idx , ll val)
{
    if(left == right) 
    {
        segment[segPos] = val;
        return;
    }

    ll mid = (left + right) / 2;
    if(idx <= mid) update(segment , left , mid , 2*segPos+1 , idx , val);
    else update(segment , mid+1 , right , 2*segPos+2 , idx , val);
    segment[segPos] = min(segment[2*segPos+1] , segment[2*segPos+2]);
}

ll ok(vector<ll> &vt , vector<ll> &prefix , ll n , ll mid)
{
    vector<ll> dp(n+1 , 0);
    vector<ll> segment(4*n+10 , mx);
    update(segment , 0 , n , 0 , 0 , 0);
    for(ll i = 1;i<=n;i++)
    {
        ll low = 1 , high = i , left = i;
        while(low <= high)
        {
            ll idx = (low + high)/2;
            if(prefix[i]-prefix[idx-1]-vt[i] <= mid)
            {
                left = idx;
                high = idx-1;
            }
            else low = idx+1;
        }

        dp[i] = vt[i]+find_min(segment , left-1 , i , 0 , n , 0);
        update(segment , 0 , n , 0 , i , dp[i]);
    }

    // cout << mid << endl;
    // for(ll i = 0;i<=n;i++) cout << dp[i] << " "; cout << endl;

    for(ll i = 1;i<=n;i++)
    {
        if(dp[i] <= mid && prefix[n]-prefix[i] <= mid) return true;
    }
    return false;
}
void ok()
{
    ll n;
    cin >> n;
    vector<ll> vt(n+1);
    vector<ll> prefix(n+1);
    for(ll i = 1; i <= n; i++) cin >> vt[i];
    for(ll i = 1; i <= n; i++) prefix[i] = prefix[i-1] + vt[i];

    // 1. apply binary search on minimum cost of an array. 
    // 2. use prefix sum to calculate the sum of element in a range.
    // 3. For each iteration of binary search make a dp table, let says currently we are checking for value mid.
    // 4. Now dp[i] = minimum sum of all blocked element from subarray [1...i], when ith element is blocked 
    // 5. Transition dp[i] = min(vt[i] + dp[j]) for all j such that sum(vt[j+1] + ... + vt[i]) <= mid. Use Binary search to find such value of j.
    // 6. Use segment tree to find min(vt[i] + dp[j])

    ll low = 0 , high = prefix[n] , ans = prefix[n];
    while(low <= high)
    {
        ll mid = (low+high) / 2;
        if(ok(vt , prefix , n , mid))
        {
            ans = mid;
            high = mid-1;
        }
        else low = mid+1;
    }
    cout << ans << endl;
}

int main()
{
    // Shubham Kumar Jha
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

#ifndef ONLINE_JUDGE
    freopen("zinput.txt", "r", stdin);
    freopen("zoutput.txt", "w", stdout);
#endif

    ll t = 1;
    cin >> t;
    for(ll i = 1;i<=t;i++)
    {
        ok();
    }
    return 0;
}
»
2 года назад, скрыть # |
Rev. 2  
Проголосовать: нравится 0 Проголосовать: не нравится

Thank you for fast Editorial

»
2 года назад, скрыть # |
 
Проголосовать: нравится +72 Проголосовать: не нравится

great problemset, definitely one of the best div2's of last months!

»
2 года назад, скрыть # |
 
Проголосовать: нравится -12 Проголосовать: не нравится

D problem (Blocking Elements) Video Editorial : https://youtu.be/ZfqWLxBG-Ow?si=WxQOHwg_hdelqH4C

»
2 года назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

everything went as planned, I will farm next div 4

»
2 года назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

i had solved 1 problem and it is accepted but why my rating get minused?

»
2 года назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

I like this round, especially the strong input/output examples. Good round.

»
2 года назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

Hey! This was indeed a very educational type of round, thanks to the contest problem-setters. I just managed to curate some well-elaborated problem discussion sessions covering problems A to D https://youtube.com/playlist?list=PLxHsiA8Ewxn24IVOuNjADlvah8d_eIXuW&si=IbM9faXnzHYP7uSH They should be helpful for beginners and many Div2 participants, especially problem D. Excited to see the community grow together!

PS: Didn't get time till now to work on the problems E to G, but would be glad to have discussions on them on any forum!