sevlll777's blog

By sevlll777, 2 weeks ago, translation, In English

Thanks for participating!

2067A - Adjacent Digit Sums

Tutorial
Submission

2067B - Two Large Bags

Tutorial
Submission

2067C - Devyatkino

Tutorial
Submission

2067D - Object Identification

Tutorial
Submission

2067E - White Magic

Tutorial
Submission

2067F - Bitwise Slides

Tutorial
Submission

2066D1 - Club of Young Aircraft Builders (easy version)

Tutorial
Submission

2066D2 - Club of Young Aircraft Builders (hard version)

Tutorial
Submission

2066E - Tropical Season

Tutorial
Submission

2066F - Curse

Tutorial
Submission
  • Vote: I like it
  • +97
  • Vote: I do not like it

»
2 weeks ago, # |
  Vote: I like it 0 Vote: I do not like it

thank you for the quick editorial, questions were tricky.

I need to understand official approach, hoping to get some proofs of correctness

  • »
    »
    2 weeks ago, # ^ |
      Vote: I like it -64 Vote: I do not like it

    Idea for B — Two Large Bags

    Now re-consider this problem with the following idea:

    For each number i in the array, count[i] should be even. You are allowed to perform operations on the counts. The allowed operation is : if count[i] >= 2, then you can perform

    Operation: count[i + 1]++ and count[i]--.

    Key Idea

    Even Pairing Requirement: Each number i must ultimately appear an even number of times so that the numbers can be split equally between the two bags.

    Pushing Numbers Forward:

    If count[i] > 2, one might think to push all count[i] - 1 copies to i + 1. However, there is a catch:

    If you push count[i] - 1 numbers, then there will be only 1 copy of i left, meaning i will not be paired with any other i. Therefore, you only need to push count[i] - 2 copies to i + 1, leaving behind a pair of i.

    Greedy Approach:

    You have to carry these extra numbers as far forward as possible because they can combine with any upcoming larger number and form a pair with that number. TC : O(n) SC : O(n).

    #include <bits/stdc++.h>
    
    using namespace std;
    
    #define ws ' '
    #define newl '\n'
    #define ll long long
    #define pb push_back
    #define all(x) x.begin(), x.end()
    #define _sz(x) (int) x.size()
    #define Yes cout << "Yes\n"
    #define No cout << "No\n"
    
    
    void solve() {
        int n;
        cin >> n;
        vector<int> hash(n + 1, 0);
        for (int i = 0, x; i < n; ++i) {
            cin >> x;
            hash[x]++;
        }
    
        for (int i = 1; i < n; i++) {
            if (hash[i] > 2) {
                hash[i + 1] += hash[i] - 2;
                hash[i] = 2;
            }
        }
    
        for (int i = 1; i <= n; i++) {
            if (hash[i] % 2 == 1) {
                No;
                return;
            }
        }
    
        Yes;
    }
    
    int main() {
        ios::sync_with_stdio(false); cin.tie(__null);
        
        int t = 1;
        cin >> t;
    
        for (int _ = 0; _ < t; _++) solve();
    
        return 0;
    }
    
    
    • »
      »
      »
      2 weeks ago, # ^ |
        Vote: I like it 0 Vote: I do not like it

      Yea I did a similar approach, just keep pushing numbers forward leaving 2 at the current number. When we reach a number where the freq == 1, the answer is "no" since it can't be split equally. When we reach the biggest initial number, just check if it's frequency is even, since every number before will either have a freq of 0 or 2.

    • »
      »
      »
      2 weeks ago, # ^ |
        Vote: I like it -21 Vote: I do not like it

      What is wrong in my comment, why you people are downvoting it?

      • »
        »
        »
        »
        10 days ago, # ^ |
          Vote: I like it 0 Vote: I do not like it

        Just consider it good comment then, people here are kinda weird.

        • »
          »
          »
          »
          »
          10 days ago, # ^ |
            Vote: I like it +5 Vote: I do not like it

          Yeah, Thank you man!

          • »
            »
            »
            »
            »
            »
            4 days ago, # ^ |
              Vote: I like it 0 Vote: I do not like it

            Thanks for your approach!

»
2 weeks ago, # |
  Vote: I like it -53 Vote: I do not like it

good contest , bad contest

»
2 weeks ago, # |
Rev. 2   Vote: I like it -68 Vote: I do not like it

I reached CM!

