reirugan's blog

By reirugan, 12 months ago, In English

Hello, Codeforces!

I am very excited to invite you to my second-ever contest, Codeforces Round 1065 (Div. 3), which will start on 20.11.2025 17:35 (Московское время)! In this contest, you will be given 2 hours and 30 minutes to solve 7 problems, two of which have been split into subtasks. The subtasks for a given problem are not necessarily placed adjacently in the problemset.

The round will be hosted by the rules of educational rounds (extended ICPC). Thus, all solutions will be judged on preliminary tests during the round, and after the round, there will be a 12-hour phase of open hacks. After the open hack phase, all accepted solutions will be rejudged on successful hacks. Also, note that there is no score distribution — rank will be determined by number of problems solved, followed by penalty; wrong submissions will incur the usual penalty of 10 minutes, following the rules of educational rounds.

As a reminder, only trusted participants of the third division will be included in the official standings table. This is a compulsory measure for combating unsporting behavior. To qualify as a trusted participant of the third division, you must:

  • take part in (and solve at least one problem in) at least five rated rounds
  • and not have had a rating of 1900 or higher at any moment in time.

Regardless of whether you are a trusted participant of the third division or not, if your rating is less than 1600, then the round will be rated for you (unless you register unrated).

Also, note the rule restricting the use of AI. If you are caught breaking this rule, you will be condemned to life spent in prison the basement of some unspecified Codeforces user. Said person's basement is a rather unenjoyable place to live in, so I would advise adhering to the rules.

I would like to thank the following people for helping make this round possible!

Good luck, and have fun!

UPDATE: Due to issues with Cloudflare, the round has been rescheduled for 20.11.2025 17:35 (Московское время).

UPDATE: Editorial

  • Vote: I like it
  • +389
  • Vote: I do not like it

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

As a tester, yuri is peak

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

a @reirugan round ? i wish it will be as good as your previous div3 round !!

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

anime kiss jumpscare

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

what's today's codeforces topic?

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

Could you please remove the gif?

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

codeforces when my mom enters the room

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

as a tester, this gif actually spoils the entire contest

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

I got jumpscared so hard by that gif.

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

'condemned to life spent in the basement of some unspecified Codeforces user' when are we specifying this lad

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

    we internally run an auction for each subject to determine whose basement theyll be assigned to

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

      I can confirm that we have increasing bids on the amount of distress given to punish the cheaters, and then the basement with the lowest bid is chosen (We don't want all of our basements occupied by cheaters)

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

As a tester, unspecified Codeforces user is yuri

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

As a tester, reirugan tested my yuri knowledge.

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

What is the anime name so I can watch it with my family later?

  • »
    »
    12 months ago, hide # ^ |
    ← Rev. 3  
    Vote: I like it -14 Vote: I do not like it

    I believe the GIF is from Samurai Flamenco.

    Edit: the GIF was changed today, current one is from Adachi and Shimamura.

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

Tester here — had fun with this round! Cool problems (gif got changed)

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

source? for cf practice ofc

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

we got gay codeforces before GTA VI?

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

can't wait for the contest's problem statements

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

is this a hint that there will be at most 18 problems?

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

opening codeforces is never disappointing

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

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

As a participant always love to taking part in Div. 3 contests

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

All my favorite NYU students have helped in this contest. Wow!

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

The picture is beautiful, feeling happy when opening codeforces.

Btw, who is the charactor in the picture?

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

As a reirugan fan good luck guys

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

安達としまむら round!

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

skibidi

Related ? $$$67$$$

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

Adachi Sakura!!!

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

How lucky I am to see a Yuri picture on CodeForces! It really makes me curious.

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

"macaquedev for pretending to test;" lol

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

The subtasks for a given problem are not necessarily placed adjacently in the problemset.

Uhh what do you mean by that??

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

    Usually subtasks are enumerated, for example, G1 and G2, and are therefore adjacent.

    In this case, it's possible the subtasks are enumerated with different nonadjacent letters.

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

Can I try? I'm just a new person

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

Llegar, partir y merendar

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

Hope to solve at least 5 problems,thus increase my rating.:)

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

    bro how you predict that?i really dont know, can you say for ex how many problems i need solve every div2 contests to reach speacialist

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

      In common, you should solve 3 problems or solve 2 problems fast(that depends on the difficulty of the contest) in div.2 to reach specialist. In div.3, the number of problems you solve is usually 5.

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

Today is my birthday:)

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

how can i participate as a tester in a competition?

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

hope everybody get a positive Delta

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

Looking for a "Demon Slayer" based contest if we are entering the zone of anime in cf!

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

Thank you cloudflare for forcing this round to be delayed

I blame the vibecoder that broke cloudflare's code

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

was the contest originally now and they postponed it or am I tripping

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

What just even happened XD

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

what is wrong with cloudflare :》

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

