eren__'s blog

By eren__, 6 weeks ago, In English

⭐ Hope you enjoyed the problems! ⭐

2269A - SauSaGe Bank

Idea: Hamed_Ghaffari
Preparation: Hamed_Ghaffari

Hints
Solution
Code

2269B - KiaKio and Squared Numbers

Idea: sweetweasel
Preparation: sweetweasel

Hints
Solution
Code

2269C - K Is Important / 2268A - K Is Important

Idea: eren__
Preparation: eren__

Hints
Solution
Code

2269D - What a SauSaGe! It's All Meat / 2268B - What a SauSaGe! It's All Meat

Idea: _R00T
Preparation: _R00T

Hints
Solution
Code

2269E - KiaKio and Energy Intervals / 2268C - KiaKio and Energy Intervals

Idea: sweetweasel
Preparation: sweetweasel

Hints
Solution
Code

2269F - AghaBalaSar and Hamed / 2268D - AghaBalaSar and Hamed

Idea: Hamed_Ghaffari
Preparation: Hamed_Ghaffari

What is AghaBalaSar?
Hints
Solution
Code

2268E - Kia Kio and Tree of Life

Idea: sweetweasel
Preparation: Hamed_Ghaffari and _R00T

Hints
Solution
Code

2268F - Deglado

Idea: eren__
Preparation: Hamed_Ghaffari and _R00T

Hints
Solution
Code
Challenge
  • Vote: I like it
  • -178
  • Vote: I do not like it

»
6 weeks ago, hide # |
 
Vote: I like it +70 Vote: I do not like it

The gap between D and E is very huge, as 1400 to 2300.

And why $$$O(n^2)$$$ or $$$O(n\log^3n)$$$ can pass E's system test ?????????

»
6 weeks ago, hide # |
 
Vote: I like it +18 Vote: I do not like it

In Hint 2 of the editorial for 1F, I believe you meant '2n*comb(2n, 2) inversions in the worst case', rather than 'n*comb(2n, 2)'.

»
6 weeks ago, hide # |
 
Vote: I like it +10 Vote: I do not like it

E feels soooo hard

»
6 weeks ago, hide # |
← Rev. 5  
Vote: I like it +5 Vote: I do not like it

In problem D you can also generate the set of possible values and check if the array value belongs to the set or not

Code

PS: I'm sure there are better ways to calculate the set but this seemed to work so why not :)

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

    Yeah, the possible values are all numbers either divisibly 3 or 5. This is because for the set of nonpositive integers less than 16, combining three multiples of three yields a number that is either divisible by 3 or 5. Then you just have to show that any two consecutive numbers in that set can be turned into multiples of three with XOR.

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

I feel like another solution of D2D/D1B should be mentioned, making the problem not as ad-hoc (and I think that the fact that xor basis of $$$3k$$$ generates exactly all masks with even popcount is a prime example ad-hoc, because it works up to 4 bits).

The solution is as follows: let's do segment tree, and in each node we'll store $$$dp[start][end]$$$ — maximum number of positions on the interval of the node, if we also xor the first element with value $$$start$$$ and the last element $$$end$$$, these operations cover out-of-bounds elements. Then to merge two nodes we actually need to do matrix multiplication, but with operations $$$(\max, +)$$$: $$$dp[s][e] = \max_t dpl[s][t] + dpr[t][e]$$$. The answer is $$$dp[0][0]$$$ in the root node. This solution works in $$$O(16^3 \log n)$$$, which is a lot. But, maybe not every value of xor can be achieved, if we precalc the set of possible values, we get $$$0,3,5,6,9,10,12,15$$$ — $$$8$$$ elements istead of $$$16$$$. Now matrix multiplication takes $$$8^3$$$ operations and the solution passes.

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

