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

Автор yse, 4 недели назад, По-английски

Thanks for participating in the contest. I hope you enjoyed the problems :)

Rating Predictions
Rate the contest!
Rate the difficulty!

A — Koshary

Hint
Solution
Code (C++)
Rate the problem!

B — Party Monster

Hint
Solution
Code (C++)
Rate the problem!

C — Snowfall

Hint 1
Hint 2
Solution
Code (C++)
Rate the problem!

D — Palindromex

Hint 1
Hint 2
Solution
Code (C++)
Bonus
Rate the problem!

E — It All Went Sideways

Hint 1
Hint 2
Solution
Code (C++)
Rate the problem!

F — It Just Keeps Going Sideways

Thanks to chromate00 for suggesting a modification to problem E, which resulted in this problem.

Hint 1
Hint 2
Hint 3
Solution
Code (C++)
Rate the problem!

G — Drowning

Hint 1
Hint 2
Hint 3
Solution
Code (C++, using ordered set)
Code (C++, using Fenwick Tree and coordinate compression)
Rate the problem!

H — Fallen Leaves

Hint 1
Hint 2
Hint 3
Solution
Code (C++)
Rate the problem!
Разбор задач Codeforces Round 1096 (Div. 3)
  • Проголосовать: нравится
  • +84
  • Проголосовать: не нравится

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

how 11 days ago?

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

The example note in C made me question reality for a moment...

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

Fast editorial

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

Mann ..Stack saved me at the last minute in E

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

Anyone managed to solve H with some greedy simulation ?

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

Thanks for the contest , I just participated out of speed-running first few problems.

Spoiler

btw C is a nice problem.

I looked other problems , They look interesting too.

Congrats on this successful contest .

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

wtf we have nearly identical solution even the naming convention for C this is my submission holy shit i hope i don't get banned lol.

373106639

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

Thanks for the insanely fast editorial, and for the good problems you have put up in the contest!

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

I'm genuinely impressed with problem G, how can one come up with that idea?

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

glad to know that there's solution without using Fenwick Tree/Segment Tree in problem F.

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

who used complex Manacher algorithm for D or just dumb me :D

»
3 недели назад, скрыть # |
Rev. 5  
Проголосовать: нравится +11 Проголосовать: не нравится

Answer to the $$${Bonus}$$$ $$${Problem}$$$ $$${D:}$$$

My approach uses greedily finding the longest palindromic subsegments, but the concept of this approach works for the idea discussed in the Editorial as well.

Since there are $$${exactly}$$$ $$${2}$$$ occurrences of each element in the array, therefore the number of pairs which are equal and of the form $$$a_{i}=a_{j}$$$ is only $$${n}$$$.

Also, since the $$${positions}$$$ of each element is $$${fixed}$$$, therefore, for each $$${center}$$$, if you find palindrome with that center, there are $$${unique}$$$ set of palindromic pairs.

If we iterate on the array, and at the current index we try to find the palindromic pair of this element. If the palindromic pair is at an index $$${j \geq i+1}$$$, then we check for each pair $$${(i, j)}$$$ $$${,}$$$ $$${(i+1, j-1)}$$$ $$${,}$$$ $$${(i+2, j-2)}$$$ $$${,}$$$ $$${....}$$$ $$${,}$$$ $$${(i+k, j-m)}$$$, where $$${i+k \leq j-m}$$$. While checking we will also mark them as visited in a visited array.

If at any point we get to know that this selected subsegment is not palindromic we simply just increment $$${i}$$$ to the index where the palindromic condition first failed, i.e., $$${i=x}$$$, where $$${a[x] \neq a[y]}$$$ for some indices $$${x}$$$ and $$${y}$$$ during the checking of palindromic condition. After incrementing, check for other possible palindromic subsegments by repeating the process.

But, if we find that the selected subsegment was a palindrome, then we iterate on the visited array from $$${0}$$$ to $$${n}$$$, and store the maximum $$${mex}$$$ found yet. Then we increment the $$${i}$$$ to $$${j+1}$$$, where $$${j}$$$ was the index of the palindromic pair of the element at index $$${i}$$$.

We increment $$${i}$$$ to $$${j+1}$$$ because we have found the longest palindromic subsegments greedily, and since there are $$${exactly}$$$ $$${2}$$$ occurrences for each element in the array, therefore $$${any}$$$ subsegment of the palindromic subsegment $$${(i, j)}$$$ cannot be present in any other palindromic subsegment.

