cry's blog

By cry, 6 weeks ago, In English
Rating Predictions

2060A - Fibonacciness

Problem Credits: Proof_by_QED
Analysis: larush

Solution 1
Solution 2
Code (C++)
Rate The Problem!

2060B - Farmer John's Card Game

Problem Credits: Lilypad
Analysis: larush

Solution
Code (C++)
Rate The Problem!

2060C - Game of Mathletes

Problem Credits: LMeyling
Analysis: macaquedev

Solution
Code (C++)
Rate The Problem!

2060D - Subtract Min Sort

Problem Credits: Proof_by_QED
Analysis: Proof_by_QED

Solution
Code (C++)
Rate The Problem!

2060E - Graph Composition

Problem Credits: LMeyling
Analysis: DivinePunishment

Solution
Code (C++)
Rate The Problem!

2060F - Multiplicative Arrays

Problem Credits: Proof_by_QED, cry
Analysis: -firefly-

Hint 1
Hint 2
Hint 3
Solution 1
Solution 2
Code (C#)
Rate The Problem!

2060G - Bugged Sort

Problem Credits: chromate00
Analysis: macaquedev

Hint 1
Hint 2
Hint 3
Hint 4
Solution
Code (C++)
Rate The Problem!
  • Vote: I like it
  • +126
  • Vote: I do not like it

»
5 weeks ago, # |
  Vote: I like it +8 Vote: I do not like it

C took me incredibly long. I was completely overcomplicating it thinking that we needed to subtract from the answer when there was an odd number of non-pair numbers.

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

    hahaha, I did the same. I didn't realize the fact that non pair numbers can never be odd up until the contest ended, so silly.

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

    hahahaha me too bro

  • »
    »
    5 weeks ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    same

  • »
    »
    5 weeks ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    Same, I didn't read that n is even only :(

    • »
      »
      »
      5 weeks ago, # ^ |
        Vote: I like it 0 Vote: I do not like it

      How will that drastically change anything? Like all i can think of is by making some modifications like storing remaining useless elemenst' count and then checking its parity would work, no?

      • »
        »
        »
        »
        5 weeks ago, # ^ |
          Vote: I like it 0 Vote: I do not like it

        It has 2 additional cases:

        If # unpaired is odd and n is odd, Alice gets the last unpaired, so we are good. If # unpaired is odd and n is even, Bob will be forced to disturb 1 pair.

        Certainly not drastic but even is just easier, that's all. I was complicating the problem too much in my mind.

  • »
    »
    5 weeks ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    me too brother ...me too

  • »
    »
    5 weeks ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    did same too if remaining are odd have to remove some elements

  • »
    »
    5 weeks ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    Everyone in my friend group seems to have problem with this.

    But I don't understand how I did it under 10 mins of reading the problem.

    On the other hand, I never have problems implementing solutions. (I did This on my own)

    But I got destroyed trying to implement B.

    And I did not understand D to begin with

»
5 weeks ago, # |
  Vote: I like it +9 Vote: I do not like it

It was a nice contest! I got stuck on problem E, but I'll learn from it.

  • »
    »
    5 weeks ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    today was the 1st time ever i reached problem E :), all the best to u!

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

:)

  • »
    »
    5 weeks ago, # ^ |
    Rev. 3   Vote: I like it +15 Vote: I do not like it

    At first reading your comment, I thought you actually had to take a dump during the contest. I almost felt sorry for you.

»
5 weeks ago, # |
  Vote: I like it +32 Vote: I do not like it

Why is F so damn hard???

»
5 weeks ago, # |
  Vote: I like it +7 Vote: I do not like it

Is it me or the B problem was kind of hard to implement ? It took me a while to solve it. Even the total number of users who solved the problem is less than the problem C.

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

    understanding that statement took me some time ..implementation is easy

  • »
    »
    5 weeks ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    it took me a long time to understand the problem properly, but even so i couldn't implement it. feels like C and D were easier

»
5 weeks ago, # |
  Vote: I like it +23 Vote: I do not like it

As an AKer in 2h29min, I think this is closer to DIV2 ;)

»
5 weeks ago, # |
  Vote: I like it +13 Vote: I do not like it

Problem G is very good.

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

