StarSilk's blog

By StarSilk, history, 22 hours ago, In English

2062A - String

Idea: StarSilk. Solution: StarSilk. Preparation: SSerxhs, StarSilk.

Rate this problem
Solution
Code (C++)
Code (Python)

2062B - Clockwork

Idea: StarSilk. Solution: StarSilk. Preparation: SSerxhs, StarSilk.

Rate this problem
Solution
Code (C++)
Code (Python)

2062C - Cirno and Operations

Idea: Yakumo_Ran. Solution: Yakumo_Ran. Preparation: Yakumo_Ran, SSerxhs, mejiamejia.

Rate this problem
Solution
Code (C++)
Code (Python)

2062D - Balanced Tree

Idea: StarSilk, SSerxhs. Solution: StarSilk, SSerxhs. Preparation: SSerxhs.

Rate this problem
Solution
Code (C++)
Code (Python)

2062E1 - The Game (Easy Version)

Idea: Yakumo_Ran. Solution: Yakumo_Ran. Preparation: Yakumo_Ran,mejiamejia,SSerxhs.

Rate this problem
Solution
Code (C++)
Code (Python)

2062E2 - The Game (Hard Version)

Idea: SSerxhs. Solution: StarSilk,SSerxhs,PaperCloud,fallleaves01. Preparation: SSerxhs,mejiamejia.

Rate this problem
Solution
Code (C++)

2062F - Traveling Salescat

Idea: StarSilk. Solution: StarSilk. Preparation: SSerxhs, StarSilk.

Rate this problem
Solution
Code (C++)
Code (Python)

2062G - Permutation Factory

Idea: StarSilk. Solution: StarSilk. Preparation: StarSilk, SSerxhs.

Rate this problem
Solution
Code (C++)

2062H - Galaxy Generator

Idea: StarSilk. Solution: StarSilk. Preparation: StarSilk.

Rate this problem
Solution
Code (C++)
  • Vote: I like it
  • +83
  • Vote: I do not like it

»
21 hour(s) ago, # |
Rev. 2   Vote: I like it +15 Vote: I do not like it

In Editorial of C :

Unable to parse markup [type=CF_MATHJAX]

Fixed

»
21 hour(s) ago, # |
  Vote: I like it 0 Vote: I do not like it

Unable to view Editorial for problem C

»
21 hour(s) ago, # |
  Vote: I like it +34 Vote: I do not like it

We're not beating the speedforces allegations with this one!

  • »
    »
    21 hour(s) ago, # ^ |
      Vote: I like it +32 Vote: I do not like it

    In all seriousness I enjoyed A-C even if they were rather guessable, but there really should have been a problem in between C and D/E1

»
21 hour(s) ago, # |
  Vote: I like it +44 Vote: I do not like it

D>>>>>>>>>>>>>>>>>>>>>E1

»
21 hour(s) ago, # |
  Vote: I like it +5 Vote: I do not like it

nah, no way, I got C wrong cus I forgot to use LL

303138777 and 303120425

  • »
    »
    21 hour(s) ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    same, spent like 20 min trying to find the mistake, but got it eventually

  • »
    »
    21 hour(s) ago, # ^ |
    Rev. 2   Vote: I like it 0 Vote: I do not like it

    same. i spent almost 2 hours + 5 WAs.. T_T

»
21 hour(s) ago, # |
  Vote: I like it +4 Vote: I do not like it

First time i solved a b AND c in div1+2. Hope to get +ve delta :). thank you!

  • »
    »
    19 hours ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    Your consistency is just awesome

  • »
    »
    19 hours ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    Me too! (Although this was my first Codeforces contest...)

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

    yeah I saw your profile too, what a consistent account, keep it up.. really awesome

  • »
    »
    9 hours ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    Can't believe I reached specialist! Ngl I think I will now do a few virtuals and solve 16-1800s now I guess, before my next contest

    • »
      »
      »
      9 hours ago, # ^ |
        Vote: I like it 0 Vote: I do not like it

      Great to see your progress brother. And the consistency is really inspiring. Congratulations for becoming specialist

»
21 hour(s) ago, # |
  Vote: I like it 0 Vote: I do not like it

