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

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

2103A - Common Multiple

Author: NemanjaSo2005

Hint 0
Hint 1
Hint 2
Hint 3
Hint 4
Hint 5
Solution
Implementation (c++)
Implementation (python)
Bonus

2103B - Binary Typewriter

Author: Blagoj

Hint 1
Hint 2
Hint 3
Hint 4
Hint 5
Hint 6
Hint 7
Solution
Implementation (c++)
Implementation (python)
Bonus

2103C - Median Splits

Author: NemanjaSo2005

Hint 1
Hint 2
Hint 3
Hint 4
Hint 5
Hint 6
Solution
Implementation (c++)
Implementation (python)
Bonus

2103D - Local Construction

Author:NemanjaSo2005

Hint 1
Hint 2
Hint 3
Hint 4
Hint 5
Solution
Implementation O(N)
Implementation O(n log n) (prvocislo)
Bonus

2103E - Keep the Sum

Author:NemanjaSo2005

Hint 1
Hint 2
Hint 3
Hint 4
Solution part 1
Hint 5
Hint 6
Solution part 2
Implementation
Bonus

2103F - Maximize Nor

Author: NemanjaSo2005

Hint 1
Hint 2
Hint 3
Hint 4
Hint 5
Solution
Implementation
Bonus
Разбор задач Codeforces Round 1019 (Div. 2)
  • Проголосовать: нравится
  • +74
  • Проголосовать: не нравится

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

oh wow... quick editorial before system test finish... thanks

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

It turned out to be a good competition. Task E is interesting

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

    You literally cheated. https://codeforces.me/contest/2103/submission/316575935 and https://codeforces.me/contest/2103/submission/316574644 have too large of an edit distance for a three-minute gap. Also, the macros at the top completely change.

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

      Yeah, it looks kind of suspicious. Also, If you take a look at his recent competitions, there is literally one competition, where all of his submissions got skipped.

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

      It's an accident

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

        could you kindly explain why you are using a different template in every submission?

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

          I don't have a common template. Each type of task has its own templates and macros. The macros in each template are sometimes different. If it's interesting, I can send you all my templates that I use

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

            I'm not buying it. We are talking about two submissions for the same problem. Why would you switch to a completely different template for the same problem?

            And again, the submission times are only 3 minutes and 4 seconds apart, which means practically you had less than 3 minutes to fix your code. In that small amount of time, not only did you manage to completely rework your solution, but you made a ton of totally unnecessary changes like:

            • reformat all the whitespace in your solution
            • rename the range() macro rng() (why?)
            • rename the test case counter from tc to T (why?????)
            • rename the input vector from stage to a (why???)
            • rename rounds to W (why?)

            None of these changes had anything to do with fixing your solution. The differences might make sense if you started from scratch with a different template, but in that case it would have taken significantly longer than 3 minutes.

            And that's just one submission. The previous 316563964 has a bunch of problems too: apparently this is some topological sort like approach. But why do you define a struct FastIn that you don't even use? You didn't use this in any of your other solutions. And there's a biggerIter lambda that unnecessarily maps INFVAL to INT_MAX. Why? None of this looks like a human wrote it.

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

              Hey! I get where you're coming from — the differences in style and structure between the two submissions are noticeable. But there's nothing shady going on here

              The first submission was just a quick draft. I wanted to test the idea fast, so I threw together a minimal version. When it failed on a pretest, it immediately pointed me to the issue — the grouping wasn't handled properly at certain stage boundaries.

              I have a pre-written template that includes a lot of useful utilities: clog2, doubly linked list handling with L/R, level-based grouping, etc. Once I saw what needed to be fixed, it took me less than 3 minutes to open my template, drop the core idea into place, tweak a few conditions, and submit. Totally doable when you already know what the bug is and have the infrastructure ready.

              As for the renaming — things like rng, T, a, W, ans, and mark are just part of my regular template. I stick with the naming for consistency and readability. No particular reason to rename them back to what I used in the draft.

              And again, this wasn’t a rewrite from scratch. It was more like "okay, I know the issue, let’s rebuild it properly using my usual tools."

              Regarding unused things like FastIn or biggerIter in other submissions — same story. My template includes them by default, and I don’t always clean up unused parts when I’m in a rush to submit. Doesn’t mean the code wasn’t written manually.

              So yeah — it’s all legit and hand-written. Just a quick fix, plugged into a familiar and efficient structure.

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

      I accidentally filled in the wrong solution, for which I received a WA. I had a solution at that time

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

        You have very suspicious and AI-like variable names

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

        But how would you explain the difference in your code-style for each of the problems you have solved? It's very unusual to have a difference in code style if you have been programming for a while. Also, some of your problems have verdicts "Wrong answer on pretest 1". Like, who wouldn't want to test out their solution before submitting it. It's kind of strange to not test your solutions before submitting, and as the other guy have mentioned above, the edit distance between your two submissions is huge. How do you even type that fast, it's impossible.

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

      I checked the first code with AI code checker and it said the code was 85-90% written by AI

      The second code was 90-95% written by AI

      If you want to try it for yourself

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

    thank you sir I had a great laugh

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

