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

Автор reirugan, 10 месяцев назад, По-английски

I hope you all enjoyed the contest!

Rating Predictions
Rate the contest!

A — Blackboard Game

Solution
Rate the problem!

B — Tournament

Solution
Rate the problem!

C — Prefix Min and Suffix Max

Solution
Rate the problem!

D — Binary String Battle

Solution
Rate the problem!

E — MEX Count

Solution
Rate the problem!

F — Minimize Fixed Points

Solution
Rate the problem!

G — Modular Sorting

Solution
Rate the problem!
Разбор задач Codeforces Round 1034 (Div. 3)
  • Проголосовать: нравится
  • +292
  • Проголосовать: не нравится

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

Pen,Paperforces round

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

Bro dropped the editorial at the speed of light. Very refreshing contest btw!!

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

Fun fact: As a tester, testing for this contest was stopped once due to me.

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

Thank you for the contest and the fast editorial!!!

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

assert(number_theory == magic);

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

editorial drops faster than brainrot memes hitting my youtube page

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

It was a weird contest for me. Took me 30+ minutes to solve A but about 15 total for both C and D :)

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

Am I the only one who got stuck on D and solved E? Very nice contest by the way, kudos

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

so fast tutorial. great work

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

problems were really interesting thank you for the great round!

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

This is the best div3 E i've ever seen

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

What could be the expected rating of the problems? ig A-B-C seems like a standard 900,1100, and 1200 rated. D was tricky but code is short so it can't be thought of more than 1400. E probably felt like 1500-1600. I don't know about F and G tho. What do you guys think?

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

In D : Step 3 -> Take the example given after Bob gets s=00101111 Alice could convert this to s=00000010 and eventually win. I don't see how Bob wins this.

The strategy I see is Alice tries to make the array of the for 10001000/01000100 etc , and wherever Bob tries to reverse digits she flips back the ones Bob flips additionally being able to take care of extra ones. Hence, even if n>2k she can win.

What's wrong?

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

So close yet so far for F. great contest btw

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

Editorial is so fast.

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

good

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

Contest without graphs and dp after long time. Kudos to authors.

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

Clean editorial, easy to understand.

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

Although i was not able to solve F, it was a beautiful problem and worth spending my time on. Thank you for the contest

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

editorial out so fast ! wow !!

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

Great Contest, except D was horrible.

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

https://t.me/placementsoftware reirugan this is a telegram channel where answers were getting released during the contest, please check this and use it during the plagiarism check to ban the contestants who have used the exact same code in their submission.

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

As always, please report cheaters on https://cf-cheater-database.vercel.app/.

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

did anyone faced connection issues while submitting? I was stuck approximately 20mins...might be my internet but i am curious if anyone faced the same? :'

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

can anyone please tell me how alice will win if n=5 k=3 and s = 11111

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

This is the closest I have ever been to AK'ing a contest.

And yet, 2 problems was left. Still a long way to go ig

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

can someone pls help me understand where I am going wrong in G? I am at a loss[submission:326909800]

https://mirror.codeforces.com/contest/2123/submission/326909800

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

I like this contest, the problems are fun to think about. Even if I don't solve E and F, I had fun with them :)

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

Strange how all Problem A solutions match. Is this collective intelligence or something else?

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

the contest went from being one of my worst to one of my best, altho i have a rank of 8.6k, stayed idle for 2 hours, clutched at the very last. Hare Krishna!

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

Thanks for great contest and lightning quick editorial!

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

Can someone please explain D to me, especially step 3 in the editorial. I was able to come to the point where I observed that 1. If n is odd and the middle element is already 1 and rest count of 1 is at max k then its always possible for Alice to Win. 2. If n is even and middle 2 elements are 1 and rest count of 1 is at max k then again Alice can win. Basically I understood the reverse of step 2 that if I can force Bob to only be able to make a sequence of length exactly 'k' then Alice can win. Also k == half the length of string in above 2 cases.

But this condition, n < 2*k seems like magic to me.