for B should the condition be ti>2max(i−1,n−i)

»
21 hour(s) ago, # |
  Vote: I like it 0 Vote: I do not like it

I think for C, one could additionally use the fact that in an array of length $$$n$$$, the sum of differences is $$$a_n - a_1$$$. Thus if $$$a_n < a_1$$$, we reverse else not.

»
21 hour(s) ago, # |
  Vote: I like it 0 Vote: I do not like it

In the editorial for B it should be max instead of min

»
21 hour(s) ago, # |
  Vote: I like it +5 Vote: I do not like it
Rating Prediction
  • »
    »
    20 hours ago, # ^ |
    Rev. 3   Vote: I like it +20 Vote: I do not like it

    There should be a row with the average and median. ^_^;

    I like the variance in predictions

    • »
      »
      »
      20 hours ago, # ^ |
        Vote: I like it +6 Vote: I do not like it

      I'd like to update it after the actual rating comes out and calculating the errors together

    • »
      »
      »
      19 hours ago, # ^ |
      Rev. 3   Vote: I like it +12 Vote: I do not like it

      I like the variance in predictions

      On the contrary, I'm surprised that the variance isn't higher, I personally would have rated H < G < E2 (unfortunately, I spent most of the contest debugging my approach for E2).

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

    C clearly had more than expected solves in the contest. shame on these cheaters.

  • »
    »
    17 hours ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    800 800 800 2400 1600 ? 2700 ? ?

»
21 hour(s) ago, # |
  Vote: I like it +14 Vote: I do not like it

The editorial for C and D is not very clear. What does fa mean in D?

»
21 hour(s) ago, # |
  Vote: I like it 0 Vote: I do not like it

not convinced(or did not fully understand) the proof of problem C. please help.

Assuming that in the optimal answer the sequence of operations is 1211121221.

Consider swapping two adjacent operations: 12→21 ... which is equivalent to taking the negation.

so, are we proving that instead of doing 1211121221 we can simply do 1111112222? Then we may need to do negation of all elements based on number of 12 operation swaps?

and of course since 111111 -> no-op we might as well only do 2222?

I think I understand now. However please let me know if I understood something incorrectly. thanks!

  • »
    »
    21 hour(s) ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    No, the argument is that operation 1 simply negates each term of the array, thereby all it does is change the sign of the sum. Thus, it is enough to perform operation 2 and take the absolute value of the sum at each step (Because if the sum was negative then you could have performed operation 1 before and gotten $$$-sum$$$)

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

    Sorry for mixing up 1 and 2. It has been corrected now, and your understanding is correct.

    • »
      »
      »
      20 hours ago, # ^ |
        Vote: I like it 0 Vote: I do not like it

      Got it, Thanks!

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

      But why doesn't it matter what the array looked like before you perform operation 1 or 2? The 12 -> 21 negating sum condition only applies to the sum right. But we can get different sums by performing operation 2 on different arrays (different elements at each index). Am I wrong?

      For example, applying 2 to 1212 gives you a different individual elements than applying it to 2121. Wouldn't it?

      • »
        »
        »
        »
        16 hours ago, # ^ |
          Vote: I like it 0 Vote: I do not like it

        Think 2121 gives same output as 11

      • »
        »
        »
        »
        16 hours ago, # ^ |
          Vote: I like it 0 Vote: I do not like it

        Yeah, I was wondering exactly that, and the editorial lacks so much explanation that you really can't assume that the negative of the array won't generate possibly new (and larger) sums after you apply some other operations on it. That's why I wrote a comment explaining it with proofs of (almost) everything (except trivial things). I think you could like my explanation, so, please, take a look at my comment (somewhere below on this comment section).

»
21 hour(s) ago, # |
  Vote: I like it +9 Vote: I do not like it

I feel like the editorial for B is incomplete, especially for beginners. The most crucial part of the solution is that there never exists a part of the sequence that goes: {i...i+1 ...i... i+1} without visiting both ends of the array which allows one to show that the only optimal sequence is one in which we bounce back and forth from opposite ends of the array.

»
20 hours ago, # |
  Vote: I like it 0 Vote: I do not like it