The best contest i've ever particpated!

»
2 weeks ago, # |
  Vote: I like it +10 Vote: I do not like it

please make editorial for problem D in English

»
2 weeks ago, # |
Rev. 4   Vote: I like it +7 Vote: I do not like it

How was it supposed to be deduced for A that 'n' is supposed to be a 'positive integer' only? The problem specified for 'n' to be an 'integer' which allows a larger set of valid pairs. More precisely for each currently accepted (x, y), (y, x) should also be a valid pair.

Or am I missing some detail?

  • »
    »
    2 weeks ago, # ^ |
      Vote: I like it +1 Vote: I do not like it

    oh yeah, correct, it says integer

  • »
    »
    2 weeks ago, # ^ |
      Vote: I like it -6 Vote: I do not like it

    There was an announcement stating that n is positive. Apart from that, there is nothing that says n should be positive.

    • »
      »
      »
      2 weeks ago, # ^ |
        Vote: I like it 0 Vote: I do not like it

      oh man ,

      many people who were solving it assuming negative and missed the announcement because they were looking at their notebook might have spent so much extra time.

    • »
      »
      »
      2 weeks ago, # ^ |
        Vote: I like it +7 Vote: I do not like it

      Ok thanks, I fortunately read the announcement before submitting. It was just that the announcement seemed to imply that the fact was deducible from the problem statement itself, therefore I was confirming.

»
2 weeks ago, # |
  Vote: I like it +8 Vote: I do not like it

tricky but insteresting questions!

»
2 weeks ago, # |
  Vote: I like it +5 Vote: I do not like it

sevlll777 Problem D (Div2) or Problem A (Div1)'s Editorial is in Russian language only.. Please make it available in English !!

  • »
    »
    2 weeks ago, # ^ |
      Vote: I like it +12 Vote: I do not like it

    It is translated on Polygon. I guess some time is needed to pull it up from here, should be available soon

»
2 weeks ago, # |
  Vote: I like it +4 Vote: I do not like it

Interesting and exciting.Love it!

»
2 weeks ago, # |
  Vote: I like it +23 Vote: I do not like it

Is there a problem in the interactor of Div. 1 A (Div. 2 D) Object Identification? This submission 305637703 passes the sample locally but gets WA 1.

  • »
    »
    2 weeks ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    we are investigating it

    • »
      »
      »
      2 weeks ago, # ^ |
      Rev. 6   Vote: I like it +31 Vote: I do not like it

      I'd like to mention that I looked for format error for about 20 min due to the misleading information from the bugged interactor in this submission and the lack of interacting process for the sample.

»
2 weeks ago, # |
Rev. 2   Vote: I like it +1 Vote: I do not like it

Can anybody explain why this doesnt work for A?