A general Segment Tree + DP solution that doesn't rely on the ai < 16 restriction and works for any ai : note that adjacent pair updates telescope into assigning a net XOR shift vi in W to each element ai, which is valid if and only if the total XOR sum of vi's = 0, where W = span of {3,6,9,12,15} = {0,3,5,6,9,10,12,15} is an 8-element subspace. We can maintain a segment tree where each node stores dp[v] — the maximum number of elements divisible by 3 in its range given a total accumulated XOR sum is v. At a leaf, dp[v] = ((a[i] ^ v) % 3 == 0 ? 1 : 0), and to merge two nodes, we perform XOR group convolution: dp_parent[x ^ y] = max(dp_parent[x ^ y], dp_left[x] + dp_right[y]) for all x, y in W. The answer is dp[0] at the root node, and updates take O(|W|^2 *log N) = O(64 * log N) time.

my submission: https://codeforces.me/contest/2269/submission/392215444

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

    hey man,

    see i did the same thing, but i did in terms of incoming and outgoing edge on the given index. But im not able to understand the idea of total xor = 0, seems like some invalid state also gets counted on..

    for example, if u see my imple, it would be basically equivalent to taking max(seg.root[x][x]), instead of just [0][0], which doesnt seem to be right, it gives the first and last element an in and out edge..

    submission

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

      The 2D merge takes 8^3 = 512 ops, giving 2 * 10^5 queries * 18 depth * 512 = 1.84 * 10^9 operations. While flattening to a 1D state reduces the merge cost to 8^2 = 64 ops (2.3 * 10^8 total ops)

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

In B, why dont simply repeat the operations until a stable state is reached? (it is accepted)

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

    Yes, I did like this. I used the operation for 49 times for each ai, then just compared those values.

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

      Wait how u guys proved for at most 49 operations they will end up as a same number?

      Like if they were in a cycle at different positions in start they eventually don't reach to the same value as the difference in their positions in the cycle remains constant!

      Ig I missed the point that some other number that just entered into the cycle which is not in the cycle in the beginning. (for ex: 19 and 7)

      Correct me if I am wrong.

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

        49 was obviously a random large safe bound :) Ig u can prove within 11-12 steps the number will reach a stable state, like even if u start with 1e9-1, then f(1e9-1) = 9 * 81 = 729, u can see how drastically the number is converging.

        And yes the phase difference of two numbers in a cycle will remain constant and that's why we are not counting those pairs as our answer.

        Edit: just see my submission https://codeforces.me/contest/2269/submission/392186819 I have finally grouped the numbers according to their phase and a pair consisting of different phases is not counted

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

        just use 729 ig , after 1st step , we can say ai <= 729 at max coz the maximum 2nd number as per the bound is 729 , when its 1e9 — 1 , after that i think there will be a tighter bound to make all numbers converge but ig 729 is safe as the maximum length of a possible cycle is 729 , although again for the 3rd iteration the bound is for 999 -> 243 and so on . doing for 729 passes well ig as n <= 1000 ,

        i did for n = 800 , it got accepted .. 393384992

»
6 weeks ago, hide # |
← Rev. 2  
Vote: I like it +4 Vote: I do not like it

392257923