Basically how to logically go from Step 2 -> Step 3 My Submission: https://mirror.codeforces.com/contest/2123/submission/326981142

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

    you can think of it like this : in order for Alice to win , she needs at some point to make all the remaining ones included in all the substrings , so that whatever Bob does he can not get the full +k ones at his turn .And when we say included in all the substrings they must also be included in the first substring of length k . So we must ensure that when we divide the string into first (k) and last (n-k) elements , we should be sure that the ones in the first substring can be included in all other substrings , so (k) should be greater than (n-k) , reformulating : k>n-k --> 2*k>n is a necessary condition for Alice to win . hope it helps:)

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

    I want to explain it to you with examples in an intuitive way.

    Take an example with n = 7, s=1111111, k = 4 (2k > n holds, so Alice wins even though s is fully 1's). now, Alice can keep doing this: flip leftmost 1 bit and rightmost (k-1) 1's, so after the first move, s = 0001110. Now Bob makes it 1111110, Alice can keep doing the same strategy, s becomes 1111100 (after Alice's and Bob's second moves). This way, after (k-1) moves, here (k-1) = 3, s will be 1111000 after Bob's turn. Now Alice can simply flip the 4 ones and win. It's easy to see that this strategy is optimal for Alice, and any other strategy is not better.

    Now, take n = 8, k = 4, and we have k+1 one's this is the most forgiving case that we can have (from Alice's perspective) where 2k > n does not hold. Specifically, take s = 00011111 (5 one's), now Alice will flip 4, Bob will flip the same 4 back to 1, so this is a trivial case. Take s = 10101011. Alice -> 00000001, Bob -> 11110001. (And now it's the same case like the one above where Alice flips 4 bits and Bob flips back the same 4 bits).

    So if count of 1's > k and 2k <= n, Bob will always win, otherwise Alice wins.

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

I absolutely love the G problem. After reading the editorial, it just seems so obvious

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

Am I only one who is thinking that my code are more complex than this lol

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

Thanks for the fast editorial. The questions were really good. I was able to solve A,B and C.

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

it was my first codeforces contest it took me 50min to solve A ,and got stuck on B,it's really interesting

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

super good contest, very interesting problems and super quick editorial !! :)

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

Gratitudes for the lightening fast editorials.

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

the sol $$$O(tn^2)$$$ for prob A, 326827179

(What tf was I thinking?)

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

My stupid ass was thinking of implementing two heaps in C but I got cold feet and didn't do shit

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

I was looking awoo 's Solution. for Problem E . I dont have any idea how this simple logic work, some. kind soul please help me. :

vector<int> cnt(n + 1);
for (int x : a) ++cnt[x];
vector<int> ans(n + 2);
forn(i, n + 1){
	int l = cnt[i];
	int r = n - i;
	if (l <= r){
		++ans[l];
		--ans[r + 1];
	}
	if (cnt[i] == 0){
		break;
	}
}
forn(i, n + 1) ans[i + 1] += ans[i];
forn(i, n + 1) cout << ans[i] << " ";
  • »
    »
    10 месяцев назад, скрыть # ^ |
    Rev. 2  
    Проголосовать: нравится 0 Проголосовать: не нравится

    Think of it like marking the start and end of the increment, and the prefix sum “spreads” the value across the entire range. https://mirror.codeforces.com/blog/entry/78762

    Btw, if you're asking about the full solution, try thinking about the problem in reverse: for each i, check whether it's possible to make the mex = i, and determine the minimum and maximum number of elements to remove to achieve that. (step 4 in this editorial)

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

    ohh look what he is calulating for each possible mex he is calculating 2 values one is what is min number of element we need to remove to get ans as i and what is max number of value we ca remove get ans as i now for getting some value as min value is just its frequency and max value you can calculate first remove everyhting that is >= element . now when a mex is not possible we break now for each i we know we can get value as i for some k belongs to l to r then we just to linear sweeping between l to r incraesing value at l by +1 and value at r by +1 and doing prefix array sum

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

    its difference array ; Imagine a you have been given an array where you are told to make increment over a range (l,r) , you can just increment the lth element by x and (r+1)th element by -x , and then take a prefix_sum at the end of it . So basically he has calculated the min number of removals and max number of removals needed to make any number from (0,n) , a possible MEX , then for each range min[i] to max[i] , he is using a difference array to make range updates and finally took a prefix sum . I had a similar approach as well.

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

    it can also be called as sweep line

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

D could also be a sliding window isn't it, If a every window is like 011 and k=3 let's say then if Alice selects one of it then, Bob wins the next.

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

D was quite tricky, E,F were much easier

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

Great contest and balanced questions! Had that nostalgic codeforces feel many contests these days don't

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

can anyone please explain why does my code exceed time limit in testcase 30 (326998284)

I'm using an array for count which should be better than a map as provided in the solution

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

Alternative solution to F:

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

Anybody body know what is wrong with this? https://mirror.codeforces.com/contest/2123/submission/326994630, stops on test 13?

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

I had a very small bug in question E yesterday that I didn't find out for an hour, that is, I didn't consider the situation of no zero, and I looked at F this morning and wrote it in 10 minutes

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

Alternative for E ( i think ). Solution uses transformation from i to i + 1 step

https://mirror.codeforces.com/contest/2123/submission/326935560

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

I dont really understand my solution of DEF completely, but I guess them and get passed

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

nice contest, i will learn solving problem by going through these editorials!

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

Am i the only one who could not solve C and ruined the contest?

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