The F question is really terrible。

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

I think my solution for E works in $$$\frac{3n}{2}$$$ operations lol

Edit: Didn't see the bonus section. Cool!

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

Great learning experience. will upsolve C, i was trying out a completely different approach :)

PS: will the answer to C bonus be a binary search approach?

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

I have solved D by simulating the process and contstructing graph on elements (There is a directed edge from u -> v when u < v) and then order in topological sort is the answer. Overkilled I guess.

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

    That is, in fact, a valid solution, and there was a harder version that needed it. But we did not use it as it was not interesting enough.

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

    i tried this during the contest but there were some inconsistencies which I couldnt clear. for example:

    let adjacent indices during some iteration be 0, 1, 2 and index 1 is being removed (let it be an odd iteration). Now, we get either a[1] > a[0] or a[1] > a[2] or both. how do we verify which edge to add to our graph? Should we add both? I couldn't come up with a solid solution to resolve this

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

      You need both edges, otherwise 2 will also be removed during that iteration. Assume you have elements from 0 to 6 and only 2 and 5 remain after that odd iteration, the condition will be like this:

      $$$0 \gt 1 \gt [2] \lt 3 \lt 4 \gt [5] \lt 6$$$

      Note that you are free to change it to $$$3 \gt 4$$$, as long as the pattern between 2 remaining elements must be $$$ \lt \lt \lt ... \gt \gt \gt $$$

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

    Can you explain your solution? I did not understand it. Edit : I understood it from another comment. Thanks for the new idea.

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

Missing corner cases/ not doing casework properly cost me a lot of time and WAs... (problem B and C)

Anyway still a great problemset. Good caution for a while for people just submit without being carefully checking through code and cases like me.

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

Another way you could think about D is that we're trying to construct an acyclic graph where we have an edge from $$$a$$$ to $$$b$$$ if $$$p_a \lt p_b$$$. We process each layer individually. Assume that we are removing all non-local maximums. If an element $$$i$$$ is not removed in this layer, then we know that $$$p_i$$$ is a local maximum, then $$$p_{i+1} \lt p_i$$$ and $$$p_{i-1} \lt p_i$$$. We also have to insert edges for elements that are going to be removed, that will be done the same way the editorial describes it. Then we calculate a topological sort. The complexity will be $$$O(n*log(n))$$$. 316594585

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

Can anyone hack my solution for C since I believe it has worst case complexity of O(n^2): 316589874

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

    Can you please tell me what you did?

    If for cases $$$1$$$ and $$$2$$$ you iterated over start of the first one and then when you get good prefix you iterate at the end of the second one, it actually ends up being $$$O(n)$$$, because if you start the second loop more than 2 times, you would have already gotten yes in one of the previous runs.

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

      I didn't quite understand the explanation. In each of the last two nested loops , for each good prefix, it run from l+2 to n, and in worst case, can the number of good prefixes be close to n and none of the pairs l,r satisfy the conditions, so shouldn't it be O(n^2) ? What is it which guarantees O(n)?

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

