JuicyGrape's blog

By JuicyGrape, 2 years ago, In English

We thank everyone who participated in the round.

1968A - Maximize?

Author: JuicyGrape

Hint 1
Hint 2
Hint 3
Solution
Implementation
Rate the problem

1968B - Prefiquence

Author: FBI

Hint 1
Solution
Implementation
Rate the problem

1968C - Assembly via Remainders

Author: JuicyGrape

Hint 1
Hint 2
Hint 3
Solution
Implementation
Rate the problem

1968D - Permutation Game

Author: FBI

Hint 1
Hint 2
Solution
Implementation
Rate the problem

1968E - Cells Arrangement

Author: JuicyGrape

Hint 1
Hint 2
Hint 3
Solution
Implementation
Rate the problem

1968F - Equal XOR Segments

Author: JuicyGrape

Hint 1
Hint 2
Hint 3
Hint 4
Solution
Implementation
Rate the problem

1968G1 - Division + LCP (easy version)

Author: JuicyGrape

Hint 1
Hint 2
Solution
Implementation
Rate the problem

1968G2 - Division + LCP (hard version)

Author: JuicyGrape

Hint 1
Hint 2
Solution
Implementation
Rate the problem
  • Vote: I like it
  • +93
  • Vote: I do not like it

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

any good resources or blogs to explain Z-function?

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

I was thinking too complex at the problem D

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

Should Problem B be just a 2 pointer problem with a time complexity of O(min(a, b))?

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

    Yeah,that is one of the possible solutions. However, it is easier to explain the dp solution)

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

There exists an $$$\mathcal{O}(n \log^2 n) $$$ solution with a very good constant factor for G2, reply to this if interested.

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

    I just thought of one too. Does it involve sorting and parallel binary search?

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

      You don't need any of that. You could simulate what you do in G1 with a set/segment tree by iterating over the lengths, and it works. The time complexity came from harmonic series and the log from DS.

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

      Not sure what “parallel binary search” means, but it is nested binary search. I don't sort anything.

      Basically, we still have our nice $$$z$$$ function, however, we will also store an RMQ which can get the maximum value of $$$z_i$$$ for all $$$i$$$ in a range $$$[l, r]$$$.

      Let's precompute the value $$$mx_i = \text{maximum number of disjoint substrings with length } i, \text{which are all equal to the prefix of length } i$$$

      If we want to check if $$$k$$$ disjoint substrings are possible with $$$\text{LCP}$$$ $$$l$$$, we just check if $$$mx_{l} \ge k$$$.

      Now the problem is the computation of $$$mx$$$.

      For length $$$i$$$, there can be at most $$$\frac{n}{i}$$$ disjoint substrings with that length. Let's use the fact that $$$\sum_{i=1}^{n}\frac{n}{i}=\mathcal{O}(n \log n)$$$.

      Using our RMQ, we can, instead of calculating $$$mx_i$$$ in linear time in the length, we can calculate it in $$$\mathcal{O}(mx_i \log n)$$$, simply binary search on the next $$$j$$$ such that $$$z_j \ge i$$$ (here, we binary search and use a sparse table to get this next $$$j$$$ in $$$\mathcal{O}(\log n)$$$, alternatively, you can walk on a segment tree in $$$\mathcal{O}(\log n)$$$).

      The complexity of this computation is $$$\sum_{i=1}^{n}mx_i\cdot \log n = \log n \sum_{i=1}^{n} mx_i \le \log n \sum_{i=1}^{n}\frac{n}{i}=\mathcal{O}(n \log^2 n)$$$

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

FOR G2: answer f(x) is decreasing function, so i just modified simple binary search solution for G1, by just changing the upperlimit as previous answer.
Code: 259245908
I am not able to prove this tho... please help me.

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

Thanks for your brilliant problems! Round was fun enough to spend full competition time just solving the problem.

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

Can someone please tell me what's the rating of problem D? I'm asking because the rating is not updated on the problem tag.

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

For B: Optimise Answer

void solve() {
    int n, m; cin >> n >> m;
    string a, b; cin >> a >> b;
    
    int j = 0;
    for(int i = 0; i < m; i++) {
        if(a[j] == b[i]) j++; 
    }

    cout << j << endl;
}
»
2 years ago, hide # |
 