Hence, we only are iterating on the array just $$${once}$$$ and we visit each and every element just $$${once}$$$. Therefore, only $$${O(n)}$$$ operations are performed in greedily finding the longest palindromic subsegment.

Now, talking about the finding of $$${mex}$$$. Since $$${0}$$$ can be present in $$${at}$$$ $$${most}$$$ $$${2}$$$ palindromic subsegments, therefore, for all other palindromic subsegments the $$${mex}$$$ can be found in just $$${one}$$$ operation $$${( mex}$$$ would be zero in that case $$${)}$$$.

$$${At}$$$ $$${most}$$$ $$${2}$$$ subsegments will take $$${O(n)}$$$ time to find their $$${mex}$$$, therefore in total it takes $$${O(2*n-2+2*n)}$$$ $$${=}$$$ $$${O(n)}$$$.

Therefore, the total number of operations turn out to be $$${O(n) + O(n)}$$$ $$${=}$$$ $$${O(n)}$$$.

My submission uses the same idea.

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

can fentree be used in E like in F

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

Problem F was a modification/extension of problem E. This is the first time I have seen this sort of "multi part" problem in a codeforces round despite it being quite common in national/international Olympiads. Personally, I find these sorts of problems quite enjoyable. Kudos to the problem authors.

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

for the bonus of problem D

I exactly solved the problem like that but for the proof my intuition told me this is correct <3

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

..

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

for the bonus of problem D

This fits the time limit because i got Accepted for same idea

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

Instant tutorial, the contest was great, and the author is Egyptian!!!

I can't ask for a better thing, thank you, yse

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

Why is it not necessary to have at least one of $$$a_l$$$ or $$$a_r$$$ to be positive in a good subarray? (Problem G)

»
3 недели назад, скрыть # |
Rev. 2  
Проголосовать: нравится +9 Проголосовать: не нравится

instead of making suffix min array in problem E, we can simply track the max gain by maintaining two state variables...

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

hmm... what if we want to maximize the number of subarrays that are divisible by 6 in problem C? And what if the number by which the product of the array numbers should be divided is arbitrary? It sounds interesting. Thanks for the contest.

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

    interesting

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

    To maximize the number of subarrays containing at least one occurrence of $$$x$$$, you can formulate the problem as follows:

    Let the number of occurrences of $$$x$$$ be $$$k$$$. These $$$k$$$ elements divide the array into $$$k+1$$$ segments of lengths $$$x_1, x_2, \dots, x_{k+1}$$$. The number of subarrays that include at least one $$$x$$$ is:

    $$$\sum_{1 \le i \lt j \le k+1} x_i x_j$$$

    This is a known optimization problem where we use the identity:

    $$$\left( \sum_{i=1}^{k+1} x_i \right)^2 = \sum_{i=1}^{k+1} x_i^2 + 2 \sum_{1 \le i \lt j \le k+1} x_i x_j$$$

    Since the total sum of elements $\sum_{i=1}^{k+1} x_i = n-k$ is constant, maximizing the sum of pairwise products $$$\sum_{1 \le i \lt j \le k+1} x_i x_j$$$ is equivalent to minimizing the sum of squares $$$\sum_{i=1}^{k+1} x_i^2$$$ which is minimized when the elements are distributed as evenly as possible ($$$x1 \approx x2 \approx x3 \approx \dots \approx x_{k+1}$$$).

    As for the divisors of $$$x$$$, i believe grouping them together in contiguous blocks to act as new singular elements is optimal though i couldn't prove it.

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