What is meant by "Since 2 does not change the sum of the sequence" in C's editorial? Doing the operation changes the sum right?

  • »
    »
    20 hours ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    Same as above, sorry for mixing up 1 and 2. I have corrected it, but it takes some time to update.

»
20 hours ago, # |
  Vote: I like it 0 Vote: I do not like it

dp solution of problem C[Check303116516..]

»
20 hours ago, # |
  Vote: I like it 0 Vote: I do not like it

Can anybody explain why this is got WA. I can't understand the editorial for problem C. Here's the submission of c — https://codeforces.me/contest/2062/submission/303119038

»
20 hours ago, # |
  Vote: I like it +1 Vote: I do not like it

B>>>>>>>>>C

  • »
    »
    19 hours ago, # ^ |
      Vote: I like it +3 Vote: I do not like it

    I did B in like 5 min and 40 minutes for C, why people with good ratings are fumbling in B? even CM in friendlist got 3WA on B. Overthinking?

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

    B is nice problem , but it was not harder then c

»
20 hours ago, # |
  Vote: I like it 0 Vote: I do not like it

Quite helpful. Thank you

»
20 hours ago, # |
  Vote: I like it -35 Vote: I do not like it

poor contest and even worse editorial

»
20 hours ago, # |
  Vote: I like it +54 Vote: I do not like it

The editorial for D is made for people who have successfully solved the problem in the contest. The editorial is not clear at all !

  • »
    »
    19 hours ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    Even I feel so,Can Someone Please provide a more detailed explanation.

    • »
      »
      »
      11 hours ago, # ^ |
        Vote: I like it +22 Vote: I do not like it
      • The operation can be rephrased as follows: choose any edge in the tree, consider the two subtrees resulting from removing that edge, choose one of those subtrees, and increment all values in it by 1.

      • Consider any assignment of initial values to the nodes. For any two nodes connected by an edge, if they have different initial values, they can only become equal if we perform the operation selecting the edge between them, and incrementing the subtree of the smaller node.

      • Now, consider what the value of node i will be in the end. We can find this value by rooting the tree at i. The final value after the tree becomes balanced will be val[i] + sum(max(0, val[u] — val[par[u]])). Basically if val[par[u]] < val[u], we will need to increment everything above u.

      • We can prove that actually rooting at any node j != i will yield the same result as i. One way to prove this is by considering what happens to the result when we move from i to a neighbor.

      • Finally, this means we can just root arbitrarily, and greedily minimize sum(max(0, val[u] — val[par[u]])).

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

        I hope there was an option to pin a comment!

        This really helped. Thanks :)

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

    I think it's quite clear for me. Can u explain which part made u confused pls?

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

      Hi, I really don't understand the second part of the editorial. I don't see how we get to the conclusion that au should always be no less than the maximum value of its child nodes av. The proof involves something about decreasing ai and I don't know why do we need to decrease anything?

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

        hmm just have a look to the formula ig. let u be the father and v be one of its child,and it's $$$\sum \max(a_v-a_u,0)$$$. let $$$M$$$ be the maximum value of a's among all these $$$v$$$. if we have $$$a_u$$$ smaller than $$$M$$$, just consider what will happen if we "push" the value of $$$a_u$$$ to bigger side(and of course,smaller than $$$r_u$$$). if we set $$$a_u\rightarrow a_u+1$$$, the value of $$$\sum \max(a_v-a_u,0)$$$ will decrease at least one, while the value of $$$\max(a_u-a_{fa},0)$$$ will increase at most one. thus it's not worse than the previous $$$a_u$$$. so it's always optimal to set $$$a_u$$$ bigger when $$$a_u\le M$$$, which lead to the observasion in the editorial.

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

        "decrease" means comparing taking the maximum with maximum -1

    • »
      »
      »
      3 hours ago, # ^ |
        Vote: I like it 0 Vote: I do not like it

      Thanks, but it's okay now. One of my friends already explained it to me.

»
18 hours ago, # |
  Vote: I like it +12 Vote: I do not like it

Please don't use symbols that are hard to understand in editorials like in E1 for example: w,dfn,nfd,pre,suf,low