I was looking forward to the yuri. At least it didn't happen during the actual round.

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

Why is the contest delayed?

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

hello?

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

Wtf???Rescheduled , was looking forward for the contest.

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

Actually it went well just before the contest begin...lol

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

I hate Cloudflare:(

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

just wanted to solve some Div3 for me

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

It's amazing that Cloudflare is fixed a minute before the original contest start time.

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

I'm seeing that Shayan's and Arpa's streams are scheduled to release within the next three hours. Please get rid of them!

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

    Arpa's video has already been delayed

    I believe Shayan hasn't prerecorded his video; my understanding is that he usually screenrecords live during the contest

    Thanks for pointing it out, though!

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

Why the contest has delayed but the stream has not delayed?

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

Why 48 hours delay :(

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

So, Cloudflare has always been the villain?

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

cloudflare disappointed us all

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

thanks i have my exams tomorrow. 2.5 hrs saved. I'll utilise this in sleeping

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

W organizers!!! I thought I would miss todays round (╥﹏╥)

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

I hate Cloudflare...

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

Dead internet theory has a new definition now

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

Non-hackers getting a crawling ban is sweet justice given all the pain hackers have experienced over the past year.

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

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

Adashima is the best!

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

C2 > DEFG

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

Div. 3>>1

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

For problem E,my code 349964120 construct a permutation with atmost 1 bad index.I wonder whether 6 was there just to confuse.

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

My B solution kept failing on some hidden case, I am confident my logic is correct. Also for D, I was trying to use DSU based approach but kept timing out. Any ideas on approach for problem D?

»
12 months ago, hide # |
← Rev. 2  
Vote: I like it -8 Vote: I do not like it

In Problem E, why multiples of 2, 5 and 10 doesn't work but multiples of 2, 3 and 6 work ?? Is it because we can have at most 6 bad indices and not 10 indices ?

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

    we can make 0 bads as well , the fact that matters is that for any N there are total primes always <=N/2 with N :)

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

    a proof for why 2,3 specifically work:

    consider a solution of the form

    **_**_**_...

    where the * themselves form a sequence s.t. the adjacent * are not coprime. clearly, such a solution has no bad indices. so, it suffices to find a sequence of the * numbers with length >= 2n/3.

    consider multiples 2 and 3. it now suffices to show that these cover 2/3rds of 1 .. n. consider partitioning 1 .. n into disjoint groups of 3 starting from 3. let j be the first number in the block (e.g. 3,6,9,etc.). if j%2==0, then j%2==0 and (j+2)%2==0. so we have covered 2/3 numbers in the range j,j+1,j+2. if j%2!=0, then j%3==0 and (j+1)%2==0. so we have also covered 2/3 numbers in this range. so, from any n we can form a valid sequence * using multiples of 2 and 3, but making sure we carefully place 6 to connect the 2 and 3 multiples. so we use 2 4 8 .. 6 3 9 15 .. for the *'s and fill in the rest.

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

felt like this was hard compared to other div3

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

I was able to do G in $$$O(N * log(N) ^ 2)$$$
Code link: https://codeforces.me/contest/2171/submission/349941964

Is there a better solution?

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

That was an awesome contest for me! After giving so much effort, i solved the c problem

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

I solved A, C1 and C2 but not B wtf?

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

Is this div2?

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

Felt difficult than almost all the div3 I participated in till now ...

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

F is much easier than E, and is too close to D, separating them by E was just evil.

Also, I skipped the first sentence of each problem since it add nothing to the statement, this also caused me to not notice that it has two versions...

»
12 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it
void sol(){
    cin>>n;
    for(int i=1;i<=n;i++){
        cin>>p[i];
        a[p[i]]=i;
    }
    if(a[1]<a[n]){
        cout<<"Yes\n";
        return;
    }
    int mx=1,mn=n; 
    for(int i=a[1];i<=n;i++) mx=max(mx,p[i]);
    for(int i=1;i<a[n];i++) mn=min(mn,p[i]);
    cout<<(mn<mx?"Yes\n":"No\n");
}

I got an WA on pD but I don't know why. Can anyone help me? thx

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

    Check this case 4 6 2 5 1 3

    Your answer is NO, but the correct answer is YES.

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

    n = 9 consider { {5, 6, 7, 9}, {2, 8}, {1, 3, 4}} All the three components are connected. But min(first) > max(last)

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

I personally not satisfied by today's div3 :( Maybe I will get downvotes. I just shared my sadness

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

How tf is this a wrong edge list !?

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

I'm so happy to reach such a high place in this round! The thrill just won't go away!

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

C1 & C2 are nice problems! I was looking at C2 and had absolutely no idea how to do it but after a quick peek at C1 I had an observation that got me through C2!

Had it not been for C1 i would have been stuck at C.

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

Why would you want to make the mod 1e6 + 3 on G?

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

    Do you have a solution that does not require precomputing factorials?

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

      I missed this. You're right. Thanks for explanation :)

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

      If all the constraints are kept the same except for the mod (most importantly, $$$1 \leq a_i \leq b_i \leq 10^6$$$ is kept) and we only considered $$$t = 1$$$, I'm aware of a (partial) solution with two steps than can be done in $$$O(n)$$$ for the first step and $$$\tilde{O}(sqrt(mod))$$$ for the second step (per test case). This idea still requires precomputation, but only for factorials up to $$$b_i - a_i$$$, so we need an additional $$$O(max(b_i))$$$ precomputation. With $$$t = 1$$$, this idea can support mods around $$$10^9$$$, however it 1) cannot be used to solve G for significantly larger $$$t$$$ (I suspect $$$t = 10$$$ already causes TLE) and 2) is definitely not suitable for Div 3, for reasons I will explain later.

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

Can someone please tell me why my dsu code for D is giving WA? Submission:349981598

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

    Consider the case 3 5 2 1 4

    Your answer is NO, but the correct answer is YES.

    Step 1, the code performs union(5, 3).

    Step 2, the code only performs union(4, 1) and union(4, 3).

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

I gave this contest after registration properly. And it was my first contest. Then why it is appearing in unrated section and not in rated section for me? Help pls

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

I introduce a solution of problem E,but I can't prove it(maybe I just know a little) Firstly, make a number of (n/2)+1 called Rt , and continue ues it ,if it's a prime number,put in the first.And then,from 2 to n,make the number mutiples,every time chose two number,such as (prime number, a,b(a and b have mutiples relation)),continue to put such numbers,until Rt > n ,put other number using mutiples relation, ans you will pass the problem.

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

i was registered as unrated by mistake in Codeforces Round 1065 (Div. 3) .please check my submissions my name is Manisha0369

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

Can anyone tell / give any hints IN C problem in genral?

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

    try playing the game starting from the index 1 , think like u are the player playing the game and what optimal moves(swap) u need to play in order to :

    1. maximise(greater than ur opponent) ur score , meanwhile
    2. the swap operation must not increase ur opponents score so that ur opponent's score became greater than ur current score .

    or in more simple words , at the ith move , u can either choose to swap or not to swap. swap only if the operation increase ur score than current or it decreases ur opponents score.

    // here the easy version assumes only 0s and 1s hence the solution is a lil bit different , the above explained algo fits best with the hard version

    // C1 — easy

    /*
    code by - Aryan Shrivastav
    */
    
    /*
    observations : 
    
    */ 
    
    #include<bits/stdc++.h>
    using namespace std;
    
    #define ll long long
    #define vi vector<int>
    #define vll vector<long long>
    #define co_endl cout<<'\n'
    #define f(i,a,n) for(int i=a ; i<n ; i++)
    
    void SOLVE(){
    
        int n;
        cin>>n;
    
        vi a(n);
        vi b(n);
    
        string ans;
    
        int total_a = 0;
        int total_b = 0;
    
        f(i,0,n){
            cin>>a[i];
            total_a+=a[i];
        }
    
        f(i,0,n){
            cin>>b[i];
            total_b+=b[i];
        }
    
        f(i,0,n){
            if(i%2 == 0){ // ajisai turn
                if(total_a%2 == 0){ // total_a is even 
                    if(a[i]==0 && b[i]==1){ // swap
                        a[i] = 1;
                        b[i] = 0;
                        total_a++;
                        total_b--;
                    }
                    else if(a[i]==1 && b[i]==0){
                        a[i] = 0;
                        b[i] = 1;
                        total_a--;
                        total_b++;
                    }
                }
                else{ // total_a is odd // dont swap
                }
            }
            else{ // mai turn
                if(total_b%2 == 0){ // total_b is even 
                    if(a[i]==1 && b[i]==0){ // swap
                        a[i] = 0;
                        b[i] = 1;
                        total_a--;
                        total_b++;
                    }
                    else if(a[i]==0 && b[i]==1){
                        a[i] = 1;
                        b[i] = 0;
                        total_a++;
                        total_b--;
                    }
                }
                else{
                    // dont swap
                }
            }
        }
    
        int ans_a = total_a%2;
        int ans_b = total_b%2;
    
        if(ans_a > ans_b){
            ans = "Ajisai";
        }
        else if(ans_a < ans_b){
            ans = "Mai";
        }
        else{
            ans = "Tie";
        }
    
        cout<<ans;
    
        co_endl;
    
    }
    
    int main(){
    
        int t;
        cin>>t;
        while(t-->0){
    
            SOLVE();
    
        }
    
        return 0;
    }
    
    

    // C2 — hard


    /* code by - Aryan Shrivastav */ /* observations : */ #include<bits/stdc++.h> using namespace std; #define ll long long #define vi vector<int> #define vll vector<long long> #define co_endl cout<<'\n' #define f(i,a,n) for(int i=a ; i<n ; i++) void SOLVE(){ int n; cin>>n; vi a(n); vi b(n); string ans; int total_a = 0; int total_b = 0; f(i,0,n){ cin>>a[i]; total_a^=a[i]; } f(i,0,n){ cin>>b[i]; total_b^=b[i]; } f(i,0,n){ if(i%2 == 0){ // ajisai turn if( (total_a ^ a[i] ^ b[i]) > (total_b ^ b[i] ^ a[i]) ){ total_a = (total_a ^ a[i] ^ b[i]); total_b = (total_b ^ b[i] ^ a[i]); // swap int temp = a[i]; a[i] = b[i]; b[i] = temp; } } else{ // mai turn if( (total_a ^ a[i] ^ b[i]) < (total_b ^ b[i] ^ a[i]) ){ total_a = (total_a ^ a[i] ^ b[i]); total_b = (total_b ^ b[i] ^ a[i]); // swap int temp = a[i]; a[i] = b[i]; b[i] = temp; } } } int ans_a = total_a; int ans_b = total_b; if(ans_a > ans_b){ ans = "Ajisai"; } else if(ans_a < ans_b){ ans = "Mai"; } else{ ans = "Tie"; } cout<<ans; co_endl; } int main(){ int t; cin>>t; while(t-->0){ SOLVE(); } return 0; }

    do reply me if u got the approach and consider upvoting it :)

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