Vote: I like it +3 Vote: I do not like it

Made video editorials for C,D,E for whoever wants to refer

C : https://www.youtube.com/watch?v=oEx5rR4wAKw

D : https://www.youtube.com/watch?v=XBUN4LwolEM

E : https://www.youtube.com/watch?v=DObsk_Rlhg8

language => Hindi

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

In problem F, my submission 259182179 has been hacked. But I resubmit it and got AC... Could anyone tell me why???

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

    Testset hasn't been updated yet, all AC solutions will be retested during some hours with updated tests

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

    Your resubmission will soon give WA verdict after system testing. In current System's all testcases are those that were during the contest [where u got AC]. Now, all the testcases that could hack other's solution, will be added in the System testcases[including the testcase that could hack ur F no. solution] and System test will run again. Then, u will get a different verdict.

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

    Uphacked as per your wish :) now it should be automatically added to the tests already.

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

    fine... new submission has been uphacked :(

    i should use map replace unordered_map

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

G1/G2 can be solved without any fancy algorithms as in my rust solution in C++ too: 259314092

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

Is this solution for G2 hackable? Using two heurestics:

1) Memoising the value of cnt calculated in f(mid)

2) Since the answer always decreases on increasing k, keeping the value of hi from previous k(not setting it to n again).

Not able to proove it's time complexity.

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

    I have done the same thing, and I was able to prove the complexity to some extent. It's easy to see that my code is $$$\mathcal{O(n\cdot\text{number of distinct values of } mid})$$$.

    First let's assume $$$l=1$$$ and $$$r=n$$$, the binary search ranges are $$$[1,n],[1,\frac{n}{2}],\dots,[1,\frac{n}{n}]$$$.

    The main observation is this, the range $$$(\frac{n}{2},n]$$$ is exposed to $$$1$$$ binary search, the range $$$(\frac{n}{3},\frac{n}{2}]$$$ is exposed to $$$2$$$ binary searches. Similarly, the range $$$(\frac{n}{i},\frac{n}{i-1}]$$$ is exposed to $$$i-1$$$ binary searches.

    It is clear that with this, we have a very loose upper bound of $$$O(n\cdot\sum_{i=2}^{n}\min((i-1)\cdot\log(n), \frac{n}{i-1}-\frac{n}{i})$$$. However, as i said, this is very loose, as the sum $$$\sum_{i=2}^{n}(i-1)\cdot\log(n)$$$ is quite a bit more than $$$n\cdot\log(n)$$$ (the total number of checks).

    We can make this tighter.

    Let's consider the ranges $$$1$$$ by $$$1$$$, first we have the range $$$(\frac{n}{2}, n]$$$. We have $$$2$$$ cases, the first case is that $$$\log(n)$$$ is smaller than the range, in which case (for the sake of an upper bound), we should assume that we take all the $$$\log(n)$$$ checks from that range, becuase we will never see that range again, so it is best to take as much as we can from that range, hence decreasing the number of times the other ranges can be chosen by $$$\log(n)$$$.

    However, if the range length is less than $$$\log(n)$$$, then all the next ranges are also smaller than $$$\log(n)$$$. So in fact, a better upper bound is $$$\mathcal{O(n\cdot\sum_{i=2}^{n}\min(\log(n),\frac{n}{i-1}-\frac{n}{i}))}$$$, this value is $$$733800000 \approx 7\times 10^8$$$ for $$$n=2\cdot 10^5$$$.

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

      The point where the minimum changes from $$$\lg n$$$ to $$$n/(i-1)-n/i$$$ will be $$$i\approx i_0=\sqrt{n/\lg n}$$$, so this analysis gives a runtime bound proportional to around $$$n\cdot ((n/i_0)+(\lg n)\cdot i_0)=2 n \sqrt{n \lg n}$$$.

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

For G2 there is also solution using the problem:

-we can deactivate an element

-we need to find the closest active element to the right

That can be done using dsu

Then we'll increase lcp. When we increase it by one, we deactivate elements, so we're left only with elements with $$$z_i \ge curLCP$$$ where $$$z_i$$$ is z-function.

To find maximum $$$k$$$ that can achieve at least $$$curLCP$$$ we will start at the beginning and then jump to the next active element of $$$i + curLCP$$$. Since the answer for $$$curLCP$$$ is at most $$$\frac{n}{curLCP}$$$, $$$O(ans)$$$ solution works in $$$O(n log n)$$$, and dsu gives us either $$$\alpha(n)$$$ or $$$log n$$$

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

In G2, shouldn't the time complexity of the case when $$$k \gt \sqrt{n}$$$ be $$$\mathcal{O}(n \sqrt{n})$$$? (the editorial says it's $$$\mathcal{O}(n \sqrt{n} \log{n})$$$)

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