I lost like 1000-2000 rank because of B and D :( and also got too confident on my two different solutions to E and submitted them both. But nevertheless, This was the most problems I ever solved in any contest yet and I am quite happy.

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

Imo, C was easier than B.

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

Can anyone explain D?

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

contest was really cool...solved A,C but couldn't solve B:(

  • »
    »
    5 weeks ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    I have a simple and intuitive solution.

    Start by considering $$$m = 1$$$

    And create an array $$$p$$$ which is the answer

    Now loop through the cards of each cow, let's say for the sake of simplicity from $$$1$$$ to $$$n$$$. The array could be filled like so : $$$p[card[i]] = i + 1$$$

    Now let's consider when $$$m > 1$$$ I will consider $$$card[i][j]$$$ to be the $$$j'th$$$ card of cow $$$i$$$

    I will do exactly what I did for $$$m = 1$$$, I will loop column by column

    When $$$j = 0$$$ (first column) , I will create my $$$p$$$.

    When $$$j > 0$$$, if the $$$p[card[i][j]] != i + 1$$$ , it means there is another permutation that is different then previous one, i will automatically output $$$-1$$$.

    One thing to note is that $$$card[i][j]$$$ could be $$$ >= n$$$, i take $$$card[i][j] \bmod n$$$ .

    here is my submission https://codeforces.net/contest/2060/submission/301926758

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

I solved A, C and D but can't solve B. I don't know what is the logical mistake in my solution.

  • »
    »
    5 weeks ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    my approach which might help:

    store in the form of int[n][m] sort all vectors find order by taking first el of all check if order is valid, else -1

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

    I created a vector of size n * m, and for each card assigned the number of the person holding it. The problem stated that you have cards starting from 0 to n * m — 1 and each card has to be greater than the last one. So with this array, you already have the sequence:

    Cow 1 has cards: 1 4 7

    Cow 2 has cards: 5 2 8

    Cow 3 has cards: 0 3 6

    The vector will be {3, 1, 2, 3, 1, 2, 3, 1, 2}. We have 3 cows, so we only get the sequence from up to index |qty. of cows-1| and check if it is equal the rest of the sequence.

  • »
    »
    5 weeks ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    check for edge case n=1

  • »
    »
    5 weeks ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    consider total m rounds.

    In each round that is total N cows will place a card. so,First create a map of all the numbers (0->n*m-1)-> for each number assign the cow. which cow is holding this particular card. Now iterate from z=0.(this is current card number) total we have to place m rounds .and in each round total n cows has to participate. say in round 1 -> z=0->search which cow has this z=0 number.insert that into a vector. increment z; z=1->search which cow has this z=1 .insert that cow number into a vector. after "n" cows played a permutation will be generated. you have to make sure that this is the only permutation will come at the end of the M rounds.

    insert this vector into a set after each round.

    at the end check whether the size is 1 or not you can refer

    https://codeforces.net/contest/2060/submission/301815602

  • »
    »
    4 weeks ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    I understood the problem statement wrong, and maybe you did the same. I thought that the card stack resets to -1 every time a new round starts. This gives a different problem, with a different solution, but you can't notice it in the sample I/Os. This variation gets WA on test 2.

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

Did anyone use Faulhaber formula to solve F?

  • »
    »
    5 weeks ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    I tried that at first, but then I realised my way of counting was wrong lol

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

    Test Case :

    1

    4

    1 3 5 2

    Expected Ans : NO

    Your Code Output : YES

  • »
    »
    5 weeks ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    I did the same at first , you can see my solution and find that we almost coded the same thing , except we both ignored the fact to change a[i-1] , we only focused on changing a[i] , you might ask how does that affect out solution.... Well , for the given test case : n = 8 a = [4 5 4 5 4 5 4 5] try printing your answer , it gives: [4 1 4 1 4 1 4 5] which is non decreasing , but still the answer is YES and that's a fluke.... so what is our next approach? Well luckily for us we dont need to change a lot in this code , just make sure to understand the fact that , we won't change the values only when a[i] > a[i + 1] , we might need to do it otherwise as well , its kinda hard to explain the intution , until i come up with a proper proof but a rough proof might look like : let's take the above array that i used as an example , there your code didn't use the operation on 2nd index(0 based) and hence in the answer array we get a 4 , instead if we had applied the operation then the answer array would've looked like [0 0 0 0 0 0 0 4] so just apply this operation on all the indices , and check in the end if it is sorted or no , lmk if you have any doubt , here's my submission : here

    • »
      »
      »
      5 weeks ago, # ^ |
        Vote: I like it 0 Vote: I do not like it

      Yeah I got it now thanks for such detailed reply, I don't understand how can I not notice such a simple thing..

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

good contest , bad contest

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

My brute force is failed for C. Its was basic level question

»
5 weeks ago, # |
  Vote: I like it +1 Vote: I do not like it

The testcases for E couldve been better. I just thought we have to make both the graphs same but i guess thats what makes me a newbie

  • »
    »
    5 weeks ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    i guess also thought the same after WA i thought another solution lol

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

thank for contest

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

man i dont know why my c is wrong .


#include <bits/stdc++.h> using namespace std; int main(){ int t; cin >> t; while(t--){ int score = 0; int n,k; cin >> n >> k; vector<int> v(n); for(int i = 0; i < n; i++){ cin >> v[i]; } sort(v.begin(),v.end()); for(int i = 0; i < n/2; i++){ if(*min_element(v.begin(),v.end()) + *upper_bound(v.begin(),v.end(),k -1 -*min_element(v.begin(),v.end())) == k){ score++; v.erase(upper_bound(v.begin(),v.end(),k -1 - *min_element(v.begin(),v.end()))); v.erase(min_element(v.begin(),v.end())); }else{ v.erase(min_element(v.begin(),v.end())); v.erase(min_element(v.begin(),v.end())); } } cout << score << endl; } }
  • »
    »
    5 weeks ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    Maybe, you are erasing from the vector ,this will change the vector,so in future issues mayrise with the upperbound and lowerbound later.these upper bound and lowerbound may change and they may not the ones which you think they'll be..Try out a test case and try printing all the upperbound's and lowerbound's and see..

  • »
    »
    5 weeks ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    It fails on this testcase: 1 2 4 2 3

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

why 301896773 gives TLE when submitted in C++20 but accepted when submitted in C++17

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

I'm quite new to graph theory problems, so please pardon any ignorance. However, for the life of me, I cannot understand why in problem E you cannot just count the number of pairs of (u, v) that are in G and not F, and the pairs in F but not G?

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

    consider the testcase

    1

    4 2 2

    1 3

    2 3

    1 2

    1 3

    the answer is zero

    but according to you answer will be 2

  • »
    »
    5 weeks ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    If (u, v) does exist in G, but not in F, it doesn't mean that you can not reach v from u (u -> w -> v)

    • »
      »
      »
      5 weeks ago, # ^ |
        Vote: I like it 0 Vote: I do not like it

      Aha! I guess I assumed that the problem only wanted one edge between (u, v).

  • »
    »
    5 weeks ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    Consider F = 1-2-3-4 and G = 1-4-2-3

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

Can someone explain how for E on the second test of test 2 the # of operations needed is only 2? I'm getting 33.

  • »
    »
    5 weeks ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    oh as long as there is a path between them it works didn't realize that

»
5 weeks ago, # |
  Vote: I like it +5 Vote: I do not like it

F was awesome

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

Nice contest. D was pretty easy, though.

  • »
    »
    5 weeks ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    didn't you get it hacked ??

    • »
      »
      »
      5 weeks ago, # ^ |
        Vote: I like it 0 Vote: I do not like it

      Nope, not yet at least. Might get hacked since I didn't really think much on it aside for my initial doubts about my approach being too simple to work.

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

Jeez!! I got stuck on problem E. Now reading the tutorial I noticed that I had the idea but still have lots of problems on the implementation looool. Btw, interesting contest, good problems. Wanna upsolve rn!!!!

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

301778309 Can someone point out the error in this for B?

  • »
    »
    4 weeks ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    Revisited this again today. While iterating over the sorted matrix, I wasn't comparing the last value of previous column to first value of previous column. (╥﹏╥)

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

Any good resources to learn combinatorics?

»
5 weeks ago, # |
  Vote: I like it +11 Vote: I do not like it

Self review no one asked for:

so mad that i sold around 50 penalty points because of the misread on a...

i lost a little time on b because of interesting construction

rushed on c, my mind was too disorganized

c-d turnaround was lowkey clean, i hit an instant mindsolve

e i sent two wa because i thought we needed to simply match the edge list, rather than the path. test case 1 seemed to support this. i sent another wa submission because i thought it was overflow

f and g were beyond me

  • »
    »
    5 weeks ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    Quite same. Got stuck on A and thought I was screwed. Than tried D and bam! solved it in first go. C was also a smooth sailing, but got stuck at B again. I really don't know what to feel as A and B gave me more trouble than my whole college exams combined.

  • »
    »
    5 weeks ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    My man, at least you realize it in time.

    When I was realized I read the problem E wrong, the contest is already over.

    It only took me ~ 30 min of implementation so if I could realize I read the problem wrong, I can comeback easily (theoretically)...

    Ready going back to pupils and wait for Div 4.

  • »
    »
    5 weeks ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    can I know the extension that you are using to predict the rating changes

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

Why was d at d?

  • »
    »
    5 weeks ago, # ^ |
      Vote: I like it +13 Vote: I do not like it

    Because we hoped that some people will prove the result instead of resorting to guessing that the obvious strategy works, and the proof is actually not so simple.

    • »
      »
      »
      5 weeks ago, # ^ |
        Vote: I like it 0 Vote: I do not like it

      Hey can you tell me whethe my proof was correct?

      I started from the first index of array and started taking the mid of first two elements. Than I subtracted it from both. Than we will reduce one element to 0 and the next to whatever was left after subtracting. By the way this was done only when first element was smaller than second as otherwise if this operation is performed there is no way that array can be non decreasing as zero is the minimum element obtainaible and everytime we pair an element with 0 the min of them both will be zero. So if we get something like 1 0 than it's likely impossible but if we have smooth sailing till last index than you are good to go.

      Does it seem satisfactory or you have a better proof? I'd love to hear your take.

      • »
        »
        »
        »
        5 weeks ago, # ^ |
          Vote: I like it 0 Vote: I do not like it

        This doesn't tell me why it is optimal to decrease on the first element first. Perhaps it is better to do them in a different order. My proof is in editorial

»
5 weeks ago, # |
Rev. 9   Vote: I like it +8 Vote: I do not like it

There is an easier solution for G without dp and more straightforward to prove(?). Imagine $$$a$$$ and $$$b$$$ stacked on top of each other, draw an arrow pointing downwards from $$$a_i$$$ to $$$b_i$$$ if $$$a_i > b_i$$$ otherwise draw an upwards arrow from $$$b_i$$$ to $$$a_i$$$. Now doing an operation on $$$(i,j)$$$ is equivalent to swapping the pairs $$$(a_i,b_i),(a_j,b_j)$$$ then flipping their arrows.

Following from the editorial, the order of the pairs in the final sorted configuration is fixed and we can freely reorder the pairs. The question left is whether we can orient the arrows correctly?

Assume we already fixed the final direction of each arrow in the final state, the number of up arrows in the final and initial state has to have the same parity (parity of up arrows is invariant under swapping). So we now ask what possible parities of up arrows can the final state have?

First sort the pairs by $$$\min(a_i,b_i)$$$. For each $$$i$$$, if $$$\max(a_i,b_i) > min(a_{i+1},b_{i+1})$$$ then their arrows must share the same direction, otherwise they can be different or the same. Now we split the pairs into consecutive segments where each all arrows in the same segment must have the same direction. The parity of number of up arrows can be $$$0$$$ or $$$1$$$ iff there exist a segment of odd length because changing the direction of all arrows in an even segment does not change the parity of up arrows. The answer to yes or no reduces to these two conditions:

1) No $$$\max(a_i,b_i) > \max(a_{i+1},b_{i+1})$$$ exist