cool contest

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

F hint 2:

You can look at all the bits separately and answer for each.

Why is that? Let's assume for the oldest bit I found a segment $$$[l, r]$$$ covering $$$i$$$. For the next bit there may exist a segment $$$[l',r']$$$ covering $$$i$$$ that is not "compatible" with $$$[l, r]$$$. This can (?) happen if there is a 1 between $$$i$$$ and both $$$r$$$'s and number of zeroes in the suffix has different parity.

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

For problem F, I think the complexity of official solution should be $$$O(nk^2 + nk \log n)$$$ since calculating range nor takes $$$O(k)$$$ time.

btw, using push down on sparse table instead of segtree can reduce time complexity of processing range max updates from $$$O(nk\log n)$$$ to $$$O(nk + n\log n)$$$

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

can anyone explain why it says -2 here in problem B but it was actually accepted

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

With a tougher implementation it is possible to solve E in (3n/2) moves instead of 3n moves. (the bonus version of the problem)

Idea is somewhat like:

  • use 2 moves so that there is a pair (2 elements with sum = k) on first and last position. should be trivial to those who have solved the main version.
  • now make first element equal to any element that is not on its correct position — that's 1 operation, this will make a cycle of minimum 3 elements (including the first element). If the size of the cycle is P, it will take (P-1) more moves to put everything in the correct place and it will put (P-1) elements in their right place (because we're not counting the first element).

So basically, we can use P moves to put (P-1) elements in their right place. Since the smallest P is 3, in the worst case, it'll take 3 operations to put 2 elements in their correct position. Notice that we only need to put (n-2) elements in their place.

  • At last, use 1 operation to make the first and last element 0 and k
Why can't P be 2?
»
19 месяцев назад, скрыть # |
 
Проголосовать: нравится +16 Проголосовать: не нравится