i guess $$$O(m \sqrt m)$$$ memory gets passed in problem H (you just need to use 16 bit integers) 349971224

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

My rating is 1177 and had never got higher than now. I have solved at least one problem in at least five rated rounds, such as 1858, 1879, 1878, 2166, 2169. And I had never cheated in any round. But I wonder why it shows "Unrated allowed"?

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

Hello

Can anyone please help me to find cases in which mine code will fail (Give Tle) for problem — F It is giving tle on test case — 12 Thanks for helping

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define int long long
const int mod = 1e9 + 7;
#ifndef ONLINE_JUDGE
#include "debug.h"
#else
#define deb(x...)
#endif
void solve();
signed main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    ll t;
    cin >> t;
    while (t--)
    {
        solve();
    }
    return 0;
}

bool check(vector<int> &a, int n)
{
    int mex = 1;
    set<int> st;

    for (int i = n; i >= 2; i--)
    {
        int ele = n - i + 1;

        st.insert(a[i]);

        while (st.find(mex) != st.end())
        {
            mex += 1;
        }

        if (mex == ele + 1)
        {
            return 1;
        }
    }

    return 0;
}

void solve()
{
    int n;
    cin >> n;
    vector<int> a(n + 1);

    for (int i = 1; i <= n; i++)
    {
        cin >> a[i];
    }

    if (check(a, n))
    {
        cout << "No" << endl;
        return;
    }

    set<int> st;
    vector<vector<int>> ans;

    for (int i = n; i >= 1; i--)
    {
        auto id = lower_bound(st.begin(), st.end(), a[i]);
        vector<int> rm;
        for (auto it = id; it != st.end(); it++)
        {
            ans.push_back({a[i], *it});
            rm.push_back(*it);
            if (ans.size() == n - 1)
                break;
        }

        if (ans.size() == n - 1)
            break;

        int size = rm.size() - 1;
        for (int j = 0; j < size; j++)
        {
            st.erase(rm[j]);
        }

        if (rm.size() == 0)
            st.insert(a[i]);
    }

    cout << "Yes" << endl;
    for (auto val : ans)
    {
        for (auto node : val)
        {
            cout << node << " ";
        }
        cout << endl;
    }
}
»
12 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

i cant write a comment here

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

    I have a very easy solution to c1 and c2, you just have to change the checking condition in the c2 version. Now it says that the play should be optimal, that means if it's the first player's turn and he is ahead in score , then he won't swap. Likewise , if he is down by one then on his turn if on swapping his score increases then only he will swap otherwise not. Second player would do the same. Therefore,the solution might be a very simple greedy approach where on the i'th turn, each player checks the score and then swaps.

    Now C1 SOLUTION----->

    [submission:349984404]
    

    The snippet shows that first we calculate the original xor of all elements,then on each move swap them. If the score increases like it can be 1 or 0 only. Then on swapping the score of both of them will become their negation.

    C2 SOLUTION -------->

    [submission:349987068]
    

    In the C2 problem, the score now won't remain 0 or 1, but the logic remains the same, first calculate the default xor of all numbers then the greedy approach to check on each move whether the scores will change or not. We just update the scores in different way in C2 because in C1 only 0 or 1 were possible pair of total xor scores. Thank You, Niksy

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

very ezzz round for div.3

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

That animation is so cool. I just love it