2)There exist an odd segment or the parity of up arrows in the initial state is even

  • »
    »
    5 weeks ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    My solution is similar to yours, but I think you're missing one case.

    Even if all the fixed segments are even length, if there exists two consecutive i's where max(ai,bi)>min(ai+1,bi+1) is false, then you can flip the first of those two i's without changing anything else. This means you can always make the total number of flips even.

    (Also you still have to check that after ordering the pairs, one of the flips (or arrow directions) is valid — such as in the first example test case where the middle pair can never be valid.)

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

      Yes, that is in the second condition (initial up arrows even)

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

In the tutorial of B, it says in general,

the i-th cow (where i∈[0,n−1]) must be able to place i,n+i,2n+i,….

but what if the input is

1

3 3

3 4 5

0 1 2

6 7 8

here there is still a possible permutation but not according to the tutorial ??

  • »
    »
    5 weeks ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    No player can play consecutive turns, so suppose player 2 plays 0, player 1 plays 3, and player 3 plays 6, then player 2 can't play any of his cards since they are smaller than 6. (If you think that player 2 can play all his cards, then player 1, then player 3, then you might have misread the question) A player will only get his turn after all other players have played, everyone maintains the same turn order throughout the game

  • »
    »
    5 weeks ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    "Farmer John wants the game to be fair, so each cow should only be able to play 1 card per round."

    Maybe you read too fast or forgot about this part.