I am really trying to understand the solution, but I can't really fathom it due to them.

  • »
    »
    18 hours ago, # ^ |
      Vote: I like it +3 Vote: I do not like it

    Yes. I can't identify/understand which algorithm is being used in the solutions for E1, and the variable names are far from helpful.

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

      low is definitely not a good name as a variable since it collides with the low in tarjan algorithm. maybe using end or ed will be better?

      • »
        »
        »
        »
        3 hours ago, # ^ |
          Vote: I like it 0 Vote: I do not like it

        For people learning tarjan algorithm, they often come up with low because it has similar operations (max the dfn).

        dfn stands for dfs number, which is the order of the DFS process in the algorithm. e.g., dfn[root] = 1.

        low stands for the maximun dfn in the subtree. e.g., low[root] = n.

        I use low as the variable name too and I just come up with the name myself. Is this a coincidence?

        • »
          »
          »
          »
          »
          119 minutes ago, # ^ |
            Vote: I like it 0 Vote: I do not like it

          well maybe it's just different to everyone :D

  • »
    »
    13 hours ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    Not sure why you're being downvoted. I thought the same thing.

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

    I am also not able to make sense of techniques used to find greater elements in subtree from the code, but now the editorial has been updated and it explains what they are doing.

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

      It is actually pretty clear now after they updated.

»
18 hours ago, # |
  Vote: I like it 0 Vote: I do not like it

Can someone explain why this code fails:

https://codeforces.me/contest/2062/submission/303155437

»
18 hours ago, # |
  Vote: I like it +1 Vote: I do not like it

Can someone tell me why it doesn't get TLE? I literally brute-forced the operations and memoized the array itself. Submission Thanks

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

    All the second operation does is multiply the array by -1 after the next operation of the first type, this means applying the second operation twice undoes itself no matter how many operations of type one are performed inbetween. Hence you only have 2*N states.

»
18 hours ago, # |
  Vote: I like it +10 Vote: I do not like it

I somehow misread the problem B and thought we need to spend an additional second if we want to reset the clock. Does anyone know if this version of the problem is solvable?

  • »
    »
    16 hours ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    I'm pretty sure the strategy of simply walking back and forth still is optimal, so you can solve the problem by updating the length of the walk as you have to reset an additional clock each cycle.

    • »
      »
      »
      15 hours ago, # ^ |
        Vote: I like it 0 Vote: I do not like it

      It doesn't really work, e.g. in test like 10 100 100 100 100 you can just restart "big" clocks one by one between restarting the small one and the answer would be YES, whereas your strategy fails.

»
16 hours ago, # |
  Vote: I like it 0 Vote: I do not like it

Below I explain the solution to exercise C, doing exactly what the editorial didn't do.

Let's call the reverse instruction as '1' and the difference instruction as '2'. Let's create a new instruction, the "negative" instruction, that I will call from here on as '3'. That instruction multiplies each element of the input array by -1.

Theorem 1) Applying operation 1 two consecutive times is the same as not doing anything (proof omitted)

Theorem 2) Applying operation 3 two consecutive times is the same as not doing anything (proof omitted)

Theorem 3) Applying operation 1 does not change the sum of the input array (proof omitted)

Theorem 4) Applying operations "12" to a sequence is the same as applying operations "231".

Proof:

Let the input array be [a1, a2, a3, ..., an]. Applying "12" on it leads to:

After 1: [an, a(n-1), a(n-2), ..., a1]

After 2: [a(n-1)-an, a(n-2)-a(n-1), ..., a1-a2]

Applying "231" to [a1, a2, a3, ..., an]:

After 2: [a2-a1, a3-a2, ..., an-a(n-1)]

After 3: [a1-a2, a2-a3, ..., a(n-1)-an]

After 1: [a(n-1)-an, a(n-2)-a(n-1), ..., a1-a2]

So, the sequences of operations "12" and "231" are equivalent.

Theorem 5) Applying operations "23" to a sequence is the same as applying operations "32".

Proof:

Let the input array be [a1, a2, a3, ... an]. Applying "23" on it leads to:

