Kirill_Maglysh's blog

By Kirill_Maglysh, history, 2 years ago, translation, In English

1945A - Setting up Camp

Idea: Kirill_Maglysh

Tutorial
Solution

1945B - Fireworks

Idea: NToneE, Gadget

Tutorial
Solution

1945C - Left and Right Houses

Idea: Gadget, NToneE

Tutorial
Solution

1945D - Seraphim the Owl

Idea: Kirill_Maglysh

Tutorial
Solution

1945E - Binary Search

Idea: Kirill_Maglysh

Tutorial
Solution

1945F - Kirill and Mushrooms

Idea: Kirill_Maglysh

Tutorial
Solution

1945G - Cook and Porridge

Idea: Kirill_Maglysh

Tutorial
Solution

1945H - GCD is Greater

Idea: Kirill_Maglysh

Tutorial
Solution
  • Vote: I like it
  • +38
  • Vote: I do not like it

| Write comment?
»
2 years ago, hide # |
 
Vote: I like it +11 Vote: I do not like it

For problem G the editorial has the swapped inequality it should be suffixMax_p >= k(Q2_front), because that indicates there is a larger k in the suffix of Q1 that highest priority person in Q2 would be waiting behind.

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

Problem E Video Editorial Audio : (Hindi)

YOUTUBE VIDEO LINK ---Click Here

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

At problem B,

"At the moment x, there will be fireworks in the sky, released at moments [x, x+a, …, x+a⋅⌊m/a⌋]"

Please explain.

»
2 years ago, hide # |
 
Vote: I like it +1 Vote: I do not like it

Problem F can be simulated with an ordered statistic tree :p

252626826

»
2 years ago, hide # |
Rev. 4  
Vote: I like it 0 Vote: I do not like it

In C sample 1.

3
101
outut:2

"can't we insert at 0 the villagers to right side 2 of 3 are satisfied ?

If there are multiple suitable positions i with the minimum ∣n2−i∣, output the smaller one."

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

nvm, i got it lol good contest btw

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

I think the problem G's statement is still not 100% clear. If 2 students with the same priority, finishing their dishes at the same time, who will go to the queue first?

I tried to solve this solve this by assuming the one who goes out eating first will come back first, but apparently this seems to not be the case. The comparator function in the solution prioritize the student with higher eating time first. This seems very unnatural to me.

Though the problem idea didn't change much if a more strictly description was added. This is still a cool problem. Though this bug me for hours, not know where I was wrong.

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

Can anyone explain E? Not able to get it from the tutorial.

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

    We know this binary search gives a number which is always <=X. (If you are not sure about that, you can try some examples.)

    Assume P is position of X.

    If we change this result and P, we can find X. Because only once we asked to P. And smaller number will give same answer(make l = mid). So we will get same index before don't swapped P and result.

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

in problem H why if a bit is 0 in more than 2 numbers then its 0 in the AND ? i understand that if we have 3 or more numbers with bit x 0 in them then it'll always be zero in the finally AND but sometimes we can have only 1 number with bit x equal to 0 and still the finally AND will have that bit 0 if we dont consider it in the red numbers ? the middle paragraph is unclear hope somebody rewrites it in a more clear way , thanks

  • »
    »
    2 years ago, hide # ^ |
     
    Vote: I like it +3 Vote: I do not like it

    Your understanding is correct. Suppose we are dealing with $$$x^{th}$$$ bit. There are 3 cases:

    1. None of the numbers contain a 0 at this position : The AND would contain 1.
    2. There are $$$ \gt 2$$$ 0 at this position. The AND would contain 0.
    3. There are 1 or 2 zero at this position. Then, we are not sure about the AND. But, let's pick one element with zero at this position, move it to the blue set, and then, let's try to pair it up with all possible elements. If no match could be found, then we know for sure that the element belongs to the red set, hence making the AND zero.

    I've added more details here

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

      Yea thanks I got it , it wasn't clear at the beginning I feel like it would've been more clear if they stated why we try all numbers where the bit is 0 in no more than 2 but now that I get it I feel like it's self explanatory

»
22 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

Problem F. Kirill and Mushrooms can actually be solved using Fenwick Tree:

Let us fix the number of mushrooms for a potion. Let this number be $$$k \leq n$$$. Now we have to maximize the minimum value that we choose for this potion. This number is the $$$k-th$$$ maximum, lets call this number $$$mxmin$$$. And we update the answer with $$$ans=min(ans,mxmin*k)$$$.

Fenwick Tree allow us to find the $$$k-th$$$ maximum, wich is equivalent to findind the $$$(rem - k + 1)-minimum$$$ with BinaryLifting. Where $$$rem$$$ is the remaining number of mushrooms. You can find how to do this in this blog