void solve(){
	ll x,y;
	cin >> x >> y;
	if(x<y){
		if(x==y-1) cout << "YES";
		else cout << "NO";
	}
	else{
		if(x%9==y%9-1) cout << "YES";
		else cout << "NO";
	}
}
  • »
    »
    2 weeks ago, # ^ |
    Rev. 3   Vote: I like it 0 Vote: I do not like it

    There will be cases where $$$y\pmod{9} = 0$$$ and your code would check if $$$x\pmod{9}=-1$$$, when it should be checking if $$$x\pmod{9} = 8$$$. You can replace your code with

    void solve(){
    	ll x,y;
    	cin >> x >> y;
    	if(x<y){
    		if(x==y-1) cout << "YES\n";
    		else cout << "NO\n";
    	}
    	else{
    		if(x%9==(y%9+8)%9) cout << "YES\n";
    		else cout << "NO\n";
    	}
    }
    

    and it should work. Also you aren't printing a new line, which you should.

  • »
    »
    2 weeks ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    x=1,y=2; test case is failling. Consider num=100,num+1=101 then x=1 and y=2

  • »
    »
    2 weeks ago, # ^ |
      Vote: I like it +1 Vote: I do not like it

    See you have a integer number n let say it consist ABCDEF where A,B..F are digits

    Thing about the two case:

    • Case 1: Where unit digit (here F belongs to [0,8]) n+1 make it belongs to [1,9] that mean the whole structure of number n would remains constant except the unit digit F so the sum would increase just by one x = A+B+C+D+E+F y = x + 1

    • Case 2: Where unit digit of n is 9 now n+1 will make unit digit 0 and carry 1 will be forward to E, again thing of two case E belongs to [0,8] or E == 9, if case 1 then simply it will add up 1 and stop other wise make digit E = 0 for n+1 and forward that carry to D.

    so you got a sum x for n, for n+1 you are going to get some zeroes in place contiguous 9 from unit place (let say k no of 0 replacing k 9's) and finally adding 1 to very first non 9 digit.

    so y = x- k.9 + 1

    clearly visible (x + 1- y) must be divisible by 9 by taking care that (...) is >= 0.

    That's it.... I hope it is helpful and easy to understand pardon my bad English

»
2 weeks ago, # |
  Vote: I like it +216 Vote: I do not like it

Here's a combinatorial solution for D1.

Let the number of planes launched from $$$i^{\text{th}}$$$ floor be $$$u_i$$$, note that $$$u_{n} = c$$$.

Now corresponding to this case in the original dp recursion solution we get the term $$$\prod_{i=1}^{n-1} \binom{c}{u_i}$$$

So the final answer is just sum over this expresion as $$$u_i$$$ ranges over all possible values constrained by $$$0\le u_i \le c$$$ and $$$\sum_{i=1}^{n-1} u_i = m-c$$$.

Now this is equivalent to a counting problem where we have $$$c(n-1)$$$ distinct objects divided into $$$n-1$$$ types with $$$c$$$ objects of every type and we want to choose a total of $$$m-c$$$ objects. The above expression occurs when we count by first deciding number of objects of each type and then choosing the objects per type. Instead we can directly choose the $$$m-c$$$ objects.

Hence the answer is

$$$\displaystyle\binom{c(n-1)}{m-c}$$$
  • »
    »
    2 weeks ago, # ^ |
    Rev. 2   Vote: I like it +135 Vote: I do not like it

    Version without needing to know the DP:

    Choose the throw order for the top $$$k$$$ floors.
    For the floor below, you get $$$c$$$ choices of either throwing your plane or letting a plane fall from above.
    This happens for all floors except the top floor (which must throw $$$c$$$ planes).

    So in total there are $$$c\cdot(n-1)$$$ choices, and $$$m-c$$$ must be chosen to actually throw planes, thus $$$\binom{c(n-1)}{m-c}$$$.

»
2 weeks ago, # |
  Vote: I like it 0 Vote: I do not like it

B was a really good problem. I wasn't able to submit the right code in time, however I still enjoyed taking my time solving the problem.

»
2 weeks ago, # |
  Vote: I like it 0 Vote: I do not like it

its awsome, Like your previous competitions, this one also had a lot of mathematics!

»
2 weeks ago, # |
  Vote: I like it +36 Vote: I do not like it

div1A >> div1B

»
2 weeks ago, # |
  Vote: I like it 0 Vote: I do not like it

Rating roll back when ? I want to be expert in problem solving

»
2 weeks ago, # |
  Vote: I like it +3 Vote: I do not like it

just curious, who or what is Devyatkino, and how is it related to the 2067C problem?

»
2 weeks ago, # |
  Vote: I like it -6 Vote: I do not like it

Problem D was really interesting theory-wise, pretty cool for an interactive problem to actually be accessible for regular users rather than being 2300+ rated

»
2 weeks ago, # |
  Vote: I like it +25 Vote: I do not like it

A YouTube solution got leaked in the last 10 minutes of Problem E. I don't know much of Div. 1 but in Div. 2 more than 10 people in top 20 have been cheated having the same solution and it might get worse lower down in the standings. Some of the solutions are with comments and exactly same, I don't know how they escaped plagiarism but something needs to be done about these cheaters or else the fun of competitive programming will end soon.

  • »
    »
    2 weeks ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    Yeah completely agreed, Here I try my best to increase my rating and on other side my friend has higher rating because he is cheating.

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

In C, if n = 6, answer is actually 9, not 8, right?

»
2 weeks ago, # |
Rev. 2   Vote: I like it +1 Vote: I do not like it

Solved ABC and had some idea about D. The problems were interesting and the observations were not very obvious. Overall a nice contest.

»
2 weeks ago, # |
  Vote: I like it +14 Vote: I do not like it

After regrading, my submission to Div. 1 A now says "Wrong answer on pretest 4." If my rating is going to be calculated based on this, this feels unfair, since it would not be hard for me to fix my solution to the problem, if I knew this was the verdict. Also, it seems that some people had the opposite problem, where their solutions failed in contest but were correct. I think the correct decision here is to void the contest.

»
2 weeks ago, # |
  Vote: I like it 0 Vote: I do not like it

"It is not difficult to understand that it is optimal to take the leftmost zero in the subsequence" for problem Div2 E why taking left most zero is optimal..?Can anyone explain in detail?

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

    You only need to consider the leftmost 0 for two reasons:

    1) You only need to check the condition until the zero you chose to keep in the subsequence. Everything after that will be valid (min = 0 and mx = 0), so you want to have the 0 as soon as possible.

    2) Checking until the index of the first zero is similar whichever the 0 you decided to choose, so based on the first point you want to check the smallest part possible.

    Consider for example the sequence 2 0 1 0 1, checking the first element is independant of the zero you chose to keep and if you decide to keep the second zero the condition fails on it (mn = 1, mex = 2)