After 2) [a2-a1, a3-a2, ..., an-a(n-1)]

After 3) [a1-a2, a2-a3, ..., a(n-1)-an]

And applying "32" to [a1, a2, a3, ... an]:

After 3) [-a1, -a2, -a3, ..., -an]

After 2) [a1-a2, a3-a2, ..., a(n-1)-an]

So, the sequences of operations "23" and "32" are equivalent.

===================

With those theorems in hand, let's solve the exercise.

Let s be any sequence of operations that leads to the maximum possible sum. For example, s may look something like this:

s = 11112221212212112111

According to Theorem 1, I can remove every pair of consecutive 1's, which would give me the following sequence:

s = 222121221221

According to Theorem 3, I can remove the last 1 of the sequence:

s = 22212122122

Now, from the left to the right of the sequence, let's change any appearance of "12" to "231". That won't change the final sum because Theorem 4 says those instructions are equivalent. If, while changing "12" to "231", we end up with consecutive 1's, we simply remove them (because of Theorem 1). If we end up with a 1 on the end, we simply remove it (because of Theorem 3). Below I simulate that process:

s = 22212122122

s = 222231122122 (Theorem 4)

s = 2222322122 (Theorem 1)

s = 22223222312 (Theorem 4)

s = 222232223231 (Theorem 4)

s = 22223222323 (Theorem 3)

As you can see, we ended up with a sequence made only of 2's and 3's. Now, let's apply Theorem 5 several times and move all the 3's to the end:

s = 22222222333

And now let's remove consecutive pairs of 3's, because Theorem 2 allows us to:

s = 222222223

This simulation gives us a general idea of what any optimal sum sequence looks like: it is either:

  • An empty sequence (s = "")

  • A sequence of 1 or more 2's followed by none or only one 3 (s = "222...2223", s = "22...2", etc)

Now, our algorithm should simply try all of those sequences and grab the one with the highest sum, as shown here: (303162845)

»
15 hours ago, # |
  Vote: I like it 0 Vote: I do not like it

is there any solution for E2 using small to big and segment tree

this is my attempt for this problem. if anyone can explain why my code gives me wa or gives a corner case for my code thanks.

https://codeforces.me/contest/2062/submission/303162086

»
13 hours ago, # |
  Vote: I like it +10 Vote: I do not like it

Sadly i was not aware that if we resubmit a accepted qestion then the time of resubmition will be considered for that problem and my rank droped by 4000.

»
13 hours ago, # |
  Vote: I like it 0 Vote: I do not like it

Can anyone recommend me some resources to solve E1? I got the idea in the contest but the editorial isn't clear about how to achieve the idea. Looking at others solutions, I feel like there's a gap in my knowledge somewhere on the topic.

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

    I have updated more detailed information on how to achieve it.

»
13 hours ago, # |
  Vote: I like it 0 Vote: I do not like it

I didn’t solve D just because I didn’t consider the tree with only one point, which resulted in me doing nothing for the last hour. That's funny.

»
12 hours ago, # |
  Vote: I like it +8 Vote: I do not like it

Thanks for the excellent contest. Problems D,E and F are all intersting!

»
11 hours ago, # |
  Vote: I like it +8 Vote: I do not like it

How is the construction of array $$$a$$$ in Problem D’s editorial optimal?

»
9 hours ago, # |
  Vote: I like it 0 Vote: I do not like it

problem C, the case 9 9 7 9 -9 9 -8 7 -8 9 why the answer is 2056?

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

Can someone who have solved E1 tell how they solved it and came to the conclusion their method was right?

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

    At first we need to sort all node by their weight, then our strategy is choosing second biggest node (when it sorted by weight), and checking if in its subtree contains all bigger weight node or not, if not we will choose it, next player will choose the biggest, so there will be no other option, so we win. If it contains all, just check next smaller weights, until we find answer. If we dont find it, then there no answer. I solved that intuitively, that's why I wasn't sure if its correct or not :)

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

Problem D: Anyone getting Runtime Error in Test 8? Please help me how my solution got accepted in 7 test cases but runtime error in test 8?