»
5 weeks ago, # |
  Vote: I like it +1 Vote: I do not like it

In problem F solution 1, how are we calculating \begin{align*} \binom{n+1}{j+1} \end{align*}

since n is very large?

  • »
    »
    5 weeks ago, # ^ |
      Vote: I like it +11 Vote: I do not like it

    n is large, but j is small. You can compute in O(j) time.

  • »
    »
    5 weeks ago, # ^ |
      Vote: I like it +10 Vote: I do not like it

    $$$\binom{n+1}{j+1} = (n+1)(n)(n-1)\ldots (n-j)/(j+1)!$$$, there are only $$$j+1$$$ terms in the binomial

»
5 weeks ago, # |
  Vote: I like it +1 Vote: I do not like it

my downfall was A. I don't know why I was overthinking it so much when it was so obvious. Took me nearly one hour to solve. I really have a lot to learn...

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

Amazing contest! I was able to solve A, B, C on whiteboard. Hope to see more contests like this!

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

Is it just me or anyone else feels like there are a bunch of people using AI to solve the problems, given LLM's are basically on Master's level. Some low rank people just straight up solve E. I tried plugging the question into ChatGPT and it instantly gave me a working answer. What is the future of these types of contests?

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

For D I used a completely different approach, where the logic (at least if you have to prove it!) is simpler: starting from the end, find the allowed interval for the previous element. Then check that the first element fits in the required interval.

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

Although B is quiet easy there is better way to implement it(or should I say more efficient)(although the logic remains the same) , we could just find the modulo the elements of each row with n if they are all the same , then it is possible else it isn't . Finding the permutation is also easy , we can just create an array and append the remainders (if they are all equal for a row). Now the permutation would be the remainder+1 . The time complexity would be $$$O(n*m)$$$ here (This is what I did during the contest).[I know that this is fairly simple problem , but I thought this would be nice to point out nonetheless]

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

Damn... I've used DSU implementation from Algorithmica. And it was wrong all from the start. Spent 30 minutes to find a bug in my solution, and the only bug was my trust in this site.

  • »
    »
    5 weeks ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    Use Striver's DSU. It is the best in my opinion.

  • »
    »
    5 weeks ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    Algorithmica DSU implementation is fine. The wrong answer for your first several submissions was caused by the if (p[u] != p[*it]): to check if two vertices are in the same component, you should compare their leaders, not their parents.

    • »
      »
      »
      5 weeks ago, # ^ |
        Vote: I like it 0 Vote: I do not like it

      Yes, you are right here. But I couldn't pass tests anyway because unite function doesn't check that leader(a) == leader(b). So it caused overflowing. I know that you should understand an implementation, that you find in the Internet, in details. And I didn't use DSU for quite a long time. I was just convinced that this is the basic check for the unite function.

      So, yeah, my statement about Algorithmica was not completely honest. Sorry about that.

      Anyway, glad that I got the idea of the problem, and thanks for your reply.

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

Can anyone explain why my solution of B 301795916 is giving wa.

»
5 weeks ago, # |
  Vote: I like it +5 Vote: I do not like it

I solved G without using dynamic programming and I think it's a bit more intuitive (at least for me).

Using the same insights as mentioned in the hints, my solution builds out a possible answer and checks if it has enough degrees of freedom to end up with an even number of flips, or necessarily has an even number of flips.

