cry's blog

By cry, 8 months ago, In English

2148A - Sublime Sequence

Solution (written by cry)
Code (C++) (MikeMirzayanov)

2148B - Lasers

Solution (written by cry)
Code (C++) (MikeMirzayanov)

2148C - Pacer

Solution (written by cry)
Code (C++) (litfan)

2148D - Destruction of the Dandelion Fields

Solution (written by cry)
Code (C++) (AksLolCoding)

2148E - Split

Solution (written by cry)
Code (C++) (kwant)

2148F - Gravity Falls

Solution (written by cry)
Code 1 (C++) (cry)
Code 2 (Python) (Vladosiya)

2148G - Farmer John's Last Wish

Solution (written by avighankc)
Solution 2 (written by Jteh)
Code (C++) (Jteh)
  • Vote: I like it
  • +74
  • Vote: I do not like it

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

Fast as light

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

Fast editorial! (please like im farming)

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

I am a noob, I can't understand the rules does it mean that if I haven't participated in 5 previous rounds and solved a Question I won't get rated?

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

Problem E was a beautiful problem for a div 4.

Enjoyed the round.

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

Problem-F: How it works step by step:

Read all the lists Keep track of their lengths. Start building the final list Look at all lists that still have numbers left. From the remaining numbers in each list, pick the list whose numbers are smallest when compared from the current position. Add numbers from that list Take all remaining numbers from that list and add them to the final list. Mark that list as used so we don’t pick it again. Repeat Keep repeating until all lists are used or we have added all numbers. Print the final list This is your combined list that is as small as possible in order. Key Idea: Always pick the next list whose remaining numbers make the smallest sequence possible. Once picked, take all remaining numbers from that list. This is called a greedy approach.

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

B was easy but the problem statement was tricky to understand.

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

super fast editorial !

can any one explained me E i did not get it?

»
8 months ago, hide # |
Rev. 3  
Vote: I like it +1 Vote: I do not like it

Got problem F accepted 10 minutes after the round got completed :( Still ENJOYED the contest :D

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

F is really a good question, a very interesting idea. Unfortunately, I couldn't come up with it during the competition (unhappy)

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

Fast editorial thanks! E and F was awwsome

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

and i was applying line equations and verifying the point of intersection, to get the total intersections for the problem B. :/

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

:(

»
8 months ago, hide # |
Rev. 5  
Vote: I like it +1 Vote: I do not like it

F possible to solve with $$$O(\sum k)$$$ time

Oops, my solution wrong. But anyway this time complexity exist — read: https://mirror.codeforces.com/blog/entry/146112?#comment-1308911

»
8 months ago, hide # |
Rev. 4  
Vote: I like it -20 Vote: I do not like it

Fast editorial fr, fr.

orz to The coder, The myth, The legend, cry

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

problem C was lovely.

loads of love to the writer.

was able to solve 4 questions.

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

Is anyone else having the same messed up rankings as me? AK, penalty time 217, 10th in common standings (but not shown), 69th in friend standings

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

Wrong interpretation for a solution for F, nvm. :)

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

    Interesting idea! So clear, and also have "one pass through the data" vibe!OwO

  • »
    »
    8 months ago, hide # ^ |
    Rev. 3  
    Vote: I like it 0 Vote: I do not like it

    what if we don't check the unique minimum case? will it time fail directly?

    and even if we do check it suppose there are 2 identical arrays(minimums) so leading to no unique element case. In this scenario isn't this method leading to a (mx*n) time algorithm? is that fine? (could you please explain how it runs fine?)

    my similar solution also passed that didn't check for unique case but kept track of when a minimum array ends(since it gives more options) however i am not able to analyse the worst case complexity. During the contest i assumed it will exceed TL. 338529461

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

      This is true. Nice catch.

      The current implementation runs in $$$\mathcal{O}(n \cdot mx)$$$, but it can be improved to $$$\mathcal{O}\left(\sum k\right)$$$ by storing, for each column, only the indices of arrays that actually have an element there. This way every element is processed at most once.

      In the given code, however, $$$mx$$$ and $$$n$$$ are dependent — the worst case occurs when all arrays are identical (same size and same values). Even then, the bound is still manageable, since $$$\sum k = n^2$$$ which means that $$$n = \sqrt(\sum k))$$$ yeilds to $$$\mathcal{O}(\sum k * \sqrt(\sum k))$$$

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