»
2 weeks ago, # |
Rev. 3   Vote: I like it 0 Vote: I do not like it

sevlll777 Could you please tell the testcase where some of the rejudged solutions of Div 1.(A) have failed. Specifically testcase 37 on pretest 2.

»
2 weeks ago, # |
  Vote: I like it 0 Vote: I do not like it

Is there a way to solve the second problem using the frequency array?

  • »
    »
    2 weeks ago, # ^ |
    Rev. 2   Vote: I like it +5 Vote: I do not like it

    305680148

    Yes, of course here is how i solved it in the contest , do check it out bro. you take a frequency array and then check if it appears more than twice , redistribute the excess counts to the next number by increment operation. after that check if all frequencies are even then only it is possible.

    • »
      »
      »
      2 weeks ago, # ^ |
        Vote: I like it 0 Vote: I do not like it

      I understand it now, Thank you very much bro

»
2 weeks ago, # |
  Vote: I like it 0 Vote: I do not like it

can someone please help me why my bfs code did not work

»
2 weeks ago, # |
  Vote: I like it 0 Vote: I do not like it

In problem A of div1, if you use fast read in to read in, and your solution happens to be wrong, when you read -1, you'll get TLE on test 2 for not having end-of-line spaces and line breaks (at least in my tests, I think). In fact, for this reason, I kept thinking yesterday that it was cin/cout that was too slow and wasted almost 45 minutes. I don't know if this problem is present in other interaction problems, but I think it has a big impact on players who are experiencing this problem for the first time, and I think the interactive library should give the correct verdict on the procedure according to the rules. I hope this issue will be revised in the next time.

  • »
    »
    2 weeks ago, # ^ |
      Vote: I like it -21 Vote: I do not like it

    I'd say it's quite a bad habit to use fast I/O method on CF. The only method to avoid such issues is to stop using fast I/O as far as I know.

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

    In which cases your code gets -1? queries seems fine

»
2 weeks ago, # |
  Vote: I like it 0 Vote: I do not like it

Can someone please tell me how did they derive this "(x-y + 1)%9 == 0" formula....I am new please help********

  • »
    »
    2 weeks ago, # ^ |
    Rev. 3   Vote: I like it 0 Vote: I do not like it

    Suppose any number whose last digit is not 9 can have its immediate next number +1 with the last digit thus the first part : x+1==y

    Now the other case if there are 9s at the end of n. Let 1199 then n+1 will be 1200. Here x = 1+1+9+9 and y = 1+2 so (x-y+1) means 1+1+9+9-(1+2)+1 = 9+9. You can see that for numbers which have any number of consequitive 9s at the end the next number's sum of digits will be its sum of digit + 1 minus those consequitive 9s. Thus if (x+1-y)mod9 is 0 it means that we can form n with consequitive 9s at the back. so if it satisfies the this condition x and y are valid.

»
2 weeks ago, # |
  Vote: I like it 0 Vote: I do not like it

Can anyone explain me how the case of last digit is solved for in Problem C.

»
2 weeks ago, # |
  Vote: I like it 0 Vote: I do not like it

1E is a classic trick in CNOI.

I think 1E is easier than 1C in CNOI.

»
2 weeks ago, # |
  Vote: I like it -10 Vote: I do not like it