Just barely optimized my $$$O(n^\frac{5}{3}\log A)$$$ solution for 2E/1C to pass (idea is binary search + 3D Mo's). It's probably hackable; have fun trying!

»
6 weeks ago, hide # |
← Rev. 6  
Vote: I like it +1 Vote: I do not like it

Really nice contest, i think for $$$1B$$$ you could also generate the graph for all the $$$16$$$ numbers, and see that all numbers divisible by $$$3$$$ or $$$5$$$ are a maximal connected component, all the other elements cannot reach this component. This is much lazier then the editorial approach but maybe more intuitive during a contest (i did it like this when i upsolved it).

This is the graph as an adjacency list, i hope it makes it clear

0: 3 6 9 12 15
1: 2 7 8 13 14 
2: 1 4 11 14 13 
3: 0 5 10 15 12 
4: 7 2 13 8 11 
5: 6 3 12 9 10 
6: 5 0 15 10 9 
7: 4 1 14 11 8 
8: 11 14 1 4 7 
9: 10 15 0 5 6 
10: 9 12 3 6 5 
11: 8 13 2 7 4 
12: 15 10 5 0 3 
13: 14 11 4 1 2 
14: 13 8 7 2 1 
15: 12 9 6 3 0 

Also for the final part, you can see that for each pair $$$(a,b)$$$ in this component there is always a $$$3k$$$ such that they both land in a number divisible by $$$3$$$ ($$$\exists k\;\; 3 \mid a \oplus 3k \land 3 \mid b \oplus 3k$$$). So the upperbound is always achievable as we can always find such $$$3k$$$ for any adjacent pair.

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

in C, a greedy solution picking max of $$$a[k]$$$ and $$$a[n-k+1]$$$, using an ordered_set or a segment tree works

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

In problem D1D

Since $$$x$$$ is reachable in at most two moves, every position $$$i \lt j \le x$$$ has distance either 2 or 3 from $$$i$$$ .

What about $$$R_i$$$? Isn't it reachable in 1 move

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

    Yes, this is a mistake, after taking 1 move for Ri and rest 2 or 3, the formula is correct.

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

The difficulty gap between problems D and E in div2 is too large.After solving D,it’s just garbage time for me.

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

Problem D idea sharing
I think D is very good problem to show that computer is your best teammate during the contest.

First i don't observe popcount at the begin,i just think if i possible to $$$\oplus$$$ some element from $$$A=\{3,6,9,12,15\}$$$,which number i can get when using element from $$$A$$$ ?This lead to a classic problem,$$$\textbf{xor basis}$$$,given $$$n$$$ numbers,how many distince number you can form,so i just use 5 minutes to quickly run a $$$\textbf{xor basis}$$$ algorithm to see what number i can construct by using element from $$$A$$$,i get a list $$$S=\{0,3,5,6,9,10,12,15\}$$$,i found that the number of element does not appear in $$$S$$$ exactly same as $$$S$$$,and i stuck here,i try to find the pattern to separate element just like parity,the reason is like if i give you $$$[1..n]$$$,you can just separate it into odd number group and even number group,so i believe that,there is some ways like parity to separate them into two group

I just print their binary representation,and i observe something interesting,all element fron $$$S$$$ have a $$$\text{popcount}$$$ even parity and all element not in $$$S$$$ have an $$$\text{popcount}$$$ odd parity,this is important,when i learn FWT ,there is an proof at $$$\text{popcount}$$$,in the rest i will just type popcount as $$$\text{PC}$$$,the proof state that,if $$$x$$$ and $$$y$$$ with same parity of $$$\text{PC}$$$ then $$$x\oplus y$$$ with be the even parity of $$$\text{PC}$$$,otherwise will be odd parity of $$$\text{PC}$$$,now $$$s\in S$$$ is fully even parity of $$$\text{PC}$$$,thus if an element $$$a_i$$$ with odd parity of $$$\text{PC}$$$ will never be a multiple of $$$3$$$,since all multiple of $$$3$$$ have an even parity $$$\text{PC}$$$.

Now the last question is the odd parity $$$\text{PC}$$$ number will separate the array $$$a$$$ into few segment,each segment will all element with even parity $$$\text{PC}$$$,for an segment $$$[l,r]$$$ with length $$$L$$$,is that possible to make all of them divide by $$$3$$$?We define $$$g_i$$$ such that $$$a_i\oplus g_i=3\cdot q$$$,and $$$pfx_i=g_l \oplus g_{l+1} \dots g_i$$$,then just let $$$\forall i \in [l,r) \text{ and } a_i \oplus pfx_i$$$,but the last element $$$a_r \oplus pfx_{r-1}$$$ may not a multiple of $$$3$$$,there is two condition,

  1. If $$$a_{r+1}$$$ is an element with odd parity $$$\text{PC}$$$,just directly make $$$a_r \oplus g_r$$$
  2. If no such element,then we can prove by computer,since $$$a_{r-1}\oplus pfx_{r-1}$$$ is already be a multiple of $$$3$$$ then $$$a_r$$$ is not a multiple of $$$3$$$ and with even parity $$$\text{PC}$$$,define set $$$U=\{0,3,6,9,12,15\}$$$ and set $$$V=\{5,10\}$$$,you just brute force it use a element $$$u\in U$$$ and $$$v\in V$$$ and such that need a $$$h$$$ to make $$$u\oplus h$$$ and $$$v\oplus h$$$ is a multiple of $$$3$$$ and it can be show that every pair of $$$(u,v)$$$,it exist such a $$$h$$$

So we may conclude that if $$$a_i$$$ with even parity of $$$\text{PC}$$$,then there is possible to make it become multiple of $$$3$$$

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

My $$$O(18n\log n)$$$ was hacked :(

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

    Was that because of branching to a random bit on trie when some bit is 0 on max(l, r)? or were u reconstructing the trie every time u go up on the cartesian tree with the new mask? idk I couldn't really understand why did people who used Trie get hacked. I was searching for a soulution with Trie and I just realized that branching to different bits when max(l, r)'s bit is 0 leads to two different answers. And is there a working solution with Trie?

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

      U R right, I didn't even notice the issue! thx

      • »
        »
        »
        »
        5 weeks ago, hide # ^ |
        ← Rev. 4  
        Vote: I like it +1 Vote: I do not like it

        You can do a binary search on trie. for example first you are going to aim for getting 1XXX then if you can get the first 1 try 11XX if you can't try achieving 01XX and so on. This is the correct solution if you still want to use Trie unlike the editorial I guess.

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

Guys, im a newbie to cf, i tried problem B for almost 5+ hrs but still cant able to settle in a decision,

it seems im overlooking something

i checked for self-cycles to break and if the intermediate number found in other process i add to map to prove they form a pair whats wrong, sm1 help

/*
 * File: B.cpp
 * Author: Harish Muthaiyan
 * Created: Saturday, September 27th 2026, 9:30:46 pm
 */

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
void __dbg() {cerr << '\n';}

template<typename Head, typename... Tail>
void __dbg(Head H, Tail... T) {
	cerr << H;
	if(sizeof...(T)) cerr << ", ";
	__dbg(T...);
}

#define dbg(...) cerr << "DEBUG: [" << #__VA_ARGS__ << "] = ", __dbg(__VA_ARGS__)

void run_case() {
	int n;
	cin >> n;
	int a[n];
    for(int i = 0; i < n; i++) {
        cin >> a[i];
    }
    
    bool maxi = false;
    unordered_map<int, unordered_set<int>> mpp;

    for(int i = 0; i < n; i++) {
        int _n = a[i];
        while(true) {
            if(mpp.count(_n)) {
                // '&' to avoid deep copy
                unordered_set<int>& par = mpp[_n];
                if(par.count(i)) {
                    break;  // cycling itself
                } else {
                    // found in some other process
                    par.insert(i);
                    if(par.size() == n) {
                        maxi = true;
                        break;
                    }
                }
            } else {
                mpp[_n] = {i};
                if(n == 1) {
                    maxi = true;
                    break;
                }
            }
            int sum = 0;
            while(_n > 0) {
                int d = _n % 10;
                sum += d * d;
                _n /= 10;
            }
            _n = sum;
        }

        if(maxi) break;
    }
    ll sz = 0;
    for(auto& [k, v]: mpp) {
        if(v.size() > sz) {
            sz = v.size();
        }
    }

    ll nC2 = (sz*(sz-1))/2;
    cout << nC2 << '\n';
}

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);

	int tt = 1;
	cin >> tt;
	auto start = chrono::high_resolution_clock::now();
	while (tt--) {
		run_case();
	}
	auto end = chrono::high_resolution_clock::now();
	#ifndef ONLINE_JUDGE
		cerr << "\nTime: "
     	<< chrono::duration<double, milli>(end - start).count()
     	<< " ms\n";
	#endif
	return 0;
}
  • »
    »
    6 weeks ago, hide # ^ |
     
    Vote: I like it 0 Vote: I do not like it

    i suggest you to transform each element multiple times (say 100 times), then count equal element pairs

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

      but how can we be so sure that every number $$$x$$$ $$$\in$$$ $$$[1, 10^9]$$$ would be part of a cycle in just $$$100$$$ transformations?

      some users got accepted with only $$$49$$$ transformations, so what is the actual upper bound for it, and how do you prove it?

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