By the way there's a typo in the editorial for E:

"There is can only be one way that all multisets can contain must the exact same elements"

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

how does the order not matter in E? like the order must matter right?

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

will i get rating as it was my third contest ?

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

Hi guys!

This was my first contest using c++, can somebody please explain to me why did my code output 33? https://mirror.codeforces.com/contest/2148/submission/338397788

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

    you call scanf with no address to store it in the loops, read into a dummy variable so that the integers are consumed

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

    Very cool bug, lol. You are getting 33 because scanf is expecting the memory address where to store the int read from the stdin. Since you have not provided any, it just ends up using the register value that was in %rdi earlier. This is undefined behavior, but here it happens to be the address of the variable n. So, all new values are read to n actually. And, since the last value in test case 2 was 32, you have n + m = 32 + 1 = 33. For test case 1, the last value and the original n value both happen to be 1 so it somehow works.

    For quick fix you can replace your scanf lines with scanf("%d", &x);. We are reading new values to x because we have no use for x and these new values. Ideally, you would declare a new int and then read in that.

    Read https://usaco.guide/general/input-output for C++ specific I/O guide.

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

    Thank you both for replying and explaining!

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

Can anyone hack my solution, don't know why it passed even though it is O(k^2logn) for F:

https://mirror.codeforces.com/contest/2148/submission/338467466

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

Can anyone tell me why my code is failing on F. https://mirror.codeforces.com/contest/2148/submission/338500676

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

For problem G, it suffices to only check prime divisors, which lowers the time complexity a lot if you precompute those.

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

    can you explain why prime divisors only is enough

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

      If a non-prime number divides some amount of values, then all of its prime divisors will divide at least as many values as it, so prime numbers are always optimal.

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

        But how does this explain drops? $$$[4,2,1]$$$ for example: yeah, it is covered by just $$$2$$$ but the drop is not represented because $$$4$$$ never exists?

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

          Whenever the gcd drops, lets say it is divided by some number x, all numbers before the drop are now going to be divisible by x when divided by the new gcd, hence it is sufficient to update the counts of all prime divisors of x to be the size of the current considered prefix.

          See submission for details: 338721463

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

    powers of primes

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

    Correct me if i'm wrong, but i don't think it works, here's a counter tc for prime divisors

    1
    2
    4 2
    
    • »
      »
      »
      8 months ago, hide # ^ |
       
      Vote: I like it 0 Vote: I do not like it

      it works. the output will be 0 1. We're not just checking the prime factors but rather the powers of each prime factor. Check my submission

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

        Thanks, i understood how it works from your code, here's a cleaner code that can run faster without maps (small change on editorial's code)

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

    You also would need to check between two powers of a prime divisor, in case: 125 25 5 5 5

»
8 months ago, hide # |
Rev. 3  
Vote: I like it 0 Vote: I do not like it

oops...I failed the E implementation so hard

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

Super fast editorial... Thanks for the contest.loved problem F and happy to solve in the contest

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

I know this is not the place to ask such question, but still: is there anyway I can bypass "crawling" block, so that I will be able to continue hacking submissions?

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

    Apparently there's none; the only way to get unblocked is to just wait. From my experience, you sometimes get unblocked after a few hours, and sometimes blocking persists for more than 10 hours. So yeah, I don't know...

    I agree that it's silly to block someone who eagerly tries to hack solutions in the open hacking phase. Also the warning text is a bit too scary and unhelpful.

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

nvm

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

For some random array is the No. of times does the prefix gcd change almost O(1) ?

i.e # of times [g != __gcd(g, a[i])] this condition occurs found to be O(1) for large random array?

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