As a complete newbie, I also confess that the contest was so good! Will upsolve B; it was so damn interesting (though I couldn't solve)!

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

C was too implementation heavy. Took 1 hour for 1 question. Damn!

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

Can somebody please help me finding out edge case for this solution 316608879 i have been thinking since 2 hours but i didnt get any edge cases, i would really be thankful, Thank you in advance

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

    you are not doing complete search

    a2 = pre[r][0] - pre[l-1][0];
    b2 = pre[r][1] - pre[l-1][1];
    

    there can be some segements $$$(l^\prime, r^\prime)$$$ where $$$l \lt = l^\prime$$$ or $$$r^\prime \lt = r$$$ or both

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

You should include Editorial link into "Contest Materials"

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

In problem D , for the test case:

1 6 2 1 1 -1 2 1

The author's constructed perumtation is:

1 4 5 3 2 6

Why is this a valid permutation , will 3 not get deleted in the first iteration itself since its not a local minima?

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

For anyone wondering about the solution of the Bonus Problem for Task C, We can simply binary search on k and use the current solution as the check function. It will be an O(n * log(n)) Solution!

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

F is really nice!

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

hello my fellow competitive programmers, this morning i was looking for some youtube videos to understand and upsolve the problems which i could not solve in 1019 Div 2 contest, then suddenly i saw this youtube channel. this man has uploaded all the solutions till problem F excluding problem E, solved all of them, and i am damn sure he has cheated, also he runs a telegram channel which is mentioned in his youtube channel where he uploads the source code of all the problems, and he has just registered some hours ago, he is — 777dimasik777. and even if he has not cheated, whats the need to upload solutions on youtube and telegram during the contest. such people ruin our community and this platform. please, someone take strict action against such cheaters, so this platform is free from them.

»
19 месяцев назад, скрыть # |
← Rev. 2  
Проголосовать: нравится 0 Проголосовать: не нравится
Bonus section of problem F:
»
19 месяцев назад, скрыть # |
← Rev. 2  
Проголосовать: нравится +8 Проголосовать: не нравится

nice editorial

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

My methods to do A:

  1. O(n log n): Sort the array and if a[i] != a[i+1] then result += 1

  2. O(n log n): Insert all elements into an array and then print out the size of the set

  3. O(n): Make an array to store the number of appearances of a certain element in an array. Then count the number of i such that count[i] > 0

They all just count number of distinct elements in the array.

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

can anyone send me a answer for median splits using dp

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

Solving the questions without participating in the contest, it was a bit shocking to see how pretty much no one solved E, given the solves for F. For reference, E took me about 15 minutes to solve on paper where F took a couple hours or so.

»
19 месяцев назад, скрыть # |
 
Проголосовать: нравится +11 Проголосовать: не нравится
»
19 месяцев назад, скрыть # |
← Rev. 2  
Проголосовать: нравится 0 Проголосовать: не нравится
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define ll long long
const int MOD = 1e9 + 7;
using namespace std;
using namespace __gnu_pbds;
typedef vector<int> vi;
typedef pair<int, int> pi;
typedef map<int,int> mi;
typedef vector<ll> vl;
typedef map<int, vector<int>> Graph;
template<class T> using oset = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;
 
bool even(int n) {
    return (n & 1) == 0;
}

bool odd(int n){
    return (n & 1) != 0;
}

//For uppercase to lowercase
char tolower(char a) { return (a | ' '); }

// For lowercase to uppercase
char toupper(char a) { return (a & '_'); }

bool ipo2(int a) { return (a & (a - 1)) == 0; }

int gcd(int a,int b)
{
    if(b==0)
        return a;
    return gcd(b, a % b);
}

int binExp(int a,int b)
{
    int ans = 1;
    while(b)
    {
        if(b&1)
        {
            ans = ans * a;
        }

        a = a * a;
        b >>= 1;
    }

    return ans;
}

int ceil_division(int a,int b)
{
    return (a + b - 1) / b;
}


void sieve(ll n)
{
    vector<bool>isPrime(n+10,true);
     for (int i = 2; i<=n;i++)
    {
        if(isPrime[i]==true)
        {
            for (int j = 2 * i; j <=n;j+=i)
            {
                isPrime[j] = false;
            }
        }
    }
}


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

    int t;
    cin >> t;
    while (t--)
    {
        int n,k;
        cin >> n>>k;
        vi arr(n);
        for (int i = 0; i < n;i++)
            cin >> arr[i];
        int len = 0;
        int ele = 0;
        int count = 0;
        vi temp;
        for (int i = 0; i < n;i++)
        {
            len++;
            if(arr[i]>k){
                ele++;
            }
            if(ele<=len/2) {
                count++;
                if(len%2 && i<n-1 && arr[i+1]>k){
                    i++;
                    temp.push_back(i);
                }
                else
                    temp.push_back(i);
                ele = 0;
                len = 0;
            }
        }

        int count2 = 0;
        len = 0;
        ele = 0;
        for (int i = n-1; i >= 0;i--)
        {
            len++;
            if(arr[i]>k){
                ele++;
            }
            if(ele<=len/2) {
                if(!temp.empty() && i<=temp[temp.size()-1]){
                    break;
                }
                
                else{
                count2++;
                 if(len%2 && i>0 && arr[i-1]>k){
                    i--;
                }
                ele = 0;
                len = 0;
                }
            }
        }
       

        if(count>=2)
            cout << "YES" << endl;
        else if(count2>=2)
            cout << "YES" << endl;
        else if(count>=1 && count2>=1)
            cout << "YES" << endl;
        else
            cout << "NO" << endl;
    }
        
}

FOR PROBLEM C can anyone tell me why my code is giving WA i am basically trying to partition it from first left side then right side and count the partition on left and right and make sure it doesnot overlaps and also of the length of the partition is odd i can add the next element if its not <=k cause it wont change my median.

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

For D you can just sort indices based on p[i] and break ties based on distance to the last element (with value $$$-1$$$). Then, iterate the sorted array and assign the highest number to odd values and lowest to even values.

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

In problem D O(n) implementation, we are sorting the array, wouldn't that make the implementation O(nlog(n))?