Problem Div2 $$${B}$$$, it's pure guess works, with no valid proof, and a vague solution in the editorial.

There is no proof why every number would eventually be a part of the two cycles mentioned. The only thing convincing is that, the maximum sum of the squares of digits that we can get from a number can be $$$729$$$, so somehow it has to repeat some number after at max $$$729$$$ operations.

But this part is totally missing in the editorial. Maybe the problem isn't bad, but the editorial is definitely bad for the problem Div2 $$${B}$$$.

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

    It's possible to solve the problem without "the fact" (all numbers converge to one of the two cycles). I actually solved the problem in the following way.

    First, simulate the process for each number until you find a cycle. For each $$$a_i$$$, record the following $$$(m_i, p_i, c_i)$$$: $$$m_i$$$ is the minimum number in the cycle, $$$p_i$$$ is the (0-based) index where $$$m_i$$$ appears, and $$$c_i$$$ is the length of the cycle.

    Then, for every pair of indices $$$(i, j)$$$, compare $$$m_i$$$ and $$$m_j$$$. If $$$m_i \ne m_j$$$, there's no possibility that the two sequences converge. If $$$m_i = m_j$$$, then $$$c_i = c_j$$$ must hold, and then you just need to check $$$p_i \equiv p_j \; (\text{mod} \; c_i)$$$: if this equation holds, the sequences will converge eventually.

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

      notice there is no reason to simulate for each ai, as it might cost up to 240 (but it costs less and n<=1e3 so it still works) but as I have written below you can simulate for a number and not index, you can look at my comment below

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

    Yes I agree, I also find it troubling to understand the solution to Div1 C/ Div 2 E

    but you have the following, as you said after one operation all the numbers are from 1 to 729 the graph that has an edge from x to square_digits(x) is a functional graph, just a pretty name for graphs where each node has one place to go, in each connected component in such graph looks like a circle and from each node in the circle there might be a tree, therefore we can say for each number from 1 to 729 run the operation 730 times, now if two numbers were the same they stayed the same therefore you can only check how many pairs are the same, (730 times so every node must get to the circle in the connected componnet)

    complexity O(n + 729*730 + 729) = O(n + 730^2)

    with no absolute crazy saying that there are only two circles

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

    I also think the editorial for D2B is a bit complex. I wonder if anyone found that there were only two cycles in contest mathematically, and what was the motivation?

    In addition, I have another solution. Apply the operation (x becomes the sum of square of digits of x) on every $$$a_i$$$ for a lot of times. Now, if two $$$a_i$$$ become the same, we count them, and that's the answer.

    We apply the operation on every number for $$$162+3$$$ times, and every number must enter a cycle after this. Then, if $$$x$$$ appeared for $$$y$$$ times in the transformed array, we add $$$\frac{y(y-1)}{2}$$$ to the answer. Time $$$O(165n+162)$$$ or $$$O(n)$$$.

    The bound $$$162+3$$$ is obtained by applying the operation on array $$$a_i$$$ multiple $$$3$$$ times. First time, bound becomes $$$729+1$$$. Second time, $$$198+2$$$. Third time is $$$162+3$$$. This can probably be lowered more using some reasoning like any three digit numbers after three operations must go below $$$107$$$ or smth.

    submission

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

    Thanks to ItayKarny for the comment mentioned functional graph, it gave me a new idea after the contest!

    Since it is a graph where each state has exactly one outgoing edge, we can simulate dfs and use dfn order to preprocess each state's final cycle id, cycle length, and phase in $$$O(num\ of\ states)$$$. Here's my submission:395911228

    But when the number of states is small, simply running the operation enough times is undoubtedly a very, very clever choice!

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

