awoo's blog

By awoo, history, 14 months ago, translation, In English

2144A - Cut the Array

Idea: BledDest

Tutorial
Solution (BledDest)

2144B - Maximum Cost Permutation

Idea: BledDest

Tutorial
Solution (BledDest)

2144C - Non-Descending Arrays

Idea: BledDest

Tutorial
Solution (Neon)

2144D - Price Tags

Idea: BledDest

Tutorial
Solution (adedalic)

2144E1 - Looking at Towers (easy version)

Idea: Roms

Tutorial

2144E2 - Looking at Towers (difficult version)

Idea: Roms

Tutorial
Solution (BledDest)

2144F - Bracket Groups

Idea: BledDest

Tutorial
Solution 1 (awoo)
Solution 2 (awoo)
  • Vote: I like it
  • +50
  • Vote: I do not like it

| Write comment?
»
14 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

is there any way to solve problem D in $$$O(n \sqrt{n})$$$, no right?

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

      Looks $$$O(n \cdot \log n)$$$ to me. No way $$$O(n \cdot \sqrt{n})$$$ would pass because my $$$O(n \cdot \log n \cdot \log n)$$$ TLEd.

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

        $$$O(n^2)$$$ with heuristics passes. Should be possible to hack it though if anyone is interested.

        https://codeforces.me/contest/2144/submission/338807854

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

          I think this is $$$O(n \sqrt{n})$$$ at worst. The if-statement containing the inner loop for $$$j$$$ is started only $$$O(\sqrt{n})$$$ times because you run it only if $$$count_i \gt cnt0$$$, and you update $$$cnt0$$$ with $$$count_i$$$. Since the sum of all $$$count_i$$$ is at most $$$n$$$, then $$$count_i$$$ will be greater than $$$cnt0$$$ only $$$O(\sqrt n)$$$ times.

          Maybe it's possible to prove even better complexity.

          upd wait, I was wrong. I can't prove that the sum of $$$count_i$$$ is $$$O(n)$$$, but I can prove that it's $$$O(n \log n)$$$. This would result in a complexity of $$$O(n \sqrt{n \log n})$$$.

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

        I think you will be astonished when you realize that $$$2\cdot (\log_2 n)^2 \gt \sqrt{n}$$$ for all $$$2 \le n \le 500\,000$$$

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

      That still o(nlogn) bro

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

        Seems you are right. Didn't though about complexity really, thought that it just will work.

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

Problem E2 can be solved without any data structure more advanced than Fenwick tree (which supports increasing some value by $$$1$$$ and get a prefix sum of values).

$$$dp_i$$$ is the number of subsequences on prefix till $$$i$$$ such that the last element picked is $$$a_i$$$ and it's a record. Then $$$dp_i = \sum_{j \lt i: a_j = previousRecord} dp_j 2^{no. \ k: j \lt k \lt i, a_k \le a_j}$$$.

Let's introduce two arrays $$$le_i$$$ and $$$pr_i$$$. $$$le_i$$$ is the number of positions $$$j \le i: a_j \le a_i$$$ for $$$pr_i$$$ we would replace $$$a_i$$$ with the previous record.

Then $$$dp_i = \sum_{j \lt i: a_j = previousRecord} dp_j 2^{pr_i - le_j}$$$

$$$\frac{dp_i}{2^{pr_i}} = \sum_{j \lt i: a_j = previousRecord} \frac{dp_j}{2^{le_j}}$$$

So one can just maintain the sum of $$$\frac{dp_j}{2^{le_j}}$$$ for all records.

$$$le_i$$$ and $$$pr_i$$$ can be calculated with Fenwick tree.

338782926

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

    Hey Noobish_Monk, if you don't mind, could you explain this code ... only explaining the filling of pref[ ] part will be enough ( You can assume, I know Monotonic stack stuff, Fenweek tree and Coordinate compression ). Thank you!

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

For D:

First attempts. After fixing a value of x I tried to get the answer “almost in O(1)” — somehow compute the total new prices and the printing penalty in one go. In practice, without grouping items by their target price p, you keep losing track of what you’re adding to revenue vs. what you’re paying for extra labels. A full rescan over all items costs O(n) per x, which is too slow.

Think like a sieve. I remembered the Sieve of Eratosthenes: the work on step i is about N/i, so the total is N log N. Same philosophy here: on step x you process buckets — contiguous price ranges of width x. There are about A/x buckets. If you pre-aggregate once (prefix sums) so each bucket costs O(1), then the total over all x is A * (1/2 + 1/3 + …) = A log A. The analogy is simple: the sieve marks multiples; we “mark” contiguous ranges. In both cases, organizing work by natural groups gives you a harmonic series instead of chasing impossible O(1) per step.

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

$$$\log n$$$ is not real, it can't hurt you.