I realised the solution for E in the last 10 minutes but ran out of time :( Solved it 15 minutes later though :P

This was a fun first contest

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

contest was fun . feels like a div 3 contest. C was interesting for me. couldnt solve d and e but i saw e problem earlier contest. overall the contest was fun. i hope everyone was satisfied with contest

»
3 недели назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится
Proof of Bonus D
»
3 недели назад, скрыть # |
Rev. 2  
Проголосовать: нравится 0 Проголосовать: не нравится

In F I used difference array to track the sum of all position which contains height x, and after it I check how many blocks finally will be in right side, we can easily find their positional sum. and the answer without removing any block will be sum of all height's answer which is their final positional sum — initial sum.

void solve() {
	ll n;
	cin >> n;
	vector<ll>a(n);
	for (auto &it : a)cin >> it;

	vector<ll>b(n + 2);
	ordered_set st;
	for (int i = 0; i < n; i++) {
		b[1] += i + 1;
		st.insert(a[i]);
		b[a[i] + 1] -= i + 1;
	}

	for (int i = 1; i <= n + 1; i++) {
		b[i] += b[i - 1];
	}
	vector<ll>c(n, 1e8);
	ll mn = 1e8;
	for (int i = n - 1; i >= 0; i--) {
		mn = min(mn, a[i]);
		c[i] = mn;
	}

	ll sum = 0;
	for (int i = 1; i <= n; i++) {
		ll t = st.order_of_key(i - 1);

		ll tot = n * (n + 1) / 2;

		ll r = n - t;

		ll prev_sum = r * (r + 1) / 2;

		sum += tot - prev_sum - b[i];

	}

	ll mx = sum;

	for (int i = n - 1; i >= 0; i--) {
		ll t = st.order_of_key(a[i] - 1);

		mx = max(mx, sum + t - (n - i));

	}

	cout << mx << endl;

}
signed main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL); cout.tie(NULL);

	int t;
	cin >> t;
	while (t--) {
		solve();
	}
	return 0;
}
»
3 недели назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

for the problem G isn't it just counting inversion with few more conditions, so can't it just be done using merge sort yse ?

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

I have Done D using Brute

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

Suffix minimum idea in E is actually neat !

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

I can't code, can't find a job, can't have GF, what I can do god, Please save me.

Started CP at the age of 24 being a unemployed, who is aiming to become CMaster at CF.

Fingers crossed :X)

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

My apparch for F (Segment Trees)

Used a lazy segment tree to track, for each element, how much distance it can move based on how many columns to the right support its height.

While iterating right → left, updated this tree to maintain:

for each height h → count of future columns with ≥ h

and used it to compute total movement (ans).

Used a second segment tree to maintain frequency of heights (prefix counts).

This second tree is used to simulate removing one element, by counting:

how many elements (heights ≥ a[i]) gain +1 movement

(inversion-like counting).

Final answer:

base movement + best gain from removing one index

code in java:- https://mirror.codeforces.com/contest/2227/submission/373194545

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

D can be solved using binary search. We can find if ans is atleast x+1.in O(n)

If ans is atleast x+1 , means all ele 0 to x are present , thus get both the positions of x. Now 2 possiblities , Both x are present in our palindrome or Only one.

For both x case , we have both position of x , hence find its centre and expand palindrome as much as possible and check if all elements from 0 to x are present. For single x , do same , now centre is positon of x itself. (Check for Both positions of x)