In B, any number being part of these two cycles is not an obvious fact. You need to provide the proof, or atleast the intuition, and not let people brute force the sequences and guess the pattern.

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

    Hi, expertaq, you can look at the comment mentioned functional graph and my comment. Actually, we don't need to prove or find the number of cycles and the cycle lengths by ourselves.

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

I wasn't able to participate in this contest, so I went to the problemset after to solve a couple problems and clicked problem A. I've never solved a Div 2 C problem in contest, but I accidentally solved it in 5 minutes because I thought it was problem A (it was problem A for Div 1) LOL

This was my solution, seems simpler than the editorial solution:

#include <bits/stdc++.h>
using namespace std;
 
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
 
    int tt;
    cin >> tt;
    while (tt--) {
        int n, k;
        cin >> n >> k;
        vector<long long> a(n);
        for (int i = 0; i < n; i++) cin >> a[i];
 
        long long ans = 0;
        while (a.size() >= k) {
            int lo = k - 1;
            int hi = a.size() - 1 - (k - 1);
            if (a[lo] > a[hi]) {
                ans += a[lo];
                a.erase(a.begin() + lo);
            } else {
                ans += a[hi];
                a.erase(a.begin() + hi);
            }
        }
 
        cout << ans << '\n';
    }
 
    return 0;
}
  • »
    »
    6 weeks ago, hide # ^ |
     
    Vote: I like it 0 Vote: I do not like it

    this is $$$O(n^2)$$$ how tf did this solution passed?

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

      I was thinking that too. But the submission took 703ms, well below the 2s limit.

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

    Yeah, I saw people in contest get AC with O(n^2) solutions as well, maybe if there were hacks they could potentially get TLE. I used a Segment Tree to track the positions lol.

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