Say you've placed the first n pairs (as the editorial mentions, this order is fixed by $$$min(a_i, b_i)$$$), then you take the next smallest pair and decide how it should be flipped. There are 4 cases:

  • it needs to be flipped (meaning the element from $$$a$$$ should end up in $$$b$$$)
    • for example, the previous is $$${1, 3}$$$ and the next to place is $$${4, 2}$$$, the 2 cannot come after the 3, so it has to be flipped first
  • it needs to stay unflipped
    • for example, the previous is $$${1, 3}$$$ and the next to place is $$${2, 4}$$$
  • it can be either orientation
    • for example, the previous is $$${2, 3}$$$ and the next to place is $$${4, 5}$$$
  • or can't be either
    • In this last case, you can early return a "NO". This would be like in the first example case where you place $$${1, 6}$$$ first and then have to place $$${2, 4}$$$, but no matter how you flip $$${2, 4}$$$ the number after the array with 6 will no longer be increasing.

You don't need to track the whole array, just the chosen state of the previous pair, which you can initialize as $$${-1, -1}$$$ (since the first actual pair can have either orientation).

If at any point you have two in a row which can be either orientation, then you can flip or not flip that fist one to make the total number of swaps even, regardless of how the total turns out. From this point on, you will return "YES" as long as you don't find a situation where a pair can't be either orientation.

You will also want to track the number of fixed orientations there are in a row. If you end up with a block of fixed orientations which is of an even count, then you can flip the pair just before this block (which is necessarily one that can be either orientation, otherwise it would be part of this block) which would flip the orientation of all the pairs in this block as well, which will have flipped the orientation of an odd number of pairs, meaning the number of total flips will have gone from even to odd or vice versa. This freedom will mean no matter what the parity of the other fixed blocks are, you can make the total number of flips even or odd.

After going through all pairs, if you found either degree of freedom (either two free pairs in a row, or a block of fixed pairs of even count) or the number of flips applied for the array you built is already even, then it's possible.

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

Why is dp[3][1] = 1 in solution of question G? Shouldn't the dp[4][1] be equal to 1 since we flip the first pair and the total flips is equal to 1?

  • »
    »
    5 weeks ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    Editorial author here. Sorry, just a really annoying typo, because I got confused between zero and one-based indexing! It's definitely meant to be dp[4][1].

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

in c we can count number of pairs using 2 pointers, i did so so maybe update tags

»
5 weeks ago, # |
Rev. 2   Vote: I like it +3 Vote: I do not like it

In problem F, why are we only doing (n,j), there can be sequence of repeated factors as well which will reduce the multiple.

i.e. example consider a sequence [2,3,3,4,4,4] and then (n-6) 1's for any n. The multiple should be n!/((n-6)! * 2! * 3!)

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

why am i getting TLE in C? I need help pls

#include <bits/stdc++.h>
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
 
using namespace std;
int N = 200002;
 
void solve();
 
int main()
{
    IOS

    int t;
    cin >> t;
 
    while(t--)
    {
        solve();
    }

    return 0;
}
 
void solve()
{
    int n, k;
    cin >> n >> k;
 
    vector<int> numbers(n);
    vector<int> counter(N, 0);
 
    for(auto& num: numbers)
    {
        int temp;
        cin >> temp;
        counter[temp] += 1;
        
        num = temp;
    }
 
    int result = 0;
 
    for(int i = 0; i < n; i++)
    {
        if(counter[numbers[i]] > 0 && counter[abs(numbers[i] - k)] > 0 && numbers[i] == abs(numbers[i] - k))
        {
            result += counter[numbers[i]] / 2;
            counter[numbers[i]] = 0;
            counter[abs(numbers[i] - k)] = 0;
        }
        else if(counter[numbers[i]] > 0 && counter[abs(numbers[i] - k)] > 0)
        {
            
            result += min(counter[numbers[i]], counter[abs(numbers[i] - k)]);
            counter[numbers[i]] = 0;
            counter[abs(numbers[i] - k)] = 0;
        }
    }
    
    cout << result << endl;
}
  • »
    »
    5 weeks ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    You're declaring an vector of length 200002 for each test case, which is slow and can cause a TLE with many test cases.

    • »
      »
      »
      5 weeks ago, # ^ |
        Vote: I like it 0 Vote: I do not like it

      Thank you. I didn't realized, my bad

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

You can solve problem B in O(nm) time complexity. You don't have to sort cards array, you have to only check is difference between consecutive terms in array is factor of n or not.

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

This is a very nice round, thank you for the authors!

The problem statements are clear and interesting, the difficulty levels are appropriate for Div 3, and even the hard problems have something instructive to learn when I can't solve it.

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

Can someone tell me why my code for E does not work?

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

B took me forever and couldn't even solve it :(

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

Coming up with a solution was easier than understanding the question.

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

There is an easier way to prove D, notice that if any set of operations sorts $$$a$$$, then that set + $$$op_1,op_2...op_{n-1}$$$ also sorts.

In the end, we will perform operations on every index at least once, and one can notice that performing $$$op_1$$$ as a first operation is optimal. After operating on index $$$1$$$, induction works for other indices.

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

A kind of brute force based matrix multiplication solution for F: https://codeforces.net/contest/2060/submission/301857001. This completes the max test

Max test

in ~3.6s. The complexity is $$$O(klog^2(k)log(n))$$$.

»
5 weeks ago, # |
Rev. 2   Vote: I like it +8 Vote: I do not like it

Problem F is similar to ABC110D.

»
5 weeks ago, # |
Rev. 3   Vote: I like it 0 Vote: I do not like it

Learnt something from the editorial.
A new word for me — Horrendous

img

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

Hii!

Can you guys tell me why this solution is getting wrong answer for problem E?