When we go from $$$k$$$ mushrooms to $$$k+1$$$ mushrooms we have to update the FenwickTree by subracting the value of the $$$p[k]$$$ mushroom.

See the code for any other detail: My submission

»
22 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

For problem F you can just use order statistic tree and use find_by_order to solve in nlogn time.

»
14 months ago, hide # |
Rev. 2  
Vote: I like it 0 Vote: I do not like it
#include <bits/stdc++.h>
using namespace std ;
#define ld long double
#define ll long long
int fact[400001] = {0};
vector<vector<int>> num(400001);
vector fst(400001,vector<int>(20,0));
unordered_set<int> s;
int mul = 1;
void gen( vector<int> &num, int in = 0 ) {
    if( in == num.size() ) s.insert(mul);
    else {
        mul *= num[in];
        gen(num,in+1);
        mul /= num[in];
        gen(num,in+1);
    }
}
signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    fact[1] = 1; 
    for( int i = 2; i <= 4e5; ++i )
    if( fact[i] == 0 )
    for( int j = i; j <= 4e5; j += i )
    if( fact[j] == 0 ) fact[j] = i; 
    int tt = 1;
    cin >> tt;
    while( tt-- ) {
        int n, k, flag = 0, x; 
        cin >> n >> x;
        int miny = (1<<20), inx, iny;
        vector<int> a(n);
        int bit[20] = {0};
        for( auto &i: a ) cin >> i;
        sort( a.begin(), a.end() );
        for( int i = 1; i < n; ++i ) {
            if( (a[i-1] & a[i]) < miny ) {
                miny = a[i-1]&a[i];
                inx = i-1;
                iny = i;
            }
        }
        set<int> o;
        for( auto &i: a ) {
            int j = i;
            vector<int> pf;
            while( j != 1 ) {
                pf.push_back(fact[j]);
                j /= fact[j];
            }
            vector<int> stbit;
            for( int u = 0; u < 20; ++u ) 
            if( ((i>>u)&1) )
            ++bit[u], stbit.push_back(u);
            gen(pf);
            for( auto &u: s ) {
                o.insert(u);
                num[u].push_back(i);
                for( auto &h: stbit )
                fst[u][h]++;
            }
            mul = 1;
            s.clear();
        }
        for( auto k = o.rbegin(); k != o.rend() && flag == 0 ; ++k ) {
            int g = *k;
            if( num[g].size() < 2 ) continue;
            int sz2 = n - num[g].size();
            int y = 0;
            for( int i = 0; i < 20; ++i )
            if ( bit[i] - fst[g][i] == sz2 )
            y += (1<<i);
            if( y + x < g && sz2 >= 2 && sz2 <= n-2 ) {
                flag = g;
                break;
            } 
            for( int u = 19; u >= 0 && flag == 0 ; --u ) 
            if( (y>>u)&1 ) {
                int d = -1;
                for( int i = 0; i < num[g].size(); ++i ) 
                if( num[g][i] != -1 ) {
                    if( d == -1 && ((num[g][i]>>u)&1) == 0 ) d = i;
                    if( d != -1 && (y&num[g][i]) < (y&num[g][d]) ) d = i;
                }
                if( d != -1 ) {
                    sz2++;
                    y = y&num[g][d];
                    num[g][d] = -1;
                }
                if( y + x < g && sz2 >= 2 && sz2 <= n-2 ) {
                    flag = g;
                    break;
                } 
            }
            if( sz2 == 0 ) {
                sz2 = 2;
                y = miny;
                num[g][inx] = num[g][iny] = -1;
            } else if( sz2 == 1 ) {
                sz2 = 2;
                int d = -1;
                for( int i = 0; i < num[g].size(); ++i ) {
                    if( d == -1 ) d = i;
                    if( d != -1 && (y&num[g][i]) < (y&num[g][d]) ) d = i;
                }
                y = y&num[g][d];
                num[g][d] = -1;
            }
            if( y + x < g && sz2 >= 2 && sz2 <= n-2 ) {
                flag = g;
                break;
            } 
        }
        if( flag != 0 ) {
            cout << "YES\n";
            vector<int> v1, v2;
            for( auto &i: num[flag] )
            if( i != -1 )
            v1.push_back(i);
            int i = 0;
            for( auto &j: a )
            if( i >= v1.size() || v1[i] != j ) v2.push_back(j);
            else ++i;
            cout << v1.size() << ' ';
            for( auto &i: v1 ) cout << i << ' ';
            cout << '\n' << v2.size() << ' ';
            for( auto &i: v2 ) cout << i << ' ';
            cout << '\n';
        }
        else cout << "NO\n";
        for( auto &i: o ) {
            num[i].clear();
            fst[i] = vector<int>(20,0);
        }
    }
}

this code for h but get wrong answer at testcase 3.Had tried stress test but not found any

kindly help me to debug this