My approach to E uses a greedy approach different from the editorial's solution but it's much more complicated, although I think it's still worth noting.

First, we need to find the original MEX, denoted MEX from now on. Now, for k = 0, the answer is always 1.

I have a variable called extra initialized to 0, extra will be the count of elements that when removed, the original MEX will stay the same. Now, of course, we need to keep 1 instance for elements < MEX, the others are extra, and for elements >= MEX, all instances of these elements are extra. For every element >= MEX, I will add the frequency of that element to extra. I also have a vector v for the frequencies of the elements < MEX, sorted in decreasing order.

I don't actually know how to explain the rest of it, but the idea is that I use binary search on this vector of frequencies to find how many values in v are <= k, and this is almost the number of different MEX's I can achieve for this particular k, we also add 1 if extra >= k because in this case we can achieve the original MEX as well.

There is also a special case where K >= extra, that is, if we removed all extra numbers that do not change the original MEX, we still need to remove more. let x = k — extra denote the amount of elements we still have to remove, the answer in this case will be (MEX — x + 1), MEX is the original MEX.

submission: 327022593

UPD: updated submission (removed unused variables).

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

Can someone help me find why my greedy approach is wrong for d . Basically i am greedily converting the outermost k 1's of the string to 0 , and then checking if i can get a substring of length k+1 . Here's my submission — 326923441

my idea was that if bob can make k+1 consecutive 1 then he always win

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

    Your approach is incorrect. Consider the following example:

    n = 5, k = 3 s = "11111"

    After Alice's first move—if she plays optimally—the string will become "01010". Now, Bob is left with a maximum substring of consecutive zeroes of length 1, so he can turn at most 3 characters into '1'. On her next move, Alice can easily turn all the characters back to '0'.

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

i had pretty simple approach on F!!....

https://mirror.codeforces.com/contest/2123/submission/326973038

I just swap x with its largest divisor!

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

I only came up with C with 1 minute left xD Don't know when am I finally touching Ds

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