Please someone hack my f

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

too short F with python slices. i think it can be hacked

338490282

»
8 months ago, hide # |
Rev. 3  
Vote: I like it 0 Vote: I do not like it

Problem G can be done very easily by just going through each number. Say, gcd till now is g and after adding current number, gcd becomes g', then there are only two cases —

  1. g' == g: In this case, if current element is not part of longest subarray, then answer does not change. If current element is part of longest subarray, i.e. it affects our answer, then g' has to be one of the divisors of current element. Hence ans = max(ans, F[d]), where 'd' is any divisor of current number > g as g'> g and F[] is cumulative frequency of divisors till now.

  2. g'< g: this is best case, we already found best subarray till the last element & current element decreases the gcd which satisfies the problem condition, that's what the problem is asking for!

[submission:https://mirror.codeforces.com/contest/2148/submission/338531912]

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

Problem G can be solved in $$$O(n\log n+\sum_{i=1}^{n}\tau(a_i)). $$$ My submission: 338537949

For each element, we must increment the count of each of its divisors by 1. Then, the problem boils down to finding the maximum count of a divisor such that it is not equal to the number of elements processed so far. Naively, this can be done with a multiset, but the heavy log factor TLEs. So, we can instead build a "buffer" which holds all elements with count equal to the number of elements processed so far (essentially, all elements in the buffer are divisors of the gcd so far). If the current element we process is divisible by some number x in the buffer, x remains. If not, we remove it (it does not divide the gcd anymore). The answer for the prefix is then the maximum of the count of every divisor not in the buffer.

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

Wish there was code for Solution 1 of G because my train of thought was like it. How can the maximum be maintained at O(1) per divisor? It feels like it's mandatory to check all currently counted divisors' count.

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

I don't know why, but I had a stroke reading problem E statement and understanding its meaning

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

I believe my solution for Problem F is $$$\mathcal{O}(\sum k_i)$$$. It's just about maintaining all the possible candidates for the current element. Here is The link.

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

    You mean F?

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

      Oh sorry, changed now.

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

        Umm... isn't there some logarithmic cost for maintaining the valid array pool (you named them candidate)? I didn't understand fully since it's in python, but I believe i implemented a similar solve where for each column, I go through all the "valid" rows that have the minimum element for current index. Makes it $$$O(\sum k \cdot \log k)$$$ for me. Again, not 100% sure for your code, that's why asking.

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

          There are nothing in my code that would cause a $$$\log$$$. You just need to iterate over the whole structure and it doesn't need to be sorted.

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

            I believe I understand now what you did. I'm essentially doing the same thing, but didn't realize that I could get rid of the $$$\log$$$ factor. Thanks.

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

Can someone tell me why is my code failing for F..

https://mirror.codeforces.com/contest/2148/submission/338427667

any failing testcases will be appreciated

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

can someone explain E problem , I didnt understand it

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

Can my G be hacked? ( https://mirror.codeforces.com/contest/2148/submission/338510007 )?

Uses segtrees to find most occurring prime factor, and gets TLE with segtrees of size 2e5. Realised 1e5 works a bit later and got AC with that, but still seems slightly iffy imo.

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

E is much easier than F,i think F is a good problem! btw I solve A-E so slowly because of the bad network I took half of time to load the problem and used m1.cf.com to submit lol

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

These questions are very challenging(For Div4)! My friend's F code has been hacked, haha.

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

Look at Ahmed_Nassar submissions surely they are ai solutions right? They are in the top of the leaderboard

»
8 months ago, hide # |
Rev. 3  
Vote: I like it 0 Vote: I do not like it

Man, what the heck! My Python code for E got a TLE on test case 10 during post-contest system testing. It has the same exact logic and time complexity as the editorial's C++ solution, which feels so unfair! :((

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

Does anyone can tell me why my code is wrong on problem F? I can't figure it out.

Also, why is the indentation of the code so strange when editing, and how can I adjust the tab space?

#include <bits/stdc++.h>

#define int long long

using namespace std;

using vi = vector<int>;

int t, n;

signed main() {
	cin >> t;

	while (t -- ) {
		cin >> n;
		vector<vi> arrs(n);

		int mx = 0;
		for (int i = 0; i < n; i ++ ) {
			int k;
			cin >> k;
			mx = max(mx, k);
			vi a(k);
			for (int j = 0; j < k; j ++ ) cin >> a[j];
			arrs[i] = a;
		}
		
		sort(arrs.begin(), arrs.end(), [](const vi& a, const vi& b) {
			int mn = min(a.size(), b.size());
			for (int j = 0; j < mn; j ++ )
				if (a[j] != b[j])
					return a[j] > b[j];

			return a.size() < b.size();
		});
		
		vi res(mx);
		int pos = -1;
		for (int i = n - 1; i >= 0; --i) {
			const vi& a = arrs[i];
			int ed = a.size() - 1;
			if (pos >= ed) continue;
			for (int j = pos + 1; j <= ed; j ++ ) res[j] = a[j];
			pos = max(pos, ed);
			if (pos >= mx - 1) break;
		}

		for (auto x : res) cout << x << " " ;
		puts("");
	}

	return 0;
}
»
8 months ago, hide # |
Rev. 2  
Vote: I like it 0 Vote: I do not like it

the test case #20 of problem F n=2 but it has only 1 following line? Am I missing something?

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

Why is my solution getting TLE? Is it solely due to the language being Python?

338599674

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

    I assume it is because of Python + using a dict instead of a vector for the counting the elements that are in ur range.

    I assume if you replace that dict, for the counting, with a list it will pass without a problem

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

how the f*ck did i fst my code is literally fkn logically equivilant to the edi like wtf ts pmo sm like ok fine i have fst i dont care, but i literally do not see a single thing wrong with my code and i am not debugging 300 lines of shit to figure ts out. i literally asked like 4 masters to check my code and i still got fst great fucking vegatables ok go downvote me now

k srry for crashout ig

anyways uh can someone tell me whats wrong lol (i seriously got no idea)

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

There is a typo in Problem F:- - Then, ki space-separated integers ai1,ai2,…,aiki follow (1≤aij≤2⋅105). it should be aik instead of aij in the bracket

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

thx for round

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

Could someone help me to understand question F?

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

F-> is anyone knows test case 19 . my code is failing on tc-19

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

Hello programmers!!!!!!!!!!!!!!!!!!!!!!!

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

Can anyone tell me why my code is giving runtime error 338645166 I am checking for out of bound in the loop but still giving error. On my compiler it is giving correct answer but cf judge is giving runtime error

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

Can Somebody explain the editorial of F(Gravity Falls),in simple language, I am having difficulty understanding that

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

    Basically, you can stack the arrays in any order and the arrays must be left-aligned (A longer array on top of a shorter one is also ok). Then, elements in each array will fall down until it touches another element (In other words, no elements are "floating"). Finally, get the elements at the bottom of the stack from left to right and form an array. Let the array be a, your task is to find the lexicographically smallest a.

»
8 months ago, hide # |
Rev. 3  
Vote: I like it 0 Vote: I do not like it

I solved F by O(sum(k) + n)

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

My submission [338493989] was sent earlier (2025-09-13 18:35:43) and judged earlier (2025-09-14 10:27:56) than the similar submission [338456423], which was sent later (2025-09-13 19:25:16) and judged later (2025-09-14 11:23:41). I did not share my code with anyone or make it public. The similarity is coincidental, and I kindly request that this be taken into account.

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

Hey, can someone explain problem F in simple terms. I get the idea, but the implementation is difficult for me to get my head around. I also watched a yt video on problem F which had a different solution, but again, I couldn't understand a part of the implementation. I would really appreciate it if one of you guys could help me out, thank you.

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

In problem E

I’m having trouble figuring out how binary search could be applied here. Could someone please explain or share an outline of how this problem can be solved using binary search?

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

Regarding solution similarity warning

Hello, I would like to clarify the situation regarding the similarity warning for my solution to problem 2148E. During the contest, I developed the solution based on my understanding of standard algorithms and competitive programming techniques. For faster code writing and autocompletion, I used GitHub Copilot integrated in VSCode as an assistant tool to help speed up writing boilerplate code and ensure syntax correctness. At no point did I copy or refer to any solutions from other contestants or any publicly available sources. If there is any similarity with other solutions, I believe it is purely coincidental, as the problem allows for multiple correct approaches derived from well-known methods. I fully support fair play and remain committed to solving problems independently and responsibly. I kindly request the contest admins to consider my good faith efforts and not to ban my account, as I have never intentionally violated the rules. Thank you very much for your understanding and consideration.

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

wow F had beutifull sloution.

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

Hello, my solution 338490913 was flagged for coincidence with another user’s code. I do not know the other participant at all and did not share or receive any solutions anywhere (I compile my solutions offline). I solved the problem independently. The similar part of the code is generic, which I use snippets for, and the core logic seems to be analogous. Please review this case manually. Thanks!

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

I am quite confused in solution 2 of problem G, why the time complexity goes to NlogN + N(cube root (N))?? Is there any formal proof??

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

omaralimm Sorry for tagging you, i saw one of your comment say that you like the Problem G, that is why i am tagging to get some quick reply, so here is my confusion, do you have any idea??

I am quite confused in solution 2 of problem G, why the time complexity goes to NlogN + N(cube root (N))?? Is there any formal proof?? It is quite of confusing to see NlogN term and even the cube root term!

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

    I can prove it.

    Firstly, let's get all the divisors of numbers up to $$$N$$$ using sieve like method before we start solving the testcases.

    That will be $$$O(NlogN)$$$, which comes from this equation — $$$n/1 + n/2 + ... n/n = n*log(n)$$$.

    And the number of divisors of a number $$$n$$$ is $$$cbrt(n)$$$.

    So, we do precomputation with a complexity of $$$O(NlogN)$$$ and solving the testcases with a complexity of $$$O(NcbrtN)$$$.

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

Problem G can be solved with complexity $$$O(n\log A)$$$, where $$$A$$$ is the maximum element.

Let's improve the Solution 2 in the tutorial:

Suppose $$$g_k=gcd(a_1,\cdots,a_k)$$$ and $$$g_{k+1}=gcd(a_1,\cdots,a_{k+1})$$$. If $$$g_k \gt g_{k+1}$$$, then there will be a prime $$$p$$$ satisfying $$$g_{k+1}p\mid g_k$$$.

Let $$$m$$$ be the maximum integer that satisfies $$$p^m\mid g_{k+1}$$$ but $$$p^{m+1}\not\mid g_{k+1}$$$, then we have $$$p^{m+1}\mid g_k$$$. Thus, we only need to try divisors in the form of powers of prime numbers.

Since the number of divisors in this form for a number $$$x$$$ is at most $$$\log x$$$, we get the complexity at the beginning.

My submission: 339058812

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

I feel a bit confused because of the analysis for problem E:"Say our left pointer l is fixed. Until the inequality is satisfied, we will keep increasing the right pointer r. Then, we will add r−l to the answer since all subarrays a[l,l],a[l,l+1],…,a[l,r−1] are satisfied. Then, increment the left pointer by 1 and repeat." Isn't this actually a different method from the code written in the solution? In the method described in the analysis, for each l, we find the largest r such that the subarray [l, r] satisfies the condition, and then we count the subarrays from l to r. But if we implement this method directly, it would require resetting the count each time l changes, leading to O(n^2) time complexity. This method isn't the sliding window technique, right? Am I misunderstanding something or is the analysis wrong?

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

    This is two pointer and the complexity is $$$O(N)$$$,the key is come through a critical observation and also a well know method in dp which is optimization point.
    First any valid subarray must have a boarder located at somewhere between [1,n],more formally any valid [l,r],that r must in [1,n],this lead us to think if we can find when r=i,how many l satisfy then sum up we can get the answer.
    Second,optimization point in dp mean the best transition point,in different condition it may have different meaning,in this problem let opt(i-1) represent the minimum l such that it may form a valid subarray,in other word any l inside [opt(i-1),i-1] will form a valid subarray with i-1,also any l don't in that range will not form a valid subarray,and we can observe when we iterate until i,[opt(i-1),i] is including range [opt(i-1),i-1],so the opt(i) can only greater or equal than opt(i-1) otherwise since we know if opt(i)<opt(i-1) this will lead to a invalid subarray as i mention before

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

The Editorial's second solution of Problem G by Jteh can be optimized further. The $$$N\sqrt[3]{N}$$$ can be internally handled by counting the number of factors in the current iteration which have count equal to $$$i$$$. If this number is lesser than what it was in previous iteration, we simply assume our answer to be $$$i-1$$$ for prefix $$$a_1 ... a_i$$$. The Proof for this is that, the set of such numbers don't see any addition as we move forward. An element from this set is removed at some rounds, thus simply keeping the count and continuing our iteration works.

Submission: 339061514

TC: $$$O(NlogN + NlogA)$$$ where $$$A$$$ is the maximum value of $$$a_i$$$

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

2148 D

Why Wrong answer on test 2?

#include<bits/stdc++.h>
using namespace std;

int main(){
    int tc; cin>>tc;
    while(tc--){
        int n; cin>>n;
        vector<long long> val(n);
        long long total = 0;
        long long minOdd = LLONG_MAX;
        int oddCount = 0;
        for(int i=0; i<n; i++){
            cin>>val[i];
            total += val[i];
            if(val[i] % 2 != 0){
                oddCount++;
                minOdd = min(minOdd, val[i]);
            }
        }
        if(oddCount == 0)
            cout<<0<<endl;
        else if(oddCount % 2 == 1){
            cout<<total<<endl;
        }
        else{
            cout<<(total - minOdd)<<endl;
        }
    }
    return 0;
}
»
7 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

Hello, I want to know that why this code for problem G (using segment tree) https://mirror.codeforces.com/contest/2148/submission/339214294

is NOT GIVING TLE

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

    -

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

      By clicking on link, it is redirecting to solution

      • »
        »
        »
        »
        7 months ago, hide # ^ |
        Rev. 5  
        Vote: I like it 0 Vote: I do not like it

        okk... i can see now....

        understand it!! great solution

        what i was doing for a particular i finding the largest value in the cnt array and if the value == i then find the max element smaller than i. this i achieved by storing 2 values in the node (largest and value smaller than it) -> and merge the nodes accordingly... but it is giving TLE on 6

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

can someone explain why my code is wrong with string implementation, i know the solution using with int, i use string for connect the element in each array, i think i do wrong in comparing but i dont know why... i want to know my mistake but i cant find it... https://mirror.codeforces.com/contest/2148/submission/339787704

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

Problem G is very interesting

»
7 months ago, hide # |
Rev. 5  
Vote: I like it 0 Vote: I do not like it

Is there a code implementation for solution 1 to problem G?

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

I am not getting, for, 2148E — Split, I thought i need to all possible subarray of a and need to check if this is awesome or not. But the solution code directly returning 0 if the whole subarray is not awesome. My question is why not considering other subarrays? Also I am not getting this line: "there is some way to place items outside the subarray such that all multisets contain must the exact same elements (ignoring ordering)." what do you mean by "placing items outside"? help please!!! [user:cry][user:kwant]

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

For Problem 2148E — Split: Reason behind this line in the editorial: return void(cout << 0 << endl); For a subarray [l, r] to be awesome: ∀v, in[v] x k <= cnt[v] But if some cnt[v] is not divisible by k, then we can never achieve: cnt[v] = x x k

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

the normal solution for lasers question?

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

Isn't the expected solution for second testcase for 2148D - Destruction of the Dandelion Fields wrong? Shouldn't it be 12 instead?

cry can you respond to it please.

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

how is E nlogn in editorial solution seems n^2