_R00T eren__ sweetweasel Hamed_Ghaffari

Please pin announcement and editorial to the contest.

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

For B, can we prove that there are only 2 cycles possible. I ran the simutation and yes those are the only set of possible values after like 50 operations, but is there a proof for it?

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

    try to prove it by yourself

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

    For sufficiently large $$$n$$$ the number after the operation will always be smaller than before, after computationally verifying for small $$$n$$$ we can use strong induction

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

      Yes, there are 1e9 elements which are reduced to 729, so there must be cycles happening inside this. But can we prove that there are exactly 2 cycles without using bruteforce?

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

        I don't see any other way, brute forcing for small $$$n$$$ and strong induction for sufficiently large is a valid proof

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

    Hi, wanna-be-HIM, also can't prove it :( But you can look at my comment. I came up with a preprocessing method only takes $$$O(num\ of\ states)$$$, and we don't need to prove the number of cycles or the lengths ourselves.

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

My Solution to D: KINDA BRUTE FORCE BUT SUBTLE - The XOR of any a[i] with any other number x in the constraints of the problem is always < 16. - It's given in the problem that you can XOR a[i] and a[i+1] with 3*k. Where 1 <= k <= 5. - This means that the possible XORs candidates to XOR the elements with is set st = {3,6,9,12,15}. - So if we make a combination of many operations per pair (a[i], a[i+1]), then it is like XORing with one of the many XOR combinations of st. For example I can make operations on a pair first with 3, then 6, then probably 15. So it's like the combination of any number of elements in the set st. And then finally XOR this combination result with the pair (a[i], a[i+1]) - Obviously it is of no use to use the same element to XOR again and again cuz it doesnt change the result of the final XOR of the two elements in any way. - An interesting observation is that any combination of the XORs will only give you numbers in the set num = {0,3,5,6,9,10,12,15}. And also, it can be seen that only elements in the array which already belong to the set num can be ever made to be divisible by 3. All the others will never give any result divisible by 3. You can simply test this out by taking all the numbers from 1 — 15 and then XORing it with the elements in the num set. - So the algorithm is fairly simple now, keep a present[] array which tracks the elements in the array which are present in the num set; 1 for present and 0 for not present. Have a ctr variable initialized to the number of elements in the array which belong the set. If at the qth query we replace an element in the array which is 1 in that index in the present array with an element which is not present in the num set, then decrease the ctr by 1. If at the qth query we replace an element in the array which is 0 in that index in the present array with an element which is present in the num set, then increase the ctr by 1.