Am I the only one, who solved problem E using Merge Sort Tree? Because when you realise, that 0 <= i <= min(n-k, mex) and freq(i) <= k it turns out to be a straightforward Merge Sort Tree task (and I couldn't figure out a different solution)

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

For question F , I just iterated from n to 1

and swapped it with the max divisor

int largest_divisor(int n) {
    if (n <= 1) return n;
    for (int i = sqrt(n); i >= 2; --i) {
        if (n % i == 0) {
            return n / i;
        }
    }return 1;
}
int solve(){
    ci(n)vector<int> a(n+1);
    for( int i= 1;i<=n;i++){
        a[i]=i;
    }
    for(int i=n; i>=0;i--){
        int largest = largest_divisor(i);
        if(largest == 1) continue;  
        swap(a[i],a[largest]);
    }
    for(int i=1;i<=n;i++){
        cout << a[i] << " ";
    }
    cout << endl;  
    return 0;
}

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

couldnt solve A, but barely managed to solve B & C lol

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

Thanks for the fast editorial guys, great contest!

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

Writing Solutions step wise is even more confusing . BEA!

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

Great contest! Thanks for the fast editorial!!!

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

there is no changing in my ratings or is not even showing any updates of this contest

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

Editorial of G seems too much complicated to understand ? Is anyone able to make it more simpler ?

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

    I tried chat GPT.

    It helped.

    Any way, I am getting WA but can't tell whats wrong in my code

    327149170

    Can some one lend some brain power?

    Thanks

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

      Found one silly mistake

      Now on TLE on test 23 327273197

      After removing all binary data structures, and using global data stores

      Now i achieved TLE on test 29 327276612

      reirugan is there any special reason why input constrain are so tight?

      My way to calculate divisors was innefficient, still normal code with STL's binary structure based data type like map, vector::push_back() gave TLE :)

      I had to re write code to optimize time with so many unconventional ways. this seem so unnecessary it also waist lot of compute resources of codeforces engines.

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

    Key observation is

    1. $$$(a + (k.n))\mod{m}$$$ where $$$n\in{N}$$$, can be written as $$$a\mod{gcd(k,m)}$$$

    2. possible values you can transform $$$a_i$$$ for given any $$$k$$$ is congruent to $$$a_i\mod{gcd(k,m)}$$$

    3. for any value of $$$k$$$, $$$gcd(k,m)$$$ will be a divisor of $$$m$$$ which means there are only less than $$$800$$$ values possible for divisors (given $$$m \lt 5\times{1e5}$$$)

    4. For each divisor you can keep array $$$a$$$ transformed into $$$a_i\mod{d|m}$$$

    5. you can keep precomputed sum of all arrays (arrays based on divisor of m). and determine answer.

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

Thanks for the contest! Great problems

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

Did anyone notice that there is an account llm-test currently solve all div3 using AI? I'm scared now :(

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

Does the"random"in Problem B mean that peopel are pairred up in twos, and after the match,the winners can be brought together to compete again?

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

Question G — Could someone please explain why ai(mod(gcd(k, m)) is the invariant across the operations? Where did gcd(k, m) come from?

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

    Let x=gcd(k,m). Since x divides k, adding k keeps ai invariant mod x because k is congruent to 0 mod x. Similarly, taking ai modulo m keeps ai invariant modulo x because x divides m.

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

    Where did gcd(k, m) come from?

    I like to imagine in term of grid, picture m=10, k-5, ai=3

    ___#______
    

    keep doing ai + k for few times and you get

    ___#____#____#____#____#____#____#____#____#____#_
    

    now see how would (ai + k) mod m would look, by wrapping this list every 10 chars

    ___#____#_
    ___#____#_
    ___#____#_
    ___#____#_
    ___#____#_
    

    You can see ai + k only ever return in 2 possible values, if you look at these values mod gcd(10,5), i.e. mod 5

    ___#_
    ___#_
    ___#_
    ___#_
    ___#_
    ___#_
    ___#_
    ___#_
    ___#_
    ___#_
    

    you can see ai mod (gcd(k,m)) is invariant. that means you can only set ai to ai mod (gcd(k,m)) being smallest possible value and take gcd(k,m) steps at a time.

    if gcd(k, m) is 1 you can make ai any value, try to picture same with k = 7.

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

can anyone explain me "we can first choose one instance of every element less than i . Now, the MEX of our chosen elements is i , so we just need to choose the rest of the elements without affecting the MEX . We can just choose elements arbitrarily, as long as we don't choose i . Since freq(i)≤k , we have enough spare elements to reach our n−k quota without needing to choose i .

" in problem E editorial

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

    lets say that mex(a) = 5

    this means that we have 0 ,1,2,3,4 present in our original array a

    now we want to keep only k elements out of n

    we want to check if we can have i as a MEX for these k elements (0<= i <=5)

    for each i we have to take all the elements that are less than i and we need to not take i

    so if we can pick K elements such that we have all elements less than i and we don't have i
    then we have made an array with k elements and it's MEX is i

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

problem G is A great educational problem can someone provide problems where the idea of this diff array can be applied also

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

why gcd(k, m) in problem G?

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

This should be the gold standard for editorial quality. Feedback for problem quality and difficulty and the solutions explained in collapsible steps. I also really liked the tester rating predictions. I don't expect all editorials to be of this quality, but I certainly appreciate it!

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

I know my doubt would be silly because i would be messing somewhere but : in problem D ,if n = 9 and k = 5 and string = 011111110 the answer according to tutorial solution should be Alice but i think Bob should win Plz tell me where i am messing up

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

I don't really understand A.

Here it says that a+b≡3(mod4) which means that b = 3 (mod4) — a; Say Alice picks 4, then b = (3 % 4) -4 = -1. Am I just not understanding the question? @reirugan

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

I am not able to see the reason that why does the test case n=5, j=4, k=1 and the array being [5,4,5,3,2] return YES. While according to me and the solution it should be returning NO.

It's been already mentioned in the step 2 of the solution to the problem that given number can only survive when k=1 if and only if j is largest number among them all.

Please Clarify

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

div 3 C Prefix min and suffix max

#include<iostream> 
#include<vector>
#include<algorithm>
#include<cmath>
#include<stdlib.h>
#include<climits>

using ll=long long;

using namespace std;

void solve();

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

    int T=1;
    cin>>T;

    while(T--) solve();
    return 0;
}

void solve(){
    int n;
    cin>>n;
    vector<int>arr(n);
    for(int i=0;i<n;i++) cin>>arr[i];
    // main

    int mn=INT_MAX,mx=INT_MIN;
    for(auto x:arr){
        if(mn > x) mn=x;
        if(mx < x) mx=x;
    }

    string bs="";
    for(int i=0;i<n;i++){
        if(i==0 || i==n-1) bs += '1';
        else if(arr[i]==mx || arr[i]==mn) bs += '1';
        else bs += '0';
    }
    cout<<bs<<endl;
}

Why my code is Wrong

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

the first time i actually used difference array !1!!1

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

We can optimize the solution for problem E using a difference array. Let cnt[x] be the frequency of value x. For x < mex, it contributes to answer k iff cnt[x] ≤ k ≤ n − x − 1.

Each x defines a valid interval on k. We add +1 on [cnt[x], n − x − 1] using a difference array, then take prefix sums.

This avoids sets/maps and runs in O(n) time with O(n) memory instead of O(nlogn) time complexity.