approx. rating of G2? 2100+ right?

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

For G2 I had a similar idea to use the fact that the answer only changes a few times and I calculated the answer for each segment with new n/l.

However, this got WA, not sure why, so I replaced it with an O(n*log^2(n)) (please someone correct me if I'm wrong).

You first binary search for the leftmost index with an answer less than the last one.

Here's the submission 259255876

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

    It TLE'd on the general test. :(

    shouldn't O(N log^2 (N)) <= O(N sqrt(N))

    I'll try analyzing the complexity and if someone can correct me...

    1- Calculating the Z function is done in O(N)

    2- Then there's the check which is also O(N)

    3- Both binary searches are log(N)

    4- is there a sqrt(N) I'm missing maybe?

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

    My friend had an $$$O(n \log^2{n})$$$ solution that ACed (which I believe uses a similar idea to your $$$n/l$$$ thing), if you wanna check that out.

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

      I don't quite understand tbh. if you could explain it to me please... unforgettablepl

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

        In my code, the calc function is pretty much the same as the check function in your code. The got variable in your code stores the maximal k such that the answer is >= len. In my code, the calc function returns the got variable. Now I make an array called ans where ans[i] = maximal k such that the answer is >= i using this function. For answering queries I just binary search over this answer array.

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

Use hash to check whether two string equal again.

And be hacked again (((

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

    I used hashing too, but I wasn't hacked since I used mersenne twister to randomly select mod for hashing.

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

      Can you share your hashing template?

      • »
        »
        »
        »
        2 years ago, hide # ^ |
         
        Vote: I like it +4 Vote: I do not like it
        mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
         
        struct Hash {
            int n;
            string s;
            const ll p = 31;
            ll mod = uniform_int_distribution<int>((int)(1e9+7), (int)(1e9+1e8))(rng);
            vector<ll> pw, hash;
         
            Hash(string _s) : s(_s) {
                n = s.size();
                pw.resize(n+1);
                hash.resize(n+1);
                pw[0] = 1;
                for(int i=1; i<=n; i++) pw[i] = (pw[i-1] * p) % mod;
                hash[0] = s[0] - 'a' + 1;
                for(int i=1; i<n; i++) hash[i] = (hash[i-1] + pw[i] * (s[i] - 'a' + 1)) % mod;
            }
         
            ll getHash(int l, int r) { return (hash[r] - (l ? hash[l-1] : 0) + mod) % mod; }
         
            bool equal(int l1, int r1, int l2, int r2) {
                if(r1 - l1 != r2 - l2) return 0;
                if(l1 > l2) swap(l1, l2), swap(r1, r2);
                return (pw[l2-l1] * getHash(l1, r1) % mod) == getHash(l2, r2);
            }
        
            bool isPal(int l, int r) {
                return equal(l, r, n-1-r, n-1-l);
            }
        };
        

        Here you go.

        Also be aware that the function isPal only works if the to the string is appended its reverse.

        For example, let's say we will call isPal for the string s = "cabad".

        To chech is substring from "aba" is palindrome, you have to initialize the hashing structure with the string "cabaddabac"

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

Why such tight constraints on G2, $$$n \leq 2\cdot 10^5$$$ when the intended time complexity is $$$O(n\sqrt{n}log(n))$$$??

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

Hey,

  1. G2 is solvable in O(NlogNlogN): checking the maximum number of intervals one can separate in such that the common prefix has length at least k is doable in O(N/k logN) if we store the valid indices with Z[i]>=k in a set.

  2. Can someone understand why the solution to F gives TLE if we use unordered_map<int,vector > instead of map<int,vector >? My solution using unordered_map was TLEd in the main tests, and the official solution has the same issue when we use unordered_map. This seems unintuitive as we never use the key ordering.

Thanks!

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

    For the 2nd point, I think even from the main tests have some exploits on unordered_map to cause enough hash collisions for $$$\mathcal{O}(n)$$$ access. It's been a common exploit for quite a while, and it's due to hash table's nature itself, as long as its hashing could be reverse engineered.

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

now I get it

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

Is there any tutorial for that Z function used in G1?

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

Can anyone refer me more problems like E?

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

why do we usually use a segment tree for finding xor on segments and not just how it was described in the problem f? or we just do this only when elements don't change?

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

I think there's an error in the editorial for problem F. It says "we may find the largest t <= r" but it should be t < r since if t == r then the segment [t+1, r] would not make sense. I tried a solution with this change in mind and it got AC. 259369531

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

Anyone has an idea why this one gets TLE https://mirror.codeforces.com/contest/1968/submission/259216131 ? it is exactly the same complexity as the editorial solution.

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

On problem F i am not convinced with the solution , can anyone provide with a better approach here , because i see the statement that

Observation: any division on more than k>3 segments can be reduced to at most 3 segments. Doesn't hold the biequivalence , that if the segment can be divided into atmost 3 segments then it can be divided into k segments

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

    The equivalence is not needed, we simply require that k > 1.

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

    We are only required to show an injection in one direction. I think we can't show bijection here, because it is not always true, that we may divide from $$$3$$$ segments up to $$$k$$$.

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

problem E as per the tutorial: Interesting fact, that in such way we generate all possible Manhattan distances. Odd distances are generated between cells from the main diagonal and (n−1,n). Even distances are generated between cells from the main diagonal and (n,n)

but I guess if total x manhattan distances exist then we only get x-1 , how to prove we can get max x-1 distances only ?

if I am wrong please correct me

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

In problem F, what is wrong in the following logic: (Here a represents the prefix xor array and mp is mp[xor] = vector)

while(q--){
   int l,r; cin>>l>>r;
   if(a[r] == a[l-1]){
        cout<<"YES"<<endl;continue;
    }

    int x = *lower_bound(mp[a[r]].begin(), mp[a[r]].end(), l);
    int y = *lower_bound(mp[0].begin(), mp[0].end(), x+1);


    if(y<r && y>x && x>=l)cout<<"YES"<<endl; else cout<<"NO"<<endl;
   }
  • »
    »
    2 years ago, hide # ^ |
    Rev. 2  
    Vote: I like it 0 Vote: I do not like it
    1. You need to look for the sum a[l - 1], not 0.

    2. The result of the second call to lower_bound() may not be dereferenceable.

    3. You don't have to check whether $$$y \gt x$$$ or $$$x\ge l$$$, since these things are automatically true.

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

Why is O(nlogn) approach exceeding time limit in B question? Normally O(nlogn) works with n<2x10^5 and time limit = 2 sec.

(i tried to write a solution using upper bound 259169919)

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

    You are using upper_bound incorrectly: the way set is structured isn't linear, thus it will make your command $$$\mathcal{O}(n)$$$.

    Instead, use the class method built for set, something like this:

    auto x1 = ons.upper_bound(lst);

    auto x2 = zrs.upper_bound(lst);

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

are there any problems similar to F

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

Can someone please explain to me the solution for problem D cause, I can't understand the editorial clearly

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

    Let me explain my idea:

    Let $$$f_s(p)$$$ be the total score of a player when he starts at the position $$$s$$$, always moves from his current position until he reaches $$$p$$$, and after reaching $$$p$$$, always stays at his current position. Bodya and Sasha's maximum score will be $$$\max_{1 \le i \le n}{f_{P_B}(i)}$$$ and $$$\max_{1 \le i \le n}{f_{P_S}(i)}$$$ respectively.

    This claim is correct because, a player will always move from his current position only when there lies some better position with higher $$$a_x$$$, somewhere in the future along the path of his $$$k$$$ moves. Now we will prove why it is always better for him to move now instead of staying at the current position for some turns and then move.

    If his current position is $$$x$$$, and he decides to stay at $$$x$$$ for some (one or more) turns, and then move to $$$p_x$$$, there are the following three cases:

    1. $$$a_x \lt a_{p_x}$$$: It is obviously better to move to $$$p_x$$$ immediately and not waste turns at $$$x$$$ with lower score.
    2. $$$a_x = a_{p_x}$$$: Staying and moving doesn't really differ here. So there is no loss in moving.
    3. $$$a_x \gt a_{p_x}$$$: When he moves after some turns, he moves definitely in the hope of reaching some position $$$y$$$ from $$$p_x$$$ (through one or several moves in between) where $$$a_x \lt a_y$$$. So it is always better to spend these turns at the position $$$y$$$ than wasting them on $$$x$$$.

    So the optimal move for a player will be — some number of moves (possibly zero), followed by some number of stays (possibly zero), until he completes his $$$k$$$ turns. So we basically iterate over his final position to know the maximum possible score.

    For all $$$1 \le i \le n$$$, $$$f_s(i)$$$ can be calculated in $$$O(n)$$$ by keeping track of how many turns it takes to reach $$$i$$$ starting at $$$s$$$ and the total score obtained along the path.

    So overall running time of the solution is $$$O(n)$$$.

    You can check my submission for better understanding: 259185280.

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

About the problem F , I have a question. According to the formula $$$X ^ X ^ X = X$$$ , why reduce k to three , instead of further reduce one? Could help me ?

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

I implemented the solution described by the editorial for G2 during contest but got TLE...

https://mirror.codeforces.com/contest/1968/submission/259238179

I am posting this so late because I was trying to upsolve with a smarter solution, but couldn't come up with one. It's pretty frustrating that my approach was correct but failed because of the constant factor.

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

for f what is the different between "--lower_bound(id[a[l-1]].begin(),id[a[l-1]].end(),r)" and "lower_bound(id[a[l-1]].begin(),id[a[l-1]].end(),r — 1)"

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

    You don't find lower_bound $$$ \gt =$$$ in the first case instead you find the first value that is $$$ \lt $$$ $$$r$$$

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

Good tutorial, thanks! But I want to ask that In problem F, why we should do mp[0].push_back(0) ?

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

For G2: I would be glad if any one help understand why author's O(n√n log(n) ) solution is passing where n=2e5 and time limit 3s.

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

Can somebody help me with Problem D submission ? i seem stuck here. 260790899

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

Can someone please tell what mistake am I doing in G1 ?

https://mirror.codeforces.com/contest/1968/submission/260861542

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

G2 卡常 厳しすぎ!! (Constant factor for G2 too tight!)

I implemented the solution described in the editorial, with KMP instead of Z-function, but all my submissions ended up TLE41 (261016696) and I couldn't get the log^2 solution right.

By dividing the submission into $$$ \gt \sqrt{n}$$$ and $$$\le\sqrt{n}$$$ parts I found my solution would finish in 3.2 seconds and I tried my best to squeeze in but still couldn't.

Could anyone help me optimize the constant factor further, or is KMP unable to pass?

BTW I don't think a $$$2e5$$$ data range for a $$$O(n\sqrt{n}\log n)$$$ intended solution is quite appropriate.

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

    if we divide the first part into < root(N / log(N)) and > root(N * log(N)) we can have a time complexity of n * root(n * log(n)). Maybe you can try this.

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

In G2 I submitted 2 solutions one wit time complexity O(N * sqrt(N) * log(n)) and other with O(N * sqrt(N * log(N))). The former solution passed whereas the later gave TLE. Does anyone have any idea why this is happening?

Former solution: https://mirror.codeforces.com/contest/1968/submission/261653053

Latter solution: https://mirror.codeforces.com/contest/1968/submission/261652536

»
22 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it
»
20 months ago, hide # |
Rev. 3  
Vote: I like it +1 Vote: I do not like it

G2 can be easily solved with z-function in O(nlogn^2). We find the maximal k for each answer i in increasing order. Use ordered set to maintain list of all indices in z-function that are greater than or equal to i and binary search for each next index. This allows us to binary search for each answer. Code

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

Can someone explain condition to move for D?

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

    First of all it is not possible to simulate all the moves since the constraints on number of moves is large . since each position in array 'A is associated with another position we need to move at max , min (n,k) times then for each move we can calculate the max score possible for the each player and after comparing maximum score achievable by both we can get the answer 359327583

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

..