Got bit by it cause my solution for D was $$$O(n \cdot \log n \cdot \log n)$$$.

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

Title: Appeal: False Plagiarism Flag for Submission 338775909 (Problem 2144D) Hey MikeMirzayanov awoo adedalic Neon Roms BledDest, My handle is ishowguts. Submission 338775909 for problem 2144D was flagged as coinciding with submission 338766632, but I wrote all the code myself offline in VS Code with no collaboration. Development timeline & evidence: * First save: September 15, 2025 at 9:03 PM IST * Last save: September 15, 2025 at 9:54 PM IST * All file “last modified” timestamps in my local workspace reflect this period * I never uploaded or shared my code on any public IDE or platform during development * I implemented each function and logic block manually in this session 
Please manually review both my code and the other submission. If you need any more evidence, I am ready to provide it.awoo Thank you for your time and understanding.


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

    You are not fooling anyone. And, file stats can be spoofed. Your account is too new, and rising too fast. You submissions from previous contests are skipped too. So, stop spamming in each thread.

    P.S. I think CF should, optionally, allow linking to IDs on other CP platforms to prove authenticity.

    • »
      »
      »
      14 months ago, hide # ^ |
       
      Vote: I like it -18 Vote: I do not like it

      This is my 2nd I'd and for the authenticity part just check my codes and if you notice that something is fishy you can dm me or in the next contest maybe we can hop on discord call and solve the questions in front of you, so please don't comment without knowing the full picture and for the last skipped question i submitted the same code of my main account in this account as unrated at that time I didn't knew that even unrated contest also gets skipped, and when u check for official submissions ull not see any skipped submissions. Thank u.

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

        bro just quit it your code for E1 is basically unreadable almost no one other than some insanely high rated people write code like that, how hard is it learn some basics of CP and then give the contests honestly?

      • »
        »
        »
        »
        14 months ago, hide # ^ |
         
        Vote: I like it +4 Vote: I do not like it
        1. Alts are against the CF rules. Refer to https://codeforces.me/blog/entry/124418

        2. Really, dude? Did you look at both the submissions? All you did was rename some variables and make the formatting worse, somehow, and replaced '\n' with an endl.

        3. if(!(cin >> T)) return 0; what does this even do?

        4. The other account is clearly a temp account, probably made just to help others cheat.

        5. I see you have dabbled in several different programming languages. Python, C, Go, Rust, C++, etc.

        Why are you trying so hard on this lost cause? Did you want that Expert so bad?

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

          and for the alts account at that time i didnt actually knew that making 2nd id is prohibited as many of my uni friends had 2-3 ids at that time, and i did got banned for that particular reason and didnt raised my voice after i got to know

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

            Cheater don't need to explain.... It just makes you look like a joker.

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

Am I the only one who eventually came up with an O(N) solution for C, but doubted its correctness because N <= 100?

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

Why it take yall so long to post the editorial bruh im tryna get educated its an eeucational round twin

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

why c constraints so low if solution is so fast?? I was hoping to see a brute force solution. I like those.

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

I think there is typo in C editorial.. answer is 2^m.. where m tells number of type 1 pairs not number of segment of type 2 pairs.

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

My solution for E1 was slightly different than the one given in the editorial: 339030512

Is it possible to come to an optimization for E2's constraints using this E1 solution?

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

A bruteforce check can also pass F.

code

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

I have a few questions about C editorial. It's stated that "the answer is $$$2^m$$$ , where m is the number of segments of type 2 pairs.", but I think it's misleading as single type 1 pair is independent and can contribute to the result with $$$*2$$$ multiplier, so it's not only about type 2 segments? I don't quite understand the explanation for $$$2^{n-k}$$$ (merges), but the inverted calculation in solution code is more explanatory: $$$2^{k+1}$$$, where extra $$$1$$$ power is for the starting position (we can choose any order) and $$$k$$$ here is the number of such $$$i$$$ such that $$$a_i \geq b_{i - 1}$$$ (we can choose any order for $$$i$$$ position, but subsequent $$$i+1$$$ if it's type 1 pair is dependent on this chosen order and must adapt accordingly, we have no freedom there).

Also, is the following reasoning for "the answer will not change (since the $$$2^n$$$ subsets of indices we are considering will yield the same results after such a transformation, just in a different order)." part correct: we assume that all swaps start from ordered state (all $$$a_i \leq b_i$$$) and answer uniqueness rely on that if there are two swaps for the same position in the end, the result is that there were no swaps performed for $$$i$$$, i.e. the thing that we performed some operations at the beginning doesn't matter because we can revert them and this leads to same answer count?

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

For C, what about the case when a = 4 3 b = 5 7

Then there is no subset of indices after which the array would be in non descending order, but you say a subset would always exist how?