Here's my code:

392366386

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

During the contest, I felt that for Problem B, the values would enter a cycle very quickly, so I wrote a brute-force function to check whether two numbers would eventually become equal. The logic is simple: just simulate both of them for 100 iterations, and then iterate over all pairs.

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

Problem B could have had a better reading code and a less complicated explanation.

»
6 weeks ago, hide # |
 
Vote: I like it -8 Vote: I do not like it

Was it just me or was d1C editorial written by chatgpt again :sob:

Anyway even though I got cooked by it I think it's a pretty good problem, yeah there's a huge gap but whatever. The only complaint I have is that once I read a few hints I found a n log^3 (log from binsearch, log from small to large, and another log from I was planning to use std::set to do the prefix xor stuff). Removing that log factor felt like yet another hurdle to jump through (though I will admit that the way to do it by only doing frequency array on the big side so you don't run out of memory is pretty interesting to me)

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

On F you can reject a grid before building any moves. Xor the inversion parity of every column. A 2x2 swap always flips two columns, so that xor never changes, and a sorted grid is 0. If you start at 1, it's -1.

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

Div 2 E can be solved via bitwise xor prefix sums right ? (From msb to lsb try to find a range that has this bit and already fixed bits counts as odd , from this result fix or dont fix this bit).

This approach is a lot simpler in my opinion and tiny bit more implementation.

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

I spent 30 minutes reading 2E only to comeback do 2D to brute and solve it after 15 minutes lol. Typical DNC problem, I have never be able to solve it in strict contest time lol

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

Div2 F, vec needn't be an array of vectors. it can just be an array. This confused me so much.

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

For Div1E, standard 3-NTT convolution can squeeze in the time limit with a fast enough template, which skips most of the problem's difficulty.

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

garbo round

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

For A : Delay the first withdrawal as much as possible while still leaving enough days to perform the remaining (k-1) withdrawals, then withdraw every day until the bank closes.

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

For 2269C — K Is Important / 2268A — K Is Important

PS:- Took this idea from cses Problem set , seemed very intuative to me

import sys

class FenwickTree:
    def __init__(self,arr):
        self.n=len(arr)
        self.tree=[0]*(self.n+1)
        for i in range(1,self.n+1):
            self.tree[i]+=1
            parent=i+(i&(-i))
            if parent<=self.n:
                self.tree[parent]+=self.tree[i]

    def update(self,index,delta):
        i=index
        while i<=self.n:
            self.tree[i]+=delta
            i+=i&(-i)

    def query(self,index):
        total_sum=0
        i=index

        while i>0:
            total_sum+=self.tree[i]
            i-=i&(-i)

        return total_sum

    def find_sum(self, target):
      
        low = 1
        high = self.n
        ans = -1

        while low <= high:
            mid = (low + high) // 2
            current_sum = self.query(mid)

            if current_sum == target:
                ans = mid
                high = mid - 1 
            elif current_sum > target:
                high = mid - 1
            else:
                low = mid + 1

        return ans



input=sys.stdin.read().split()
it=iter(input)
t=int(next(it))

for _ in range(t):
    n,k=int(next(it)),int(next(it))
    arr=[int(next(it)) for _ in range(n)]
    ft=FenwickTree(arr)
    res=0
    curr_len=ft.query(n)
    while curr_len>=k:
        idx_1=ft.find_sum(k)
        idx_2=ft.find_sum(curr_len-k+1)
       

        if arr[idx_1-1]>arr[idx_2-1]:
            res+=arr[idx_1-1]
            ft.update(idx_1,-1)
        else:
            res+=arr[idx_2-1]
            ft.update(idx_2,-1)

        curr_len=ft.query(n)


    print(res)
            

            


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

Problem D is quite simple, but the thinking process really made me feel awkward.

»
12 days ago, hide # |
← Rev. 2  
Vote: I like it 0 Vote: I do not like it

$$$O(b \, n \log^2 n)$$$ is not supposed to pass for E?