https://codeforces.me/contest/2062/submission/303196494

  • »
    »
    6 hours ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    I found the answer, thanks to Eunha His code helped me understand the problem. The recursion limit in Python is too low for test case 8 so we have to use a stack.

    Surprisingly adding sys.setrecursionlimit(500000) is also not solving the problem.

    Anyone knows any other way of increasing recursion limit? To do this without stack using recursive dfs?

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

How does the C++ solution of D work?
Why does this line erase(e[v], u); not TLE?
Should it not be $$$O(n^2)$$$?

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

    The total time these erase operations take throughout the whole DFS is $$$\mathcal{O}(E)$$$, because this operation is done for each vertex only once and for each vertex it takes time proportional to the number of edges attached to it. Since this is a tree, it's also $$$\mathcal{O}(V)$$$.

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

Is there any proof for B ?

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

why O(n^2) gives TLE in E1, even when time limit is 4 sec ?


const int N=1e6+5; vector<int> tree[N]; int down[N]; int up[N]; int id; bool visited[N]; int p[N]; void dfs(int u) { if(visited[u])return; down[u]=++id; visited[u]=1; p[id]=u; for(auto it:tree[u]) { dfs(it); } up[u]=++id; } bool comp(pair<int,int>&a,pair<int,int>&b) { return a.first>b.first; } void solve() { int n; cin>>n; for (int i=1; i<=n; i++) { tree[i].clear(); id=0; visited[i]=0; } vector<int>wt(n+1,0); for(int i=1;i<=n;i++) { cin>>wt[i]; } for(int i=0;i<n-1;i++) { int x,y; cin>>x>>y; tree[x].push_back(y); tree[y].push_back(x); } dfs(1); vector<pair<int,int>>ans; for(int i=1;i<=n;i++) { int l=down[i]; int r=up[i]; for(int j=1;j<=id;j++) { if(j>=l && j<=r)continue; if(p[j]<=n && wt[p[j]]>wt[i]){ ans.push_back({wt[i],i}); } } } for(int i=0;i<=3*n;i++) { p[i]=0; } if(ans.size()==0) { cout<<0<<endl; return; } sort(ans.begin(),ans.end(),comp); cout<<ans[0].second<<endl; }
»
6 hours ago, # |
  Vote: I like it 0 Vote: I do not like it

Is the reason why the first comparison in question C did not take an absolute value compared to the prefix sum without operation?

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

2062B Clockwise ans in c++ is wrong my code is also similar except var name . testcase 1 both code passed but testcase 2 failed both.

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

This had such an uneducative C, the previous round's B was better than this round's C. Just simple observation that sum of differences is an-a1,solves this.

»
3 hours ago, # |
  Vote: I like it 0 Vote: I do not like it

Anyone have material For understanding E1 problem i see sol but that is beyond my understanding since some are using eulertour or something can someone provide problem resource for this pls

  • »
    »
    51 minute(s) ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    I solved it with small to large trick, it was needed to maintain how many nodes V in subtree U satisfy this condition: w[U] < w[V]. Here you can read more details about it.

»
3 hours ago, # |
  Vote: I like it 0 Vote: I do not like it

E1 editorial says "Additionally, we can enumerate the nodes in descending order of wi and maintain their lowest common ancestor (LCA). If the LCA of all v satisfying wv>wu is not a descendant of u, then there must exist a node v outside the subtree of u that satisfies wv>wu."

what if there are n/2 nodes with maximum w[v] and we need to check each one of them with every other w[u] to find the answer and exactly the last one we check is the answer?

isn't it O(n^2lg)? or even O(n^2)?

can someone explain if I'm wrong?

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

Don't know if anyone can't understand the implementation of E2 from official editorial but here is my own code, based totally on what the editorial said, using LCA and basic data structures. maybe it's easier to understand?

»
89 minutes ago, # |
  Vote: I like it 0 Vote: I do not like it

You can also use Small To Large for problem E1.

Idea : - If the current value don't contain the previous larger values then the node containing it is definitely winnable. Or if it does contain, if the previous larger values do exist outside of the subtree of this node then it is also a winnable node.

This is my code :

https://codeforces.me/contest/2062/submission/303225889