// this is code
#include<bits/stdc++.h>
using namespace std;
 
void soln(){
    int n, f, g;
    cin>>n>>f>>g;
 
    unordered_set<string>st1,st2;
    for(int i = 0; i < f; i++){
 
        int x, y;
        cin>>x>>y;
        int mini = min(x, y);
        int maxi = max(x,y);

        string val = to_string(mini) + to_string(maxi);
        st1.insert(val);       
    }
 
    for(int i = 0; i < g; i++){
 
        int x, y;
        cin>>x>>y;
        int mini = min(x, y);
        int maxi = max(x,y);

        string val = to_string(mini) + to_string(maxi);
        st2.insert(val);       
    }
 
    int ans = 0;
 
    for(auto x: st1){
        if(!st2.count(x)) ans++;
    }
 
    for(auto x: st2){
        if(!st1.count(x)) ans++;
    }
 
    cout<<ans<<endl;
}
 
int main(){
    int t;
    cin>>t;
 
    while(t--){
        soln();
    }
}

I know DSU will be the correct way of solving this, but this is what clicked in my mind.

  • »
    »
    5 weeks ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    Although your method itself (calculate the difference between edges) is wrong, your comparing method (concat it to a string) is even wrong. Consider $$$(1,112)$$$ and $$$(11,12)$$$.

    For why your method is wrong, consider:

    $$$F$$$: $$$(1,2)$$$ $$$(1,3)$$$.

    $$$G$$$: $$$(2,3)$$$ $$$(1,3)$$$.

    • »
      »
      »
      5 weeks ago, # ^ |
        Vote: I like it 0 Vote: I do not like it

      Aaah! I got it.

      Thankyou for your explanation.

  • »
    »
    4 weeks ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    I would also like to mention, to save you from possible hacks in the future, to not use unordered_set and unordered_map, since those have worst case O(n) time complexity for lookups. Instead use the normal set and map

    • »
      »
      »
      4 weeks ago, # ^ |
        Vote: I like it 0 Vote: I do not like it

      okay!

      Thanks for your suggestion. I am not so active on codeforces. What are hacks?

      • »
        »
        »
        »
        4 weeks ago, # ^ |
          Vote: I like it 0 Vote: I do not like it

        Essentially, people can make custom test cases to test against another solution, and if you are using unordered_map, they can make a test case that triggers the O(n) time complexity for lookups and give it to your program to make it time out.

        • »
          »
          »
          »
          »
          4 weeks ago, # ^ |
            Vote: I like it 0 Vote: I do not like it

          ok ok I will ensure to use normal map and set in the future. Thankyou!

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

I overcomplicated the problem E. First of all, I tried to remove the edges from $$$F$$$. I took $$$3$$$ vertices $$$a$$$, $$$b$$$, and $$$c$$$ which are there in $$$1$$$ connected component in $$$F$$$, but $$$a$$$ and $$$b$$$ are not in same component in $$$G$$$, so I have to remove some edges in $$$F$$$ such that $$$a$$$ and $$$b$$$ seaparates in different components, but in doing that it can happen that I separated $$$b$$$ and $$$c$$$, and there is a path from $$$b$$$ to $$$c$$$ in $$$G$$$. So, now I have to re-add edges. Moreover, in all of these operations I have to find out which edges to remove, probably bridges. I got overwhelmed by all of that and ended up not solving.

Then, I am looking at editorial which seems nothing in front of the approach which I was thinking. Any suggestions on how to prevent such blunders in future?

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

The Solution2 of F has a typing mistake.

The formula

Unable to parse markup [type=CF_MATHJAX]

should be corrected to

Unable to parse markup [type=CF_MATHJAX]

.
»
5 weeks ago, # |
  Vote: I like it 0 Vote: I do not like it

Can anyone help me understand why my solution for E was wrong? 301891399

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

Does anybody got wrong ans on test case 2 on e ans is 21 code gives 25

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

F: How dp from editorial works? Example:

dp[6][1] = 1
dp[9][1] = 1
dp[18][2] = dp[18/2][1] + dp[18/3][1] = 2

But it wrong, correct is 4! Possible arrays: [9 2] [2 9] [6 3] [3 6]

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

    You update dp from all non-1 factors, not just prime. In this case it should be dp[18][2]=dp[18/2][1]+dp[18/3][1]+dp[18/6][1]+dp[18/9][1]+dp[18/18][1]=1+1+1+1+0=4

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

I wish Problem E had been based on a different topic instead of graphs.

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

Hello could someone explain me why for problem F: fk(n)=∑j|kfj(n−1) (according to the first solution) and there is no "n" factor in the expression. For me there is n ways to add an element to an array of length n-1 to do an array of length n.

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

Going to Study DFS ans DSU after the contest...

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

For problem G, if you have played Rubic's cude, you can find out that we use 2*2 Y perm to contruct E perm.It's very interseting. G is a very good problem.

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

How can I understand that both fk(n) and Sk(n) are polynomials. I know Lagrange Interpolation for the first time.

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

Every solution I see for Problem B has sorting while it can be solved with a straightforward approach in an O(n*m) time complexity as follows:

#include <bits/stdc++.h>
 
#define IO                        \
    ios_base::sync_with_stdio(0); \
    cin.tie(0);                   \
    cout.tie(0);
#define ll long long
#define ld long double
using namespace std;
const ll N = 1e5 + 5, MOD = 1e9 + 7;
 