in C you said you cant explain it briefly! this is the contest for making people to get new ideas , to have fun , to learn new techniques, not for searching the random idea in your head which you cannot even explain briefly. Do you believe you explanation is worth it? CF is being a joke day by day just for problem setters like you who came here to show how cool are they not to set cool problems

  • »
    »
    2 weeks ago, # ^ |
    Rev. 3   Vote: I like it 0 Vote: I do not like it

    Have you read editorial through the end? It's not like I dont explain ideas, it is just a choice of words to justify (or motivate) idea of adding $$$10^x$$$ instead of $$$99.99$$$ in the operations, since it is easier to see how digits are affected in this case. I could just directly explain solution instead, but I believe explaining motivation behind some ideas is also important, and thats what Im trying to do usually, [side note:however I would agree that in D2E solution is not well-motivated, the thought of looking at zeros is pretty random, but] I believe D2C explained well, if not please tell me what is unclear...

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

      How would you solve the problem using bfs?

»
2 weeks ago, # |
  Vote: I like it 0 Vote: I do not like it

In problem 2067D - Object Identification, why is one query insufficient in the second case (when $$$x_1,x_2,…,x_n$$$ is a permutation)?

Is there a case in which one query will give a response $$$>=$$$ $$$n - 1$$$ and the other will not?

Can you provide a counter-example for the one-query approach? thank you :)

  • »
    »
    2 weeks ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    something like

    3
    1 2 3
    2 3 2
    

    Path in graph theoretically can have length of $$$n-1$$$ if it goes through all vertices of the graph ($$$1 \to 2 \to 3$$$ in this case), and if $$$y_i = y_j$$$, Manhattan distance can be also equal to $$$n-1$$$.

    • »
      »
      »
      2 weeks ago, # ^ |
        Vote: I like it 0 Vote: I do not like it

      that's right, thanks!! I thought that the distance between nodes are measured by nodes count not edges count :)

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

B. Two Large Bags

test case:
1
4
1 2 3 4

The editorial code outputs "No".But, is this case should be "Yes"?

update: it's the same content, not sum.....i'm stupid

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

Some thoughts on 2E / 1B. What if we consider the weighted version of this problem? I mean, let every $$$a_i$$$ have weight $$$w_i$$$, and now we need to find not the maximal possible length of a magical subsequence, but the maximal sum of weights in a magical subsequence.

Such version of this problem looks very curious for me. Now we can not just say that the subsequence without zeroes outperforms almost every other subsequence, and we need to go deeper. Seems i have a solution for this version, and it looks really nice (but, ofk, it also might be wrong :) ).

Did anyone have some thoughts like this?

  • »
    »
    2 weeks ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    Hmm, yes, my "solution" was wrong indeed) But the problem statement still looks curious!

»
2 weeks ago, # |
  Vote: I like it 0 Vote: I do not like it

Tutorial for 2067E — White Magic: "(this can be easily done in O(n), calculating prefix-min and suffix-mex is a well-known problem)".
I know how to calculate suffix-mex in O(nlogn), but I didn't know it can be calculated in O(n). What is the idea behind faster solution?

  • »
    »
    2 weeks ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    Ignore elements that are bigger than $$$n$$$ since they are not impacting any suffix mex. and just use counting array for elements $$$\leq n$$$. You can refer to code from submission from editorial.

»
2 weeks ago, # |
  Vote: I like it 0 Vote: I do not like it

The interactor of div1 A seems to have some bugs.I got TLE on the sample but that's impossible.

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

Question about 2067F Bitwise Slides:
1) When x=pref(i-1): There are a total of 3 ways to arrive from (pref(i-1),pref(i-1),pref(i-1)).
2) When x is whatever: We can come from (x,x,pref(i-1)) to (x,x,pref(i)).
Aren't 2) when x=pref(i-1) and third way from 1) duplicates? How can we be sure that we aren't counting the same operation twice?

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

1E can be solved with 1 log, i.e. $$$O((n+q)\log (a_i))$$$

