Hello Codeforces!
The Algorithms and Coding Club, IIT Delhi (ANCC) in collaboration with Tryst, IIT Delhi invites you all to participate in ICPC-de-Tryst 2025.

ICPC-de-Tryst is an ICPC-style team contest, featuring challenging algorithmic problems to be solved in a span of 4 hours, for teams of up to 3 members.
- Date & Time: Wednesday, March 12, 2025, 19:30 IST
- Mode: Online
- Platform: Codeforces
- Registration Link
- Each participant may use their own computer (no restriction to a single PC per team).
- Prizes: 15k INR total for top 3 Indian teams
Join this WhatsApp group for more updates.
The problems were prepared and tested by Proelectro444, Soumil69, VijayBalaji, lucky__389, mayank69goel, ErrorAssassin, Azm1t, ghoul932, BladeRunner, etherinmatic, MridulAhi.
UPD1: Contest link
UPD2: The Contest is delayed by 30 minutes and will start at 19:30 IST due to registration issues at codeforces. Please register carefully this time, as registrations can't be changed due to some technical issue.
UPD3: Editorial
Good luck and happy coding!
ANCC, IIT Delhi








Contest clashes with cc starters.
We had initially planned to keep it yesterday but was clashing with a CF contest so all submissions would have been in queue which would have spoiled the experience. Also today is the last day of our Tech Fest, so it had to be conducted today :(
I think starting it at 3:30 Pm would be a good idea.
Have mercy on us job peeps man :')
Casually calling me jobless without saying :)
Where's the contest link? when will it be visible??
https://codeforces.me/contestInvitation/2ca92069b86064f34ba695a2ecd35f982a3cf780
Here it is , indeed it was in the WhatsApp group, do upvote
team up?
would you like to join in my team? i am also from nsut, first year.
Plese adopt me. I am a fresher too.
Correct me if I am wrong, but for B, do we divide the array into blocks of size 2 * k and find answers in 3 * (k — 1) for each block? So it takes 3(n/k)(k — 1) operations that are less than 3n.
For each block, we find the aggregate for suffixes and prefixes in k — 1 operations for each half and merge answers from each half in at most k — 1 operations again.
How do you find the required value for each subarray of length k using this? The intended idea is to partition the array in block sizes of k, and finding aggregate for each prefix and suffix of the block, after which we can find value for each subarray of length k in at most 1 query.
Same idea. I meant that we divide the array into blocks of 2*k, calculate prefixes of the right half of size k and suffix of the left half of size k, and merge in 1 query for all k-1 arrays for which we don't know the answer. btw, cool contest!
Can Someone pls Provide Hints/Solution of A.
Since a diverse subarray contains at most $$$500$$$ distinct numbers, any element’s frequency is at most $$$500$$$ in it. Iterate over $$$r \in [1,n]$$$. Maintain a set $$$\mathcal{S}$$$ that stores the last index where each element in the current prefix $$$[1,r]$$$ appears. Maintain an array of length $$$501$$$ where the entry for $$$y$$$ stores the largest index $$$l'$$$ such that $$$\text{max_freq}[l',r] \ge y$$$. Iterate over ranges of $$$l$$$ with fixed value for distinct numbers ($$$x$$$) in $$$[l,r]$$$ using $$$\mathcal{S}$$$. Take the intersection of this range with the range where $$$\text{max_freq} \le x$$$ and add it to answer. The overall time complexity is $$$O(n \log n + n \cdot \max(a_i))$$$.
Thanks;
What's the intended solution of problem C?
Greedily remove subtrees of size $$$\geq k$$$ from the bottom of the tree. Tree is decomposed into chains using HLD to maintain subtree sizes. $$$O(n/k)$$$ segment tree operations are needed to find the value for each $$$k$$$ so overall time complexity is $$$O(n\log^2 n)$$$.
Can you explain how this is $$$O(n * log^2 n)$$$ ? , I simulated this obvious greedy using HLD but my complexity seems to be $$$O(n * log^3 n)$$$ because you remove at most $$$O(n * log n)$$$ edges and for each edge HLD update is $$$O(log^2 n)$$$
Only the chain having the root of the removed subtree needs to be updated. When a chain is no longer useful, then add its remaining node count to its parent chain.
Oh thanks i didn't notice this approach, although I optimized my $$$O(n * log^3 n)$$$ a little bit so it passed but with 3999 ms :P (TL is 4 secs)
is K designed to have tight memory but generous TL?
I can't get rid of MLE on test 36, tried all sorts of memory optimization but can't
Intended is Virtual/Auxiliary tree right?
https://codeforces.me/gym/595453/submission/310268897
Ask chatgpt, just like how you asked it for the code.
Please provide your ANCC club (IIT Delhi) codeforces group link, so that we can solve such more interesting contests.