Link -(https://mirror.codeforces.com/contest/2227/submission/373144878)

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

H is great, the edge-perspective idea is interesting.

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

I think my solution is the same as Bonus Problem D: 373133653, instead of brute-forcing all over the center, i did brute-force from the boundary.

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

    Since each element appears exactly twice. Each value can only be in at most 3 different situations (they can be the matching pairs, or they can be the center). If they are the matching pairs, they can only be visited exactly one times. If they are the center, they can be visited by other element at most 2 times. This gives us O(N) solution.

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

Can anyone explain the solution to the Bonus question of D ?

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

By the way, G is solvable without having to use PBDS / segtree structures, which is helpful for easier implementation

If we twist the perspective a little bit from the provided solution, then pref[l-1] < pref[r] when l is odd, and pref[r] < pref[l-1] when l is even. Notice how in both cases, the smaller side (l-1 and r respectively) are even, and the larger sides are odd. And in each case, r appears later than l-1 and vice versa. Since l-1 and r are different parity, they cannot be equal and hence each case goes either in the 'smaller' or 'larger' category, which these two criteria fit exactly. This means that we can just search for the number of EVERY pref[#odd] (regardless if the index is larger or smaller than that of the even index) that are larger than each pref[#even]. Since this requires no element addition or subtraction, this can be done with sorting + binary search.

Implementation

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

E and F are amazing!

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

this was my first contest, letsgo

solved a and b, and almost solved c, didn't know how to sort numbers that aren't divisible directly by 6, gotta work on my math

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

what am i doing i tried to maximise the subarrays in C

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

the persons who use ai , their family all died already btw, an excellent contest

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

a similar problem after c?

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

an elegant solution for F :) 373205287

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

in problem D, why couldn't we check if there is a palindrom bitween the tow zeros ,then if there is we check the number on the tow sides of it to make it longer, otherwise we assume that every zero is the center of the palindrom and the answer will be the maximum mex of each of the palindrims? I hope you understand my quastion '_' ^_^ 2227D - Palindromex

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

i got braingasm after solving A and B

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

Wow, this was my first contest. Solved problems A, B and C smoothly, struggled in D.

But a great experience overall!!!

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

can it be said for D given the constraints that two palindromic subarrays cannot intersect unless one is completely inside the other, and then we can do a brute force on all palindromic subarrays which cant be extended by adding one element on each side? the only exception i can think of is a subarray of the form abab which can still be handled within the code

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

yse Why has my rating not updated for this round? Why does it show a delta of 0?

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

The problems are interesting.

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

guys i made it :DD

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

I think there's a typo in the "Hint 2" of problem E, it should be "The number of rows/cubes that stay in column i is exactly the suffix minimum s_i."

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

good contest

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

I used a Fenwick Tree for all of problems E, F and G.

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

SegmentTreeforces

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

in G what sort of intuition would lead one to guess that alternatingsum>0 is a sufficient condition?

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

I did problem F completly differently

If you look at $$$a[i]$$$ and some block at height $$$y \leq a[i]$$$, the number of times that that block contributes to the total motion is the number if $$$j \gt i$$$ such that $$$a[j] \lt y$$$. If we loop through the array backwards and mantain a histogram $$$h[x]$$$ of the number of times $$$a[j] = x$$$ for $$$j \gt i$$$, then the number of times a block at height $$$y$$$ contributes to the motion is

$$$h[y-1] + h[y-2] + h[y-3] + \dots$$$

$ Adding this up for all $$$y \leq a[i]$$$ ands, the contribution is

$$$h[a[i]-1] + 2h[a[i]-2] + 3h[a[i]-3] + \dots = \sum_{k=0}^{a[i]} (a[i] - k) h[k] = a[i]\sum_{k=0}^{a[i]} h[k] - \sum_{k=0}^{a[i]}kh[k]$$$

$ Finally we can mantain two fenwick trees representing sums of $$$h[k]$$$ and $$$kh[k]$$$ to get the answer. You can get the maximum increase from decrementing one $$$a[i]$$$ with the same method

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

KAN MikeMirzayanov

Cant we do anything about blatant cheaters?

We can easily spot cheaters in this contest.

For example, cookingDSA is clearly using AI solutions in this contest.

Are there going to be any updates in the near future regarding anti-cheat tools, etc.?

If not, we can float a blog where people can share their ideas so that cheaters will be reduced.

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

First time upsolved all the problems of a Div-3 round!! Problem H was most interesting and only painful problem for me.

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

How to solve H if the set S contains all vertices of the tree?

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

For problem H, there is also a sneaky dp solution which somehow passes without TLE

I basically try to root the tree at each non leaf node and then try to calculate the best possible cost for that root.

373383493

This solution TLEs if you try to root the tree also on leaf nodes

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

H is so confused

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

the solution for H is so confused you said If cnt[u], is even, all leaves inside this subtree can be paired with each other internally. This edge does not need to be crossed by any path. so what about the sons of vertex u get used already, then u become the new leaf ? and cnt[u] = (adj[u].size() == 1); is so confused , what ru cal for ??? obviously not cal for the num of leaves

you said: let cnt[u] be the total number of leaves in the subtree rooted at u but yoru cnt[1] equal to 3 on sample 1, obviously the num of leaves is 2 who can explain this for me plz!!!

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

    root in 1 . if 1 sons of vertex u get used , another sons of this vertex u have been paired with this . every node (expect root) have 1 father , so if adj = 1 , we expect father node cause adj = 0 , this is leaf

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

      thank you! now i have solved the problem, i misunderstood the definition of the leaf node, , ans the cnt of nodes is only, no matter with the root, thanks a lot btw, i dont read this sentence of the problem : this set is determined from the original tree and does not change, my bad XD

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

I love problem G

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

C