void solve()
{
    ll n, m;
    cin >> n >> m;
 
    vector<ll> vec(n * m, 0);
 
    for (ll i = 0; i < n; i++)
    {
        for (ll j = 0; j < m; j++)
        {
            ll x;
            cin >> x;
            vec[x] = i;
        }
    }
 
    for (ll i = n; i < n * m; i++)
    {
        if (vec[i] != vec[i - n])
        {
            cout << "-1\n";
            return;
        }
    }
    for (ll i = 0; i < n; i++)
    {
        cout << vec[i] + 1 << " ";
    }
    cout << "\n";
}
 
int main()
{
    IO
        ll t;
    cin >> t;
    while (t--)
        solve();
    return 0;
}
»
5 weeks ago, # |
  Vote: I like it 0 Vote: I do not like it

Normal solve

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

Regarding the solution for G, the key observation part can be proven without contradiction.

Since the final solution keeps the sequences $$$a$$$ and $$$b$$$ in ascending order, we have the following.

$$$a_i \leq a_{i+1}$$$ and $$$b_i \leq b_{i+1}$$$.

Real numbers have a convenient property where $$$x \leq y$$$ and $$$z \leq w$$$ implies $$$min(x,z) \leq min(z,w)$$$, so we can immediately derive the following result.

$$$min(a_i,b_i) \leq min(a_{i+1}, b_{i+1})$$$.

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

For problem F, the solution 1 that is described in the editorial for computing non-unity sequences for length till 16 using dp. You can actually do it using inclusion and exclusion too.

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

How are we making sure that algorithm given in editorial for E, is indeed giving us the minimum number of operations?

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

Problem F is an advanced version of LeetCode 1735. Count Ways to Make Array With Product. You can try solving the simpler one first.

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

In the first problem just 2 condition would have been sufficient.

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

why we have take -99 in soln of A ??

I am new , can someone help .......

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

)

»
5 weeks ago, # |
Rev. 2   Vote: I like it -8 Vote: I do not like it

Can someone tell me why Problem C gives TLE in testcase 17 for this solution in java 8 This uses sorting and two pointers.

    import java.util.*;
    import java.io.*;
     
    import java.io.IOException;
     
    public class Main{
        static class FastReader{
            BufferedReader br;
            StringTokenizer st;
            public FastReader(){
                br=new BufferedReader(new InputStreamReader(System.in));
            }
            String next(){
                while(st==null || !st.hasMoreTokens()){
                    try {
                        st=new StringTokenizer(br.readLine());
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                }
                return st.nextToken();
            }
            int nextInt(){
                return Integer.parseInt(next());
            }
            long nextLong(){
                return Long.parseLong(next());
            }
            double nextDouble(){
                return Double.parseDouble(next());
            }
            String nextLine(){
                String str="";
                try {
                    str=br.readLine().trim();
                } catch (Exception e) {
                    e.printStackTrace();
                }
                return str;
            }
        }
        static class FastWriter {
            private final BufferedWriter bw;
     
            public FastWriter() {
                this.bw = new BufferedWriter(new OutputStreamWriter(System.out));
            }
     
            public void print(Object object) throws IOException {
                bw.append("" + object);
            }
     
            public void println(Object object) throws IOException {
                print(object);
                bw.append("\n");
            }
     
            public void close() throws IOException {
                bw.close();
            }
        }
     
        public static void main(String[] args) {
            FastReader in=new FastReader();
            FastWriter out=new FastWriter();
            try {
                int n = in.nextInt();
                for(int i=0; i<n; i++){
                    int a=in.nextInt();
                    int b=in.nextInt();
                    int[] arr=new int[a];
                    int ans = 0;
                    HashMap<Integer,Integer> map=new HashMap<>();
                    for(int j=0; j<a; j++){
                        arr[j] = in.nextInt();
                    }
                    Arrays.sort(arr);
                    int f = 0, g= a-1;
                    while(f<g){
                        long sum = 1L*arr[f]+arr[g];
                        if(sum==b){
                            ++ans;
                            ++f;
                            --g;
                        }else if(sum<b){
                            ++f;
                        }else --g;
                    }
                    out.println(ans);
                }
            } catch (Exception e) {
                return;
            }finally{
                try{
                    out.close();
                }catch (IOException e){
                    e.printStackTrace();
                }
            }
        }
    }
»
5 weeks ago, # |
  Vote: I like it +1 Vote: I do not like it

Thanks for the contest, this was such a great problem set; it's been a long time since I've enjoyed one like this.Problem F is definitely on my top 3 list.

»
5 weeks ago, # |
Rev. 3   Vote: I like it 0 Vote: I do not like it

TLE on E because instead of doing: if(!visited[child]) { visited[child] = true; bfs.push(child); } i did: if(!visited[child]) { bfs.push(child); } i deserve the -ve

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

Can someone comment about the time complexity if E is solved using DFS rather than DSU , I think for DFS , it can get TLE if testcases are not so gentle for the same constraints ?

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

    My solution with BFS was O(NlogN), though I can't say if that's the best time complexity possible

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

Anyone in community pls help with the following issue of mine:

I had solved first 4 and hadn't got any error in C. But during system testing I was getting runtime error on test 14 (my submission: 301790765). But with same logic another solution of a friend of mine (301906786) was getting accepted. You can see that only difference is that he is accessing first element in multiset and I was accessing last element.

And with my other ID I had submitted exact same to same code as that on which I was getting runtime error on test 14, but to my surprise on this other ID with same code same compiler I was getting runtime error on test 17 (301902846) instead of 14.

So after that I tried exact solution as that of my friend on same compiler C++ 20, but I was getting runtime error on test 4 this time (302179372). So pls help me with this because because of this runtime error I got -99 instead of -35, my official standing slipped from 4000 to 11500.

Pls help cry

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

    OK here's why it's happening

    ll req = *it;
    

    You're setting req equal to the value at *it.

    s.erase(it);
    

    you're deleting the element that the iterator points to

    s.erase(s.find(k-*it));
    

    then you're again trying to access the data behind this iterator that you've deleted, which results in undefined behaviour.

    You were on the right track when you wrote ll req = *it", if you had just written s.erase(s.find(k-req)) instead of s.erase(s.find(k-*it)), you'd have been fine.

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

Am i the only one who understood something wrong on B problem statement? I thought the card stack restets to -1 every time a new round starts. I realised that i was wrong when i saw the solution. Luckily for me i didn't participate in the contest :P

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

I have a few questions regarding Solution 2 for Problem F.
1) "By induction we can prove that both fk(n) and Sk(n) are polynomials." How can we prove this?
2) "From the definition of Sk(n), we have q(k)=p(k)+1."
The definition of Sk(n) is sum of fk(i) for i=1 to n, isn't it? Because of that, Sk(n) is sum of polynomials with degree p(k). Sum of polynomials with degree p(k) should have the same degree (as p(k)). Supposing all of that, q(k) should be p(k). How is q(k)=p(k)+1?

  • »
    »
    4 weeks ago, # ^ |
    Rev. 3   Vote: I like it +6 Vote: I do not like it

    1) First, $$$f_1(n)=1$$$ is a polynomial.

    Second, assume that for all $$$\Omega(k)\le m$$$, $$$f_k(n)$$$ are polynomials (where $$$\Omega(k)$$$ is the prime omega function). Then, for $$$\Omega(k)=m+1$$$, $$$f_k(n)-f_k(n-1)=\sum_{j|k,j<k}f_j(n-1)$$$. Since $$$\Omega(j)\le m$$$, the RHS is a polynomial. Then, you can accumulate the formula to get $$$f_k(n)-f_k(1)= \mathrm{sum\ of\ some\ polynomials}$$$, so $$$f_k(n)$$$ is also a polynomial.

    2) Note that $$$\sum_{i=1}^{n}i^m=\Theta(n^{m+1})$$$.

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