Submission: 306294227

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

    And it's also easier to implement compared with the official segment tree + binary search approach.

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

    FYI (helped with AI translation)


    Solution

    Noticing that Operation 1 is only useful when two barrels contain the same weight of water (otherwise the presence of poison won't affect the result), and the barrels selected in Operation 2 must be confirmed poison-free.

    Initially, we must select two barrels with $$$k$$$ kg of water each and compare them. If poisoned, the process ends. We consider the case where their weights remain equal (i.e., no poison exists).

    At this point, the freely disposable water quantity is $$$2k$$$, denoted as $$$L$$$.
    All operations can be categorized into two types:

    1. Select $$$a_i \le L$$$, then update $$$L \leftarrow L + a_i$$$. (i.e., use $$$L$$$ to obtain a barrel with $$$a_i$$$ kg for comparison)
    2. Select $$$a_i + L \ge a_j$$$ (both $$$i$$$ and $$$j$$$ are unconfirmed), then update $$$L \leftarrow L + a_i + a_j$$$. (i.e., pour $$$a_j - a_i$$$ water into barrel $$$i$$$, then compare $$$i$$$ and $$$j$$$)

    Starting with $$$L = 0$$$, the initial process of finding two barrels with $$$k$$$ kg can be described using Operation 2. Therefore, we discard the first step and solve the problem starting from $$$L = 0$$$ with no confirmed barrels. If we can confirm $$$\ge n-1$$$ barrels as poison-free, output Yes (the last barrel can be determined by elimination).

    We accelerate this process using range doubling decomposition.
    Divide the value range into $$$O(\log a_i)$$$ blocks of $$$[2^k, 2^{k+1})$$$.
    A key property emerges: if any barrel in a block is confirmed poison-free, we can confirm the entire block.

    Proof:
    For a barrel $$$a_i$$$ in block $$$[2^k, 2^{k+1})$$$:

    1. If confirmed via Operation 1: $$$L' = L + a_i \ge 2a_i \ge 2^{k+1}$$$. Thus $$$L'$$$ exceeds all values in this block, allowing confirmation of all barrels via Operation 1.
    2. If confirmed via Operation 2: $$$L' = L + a_i + a_j \ge 2a_i \ge 2^{k+1}$$$. Same conclusion follows.

    For each block $$$[2^k, 2^{k+1})$$$, maintain two multiset to track:

    • Values within the block
    • Minimum differences between adjacent pairs in the block

    Traverse blocks from smallest to largest. If a block contains a confirmable barrel:

    1. Confirm all previous unconfirmed blocks (including this block)
    2. Add their total sum to $$$L$$$

    A block $$$S$$$ is confirmable if and only if:

    $$$ L \ge \displaystyle\min_{i \in S} a_i \quad \text{or} \quad L \ge \displaystyle\min_{\substack{i \in S\text{ and} \\ j \text{ is unconfirmed}}} |a_i - a_j| $$$

    The first condition is easy to check by maintaining the minimum value of each block.

    The second condition requires checking:

    • Differences between adjacent blocks' max/min values (however, if the previous block is confirmed poison-free, it shouldn't be considered, as it has been included in $$$L$$$)
    • Differences within the current block

    which can be done in $$$O(1)$$$.

    Thus, the time complexity is $$$O(n\log a_i)$$$. (because we only traverse each block once)

    Maintain the sum of confirmed blocks and count of confirmed barrels to determine the final answer.

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

    There is another solution with the same complexity

    Use a segment tree

    On position $$$i$$$ maintain the value $$$pref_i - i$$$ where $$$pref_i$$$ is the sum of elements of $$$a$$$ that you can have if you currently have value i. Now we can't get to the $$$x$$$ if min(0, x)$$$ < 0$$$.

    Now look at each pair $$$(a_{i-1}, a_i)$$$ (in sorted array). If you have access to the value $$$a_i - a_{i-1}$$$ then you have access to the value $$$a_i$$$, so you can do add(a[i]-a[i-1], a[i]). You can easily maintain this troughout queries using multiset.

    One more thing, you can see, for example, that this doesn't work for 2 2 4 11 100, because with 2 2 4 we think we can get 11 because $$$11-4=7 \leq 8$$$ but we can't use 4 twice.

    To avoid this do the following:

    If $$$2a_{i-1} < a_i$$$, do add(a[i], a[i])

    Else do add(a[i]-a[i-1], a[i]).

    305735628

»
4 days ago, # |
  Vote: I like it 0 Vote: I do not like it

so difficult

»
3 days ago, # |
Rev. 2   Vote: I like it 0 Vote: I do not like it

Solution for 2067B - Two Large Bags Using Frequency Counts

  1. Create a frequency array to count the occurrences of each number.

  2. If a number appears more than twice, transfer the excess to the next number.

  3. If any number has an odd frequency, print "No".

  4. If all frequencies are even, print "Yes".

Time Complexity: O(n) using frequency counts, making it faster than the sorting-based O(n*log(n)) solution in the tutorial.

Code Implementation: 307574956