Problem #E.

How the author solution is taking care of deleting the edges from graph F?

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

Problem G has a greedy solution that avoids the sorting step. We first create a vector that maps the lesser value to the greater value of each pair, taking care to save the parity of the flipped state. Then, at each iteration of the main loop, we find the next smallest pair (via a linear lookup) and execute the greedy logic. This results in $$$O(n)$$$ overall time complexity. 302303333

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

E is ridiculously trivial, I hate myself for not being able to do it.

If you need a hint => just don't overthink it.

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

I am unable to find the wrong case for my submission on G it's WA on 4. Can someone give some test case for it.

here is my submission:303466389

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

哈哈哈哈哈哈哈

»
10 days ago, # |
Rev. 3   Vote: I like it 0 Vote: I do not like it

Another solution for F: For a fixed $$$x$$$, let the $$$(\alpha_1, \alpha_2, \dots, \alpha_s)$$$ be the powers of primes in its factorization. Then, for a fixed $$$|a| = m$$$, the number of arrays is $$$\prod\limits_{i=1}^{s}\binom{m+\alpha_i-1}{\alpha_i}$$$ since we choose positions of primes independently for different primes and for a fixed prime we have a kind of "stars and bars" situation. To get the answer for a certain $$$x$$$, we sum the products for $$$m = \overline{1,n}$$$.

Since $$$n$$$ is large, it's impossible to do explicitly. Instead, notice that $$$\prod\limits_{i=1}^{s}\binom{m+\alpha_i-1}{\alpha_i}$$$ is a polynomial of $$$m$$$ with a degree no more than $$$16$$$ (since there are no more than $$$\log_2{(x)} \leq \log_2{(k)} < 17$$$ primes in factorization of $$$x$$$). We can write the polynomial as $$$\sum\limits_{j=0}^{t}c_{xj}\cdot m^j$$$, then the answer for $$$x$$$ is \begin{equation} \sum\limits_{m=1}^{n}\sum\limits_{j=0}^{t}c_{xj}\cdot m^j = \sum\limits_{j=0}^{t}c_{xj}\sum\limits_{m=1}^{n}m^j = \sum\limits_{j=0}^{t}c_{xj}\cdot f_j(n), \end{equation} where $$$f_j(n)$$$ is a sum of first $$$n$$$ $$$j$$$-th powers which is actually a polynomial of degree $$$j+1$$$ (Faulhaber's formula: https://en.wikipedia.org/wiki/Faulhaber%27s_formula ).

We can precompute the coefficients of $$$f_j(x)$$$ for $$$j = \overline{1...\lfloor\log_2(k)\rfloor}$$$ by constructing a system of linear equations and Gaussian elimination in $$$O(\log^4(k))$$$. Then we get an answer for a single $$$x$$$ in $$$O(\log^2(k))$$$ time required for multiplication and evaluation of polynomials.