Proof_by_QED's blog

By Proof_by_QED, 5 weeks ago, In English
Rating Predictions

2065A - Skibidus and Amog'u

Problem Credits: chromate00
Analysis: macaquedev

Solution
Code
Rate The Problem!

2065B - Skibidus and Ohio

Problem Credits: cry
Analysis: macaquedev

Solution
Code
Rate The Problem!

2065C1 - Skibidus and Fanum Tax (easy version) and 2065C2 - Skibidus and Fanum Tax (hard version)

Problem Credits: larush
Analysis: macaquedev

Solution
Code
Rate The Problem! (C1)
Rate The Problem! (C2)

2065D - Skibidus and Sigma

Problem Credits: cry
Analysis: macaquedev

Solution
Code
Rate The Problem!

2065E - Skibidus and Rizz

Problem Credits: Proof_by_QED
Analysis: macaquedev

Solution
Code
Rate The Problem!

2065F - Skibidus and Slay

Problem Credits: chromate00
Analysis: chromate00

Solution 1
Solution 2 (Skibidi)
Code (Solution 1)
Code (Solution 2)
Rate The Problem!

2065G - Skibidus and Capping

Problem Credits: larush
Analysis: Proof_by_QED

Solution
Code
Rate The Problem!

2065H - Bro Thinks He's Him

Problem Credits: Proof_by_QED
Analysis: efishel

Solution
Code
Rate The Problem!
  • Vote: I like it
  • +38
  • Vote: I do not like it

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

First time I tried competing in Rust. Hopefully next time will go better. Thanks for the round!

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

Auto comment: topic has been updated by Proof_by_QED (previous revision, new revision, compare).

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

That was not Div4......

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

I'm sure exactly zero people used the Auxillary Tree method to solve F.

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

    Even after reading the tutorial, I have no idea what an Auxiliary Tree is.

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

    It was originally in the statement :) (notes to be precise)

    It doesnt make much sense in the editorial indeed.

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

    It'll be fun to research though lol

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

    well maybe, but: I immediately thought about auxillary tree after reading F. Then I thought there must be some better/simpler solution. Then I thought of solution 1 from the editorial

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

Problems really weren't newbie-friendly. The problems are excellent, but not for Div.4 contest. More like Div.3 — Div.2

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

    This was my first ever competition other than the one i gave previously. First Div 4 competition. And the first and second problem were i mean pretty easy. The third problem was tough though i was able to solve it.

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

Hope there are no more GPT or any AI during future contests.

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

    so true. There is no way so many pupils and newbies can solve beyond E and F without cheating

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

    hahaha yes, during the break-ins, guys with a rating of <1200 are in the top 200 and comments on every line in the code XD

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

I've been struggling for more than an hour to optimize Problem G, but I haven't been able to succeed.

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

pls tell me i'm not the only one that used LCA to AC F.

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

Alternative solution for H:

Make a segment tree, and in each node, place the following things:

  • The length of the segment (call it $$$l$$$);

  • The number of subsequences with each start and end (call it $$$C_{i,j}$$$);

  • And the number of non-equal adjacent elements across all subsequences (call it $$$ans$$$).

We can find $$$ans$$$ in the following way: either the adjacent elements are both in the left, both in the right, or one's in the left and the other is on the right. So it's gonna be

$$$left_{ans} \cdot 2^{right_{len}} + right_{ans} \cdot 2^{left_{len}} + \sum_{0 \le i,j,k,l \le 1, j \neq k} left_{C_{i,j}} \cdot right_{C_{k,l}}$$$

.

This is what the code looks like: 305334877

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

Can someone please explain why two pointer does not work in Problem C2 after sorting array b?

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

    Because a is not sorted, so while you move the first pointer forward the second pointer may move backward, then forward, then backward and so on. The solution's time complexity will be no better than O(n^2).

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

F is a very interesting question. It could've been set in a Div 2 or 3.

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

Could someone please explain why my submission for C1 is wrong?

https://codeforces.net/contest/2065/submission/305319973 (ignore "printDiffs" and "brute" functions, I used those for debugging)

I tried figuring it out but couldn't find what I did incorrectly...

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

    Think about what you should do if a[i — 1] > a[i] is not true (i.e.: a[i — 1] <= a[i]). Are there any cases where it would be beneficial to perform the operation in that case?

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

could C1 also be solved using masks? 305285624 if yes, why doesn't this work ?

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

I liked problem D. never used prefix sums like that before. Very interesting contest overall :D (A little too much brainrot for me tho). Also I was curious if using DFS/BFS is a good idea in problem F. It might be redundant, but if anyone solved with bfs/dfs, please share your solution.

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

    I solved using BFS,created a map for adjacent elements for each node in the tree ...305322643..hope you like it :D

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

      Yep. That's literally what I wanted! Thank you kind sir.

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

    I used DFS but I kept getting TLE on Test 16, pretty sure thats a star formation. Ended up just using maps and sets to solve instead.

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

Problems were defo not sorted according to difficulty, D was much easier than C1C2 combined! I had to do a very weird sorting pref sum thing just to solve it bcz i thought sorting according to sum was too easy,AC is AC lhamdoullah but still D shouldve been put before C

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

Can anyone tell me where this solution for problem G might be going wrong
I believe, I did it similar to the approach given in editorial

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

    Seems that your code give WA in large cases only. When $$$n \ge 460$$$ your code print a lower answer that the expected. Like, your output is for example 4098 and the correct answer is 108219. Maybe you aren't counting some semi-primes or primes.

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

Can someone pls help with F problem. I have maintained a neighboring frequency map and just checking if frequency > 1 for some element.

https://codeforces.net/contest/2065/submission/305373353

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

2065D - Skibidus and Sigma Editorial

Sort each array in decreasing order. Sort the arrays themselves in terms of their sum, from largest sum to smallest Put together the final array Take the score This score is guaranteed to be maximal.

Bolded part is a mistake?

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

    I believe so

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

    You cannot reorder an individual array. Read the statement carefully.

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

    Yes — DON'T sort the arrays in decreasing order! I misremembered the problem while writing the editorial! sorry!

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

Can someone please help on what mistake I'm making for Problem G,

My submission

Thank you so so much!!

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

    Maybe your code is getting TLE because of this line:

    vector<ll> freq(2e5+5, 0);
    

    You are allocating $$$2 \cdot 10^5$$$ for each test case $$$t$$$ ($$$t \le 10^4$$$), this is like $$$2 \cdot 10^9$$$ causing the TLE. The statement says that: It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2\cdot 10^5$$$.

    If you replace 2e5+5 to n+5 you'll get an AC. 305391811

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

Problem G https://codeforces.net/contest/2065/submission/305402634 Can someone please tell me what i am doing wrong I am wrong answer on 4th case

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

    I initially solved it by sorting, but your idea is also correct (proof 305556881). The only difference I see that could be wrong is you are using java.

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

      You are correct gives correct answer in c++ but why is that can you explain please

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

        Bro, seems like I got it. It's not where I looked first:

        static void sieve(int n){
        ...
            for(int i=2;i*i<n;i++){
        
»
4 weeks ago, # |
  Vote: I like it 0 Vote: I do not like it

Brainrot Question names

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

Why my O(16 * n * logn) solution on H got tle :(

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

why this contest (DIV-4) rating is not updated...

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

    Due to large number of participation + long hacking phase + A lot of cheaters

    It takes time to asses and declare the final leaderboard, Its better to wait and get honest rating than to see cheaters getting +400 above you.

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

can somebody tell me at what test case my code might be failing 305361698

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

    PLZ Somebody help me with this

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

      Nevermind sorry, the advice I gave earlier is for C2.

      I looked through your code. I would try to make sure of two things:

      1. It seems like when you shift the one in front (d[i + 1] = 1), you then set the next one to always enter the first part of the for loop. In other words, in your code, I think once you flip one in front, it always flips the one in front regardless of whether or not it should. Always check, in your code, that every flip you do decreases or increases the number if it is expected to do that. It is a bit hard to tell what the d array is used for, it seems to be telling whether or not a bit is able to be flipped but is interacting with the ones in front, which haven't been checked yet?

      2. Make sure your code is not O(n^2) time complexity. I think your funci() and funi() functions are O(N), and if these run on every index, you might get a time limit problem because doing this on every index is O(n^2). I am not 100% sure of this.

      Sorry for the initial wrong example/

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

Question H's tutorial has faulty LaTeX in the "Solution" section near the bottom. In the last math's pseudocode, there's some oplus1 thing. I think it's just supposed to be s[j] XOR 1.

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

    $$$\oplus$$$ represents $$$\oplus$$$ (XOR).

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

CAN ANYONE EXPLAIN WHY THIS APPROACH TO c WAS WRONG?

https://codeforces.net/contest/2065/submission/305299896

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

    we need something greater than prev( i.e, a[i-1]) in the ith position. two options: a[i] and someB-a[i].

    how do we find someB such that someB — a[i] >= a[i-1]? binary search for someB >= a[i-1] + a[i].

    However, your binary search looks for the incorrect equation.

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

      oh nevermind I misread your equation.

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

        Okay, you are not considering a[i] as a better alternative to the binary searched someB — a[i]. Since the question says we have two options but you seem to be consider a[i] assignment as directly someB — a[i] instead of picking the minimum of the two options if someB is found.

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

Does anyone tell me why my O(16 * n * logn) solution on H was TLE ? I read William Lin's solution and it may the same with mine

Here is my solution https://codeforces.net/contest/2065/submission/305249433

Here is William Lin's solution https://codeforces.net/contest/2065/submission/305272835

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

Lol I didn't solved B. after 1st wrong submission big mistake

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

I’m working on problem C2 and I’m unsure where my code is going wrong. Could anyone help me figure it out?

void solve () {
    int n,m;
    cin>>n>>m;
    vector<int>a(n),b(m);
    for (int i=0;i<n;i++) cin>>a[i];
    for (int i=0;i<m;i++) cin>>b[i];
    sort(b.begin(),b.end());
    a[0] = (b[0]- a[0]) < a[0] ? b[0]- a[0] : a[0];
    for (int i=1;i<n;i++) {
        int ind = lower_bound(b.begin(),b.end(),a[i-1]+a[i]) - b.begin();
        if (ind < m && b[ind] - a[i] <= a[i] && b[ind] - a[i]>= a[i-1]) {
            a[i] = b[ind] - a[i];
        }
        if (!(a[i] >= a[i-1])) {
            cout<<"NO"<<"\n";return;
        }
    }
    cout<<"yes"<<"\n";
    return;
}


int main()
{
    int ct ;cin>>ct;
    while(ct--)
    {
        solve();
    }
    return 0;
}

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

    You're only applying the operation when you get a shorter element compared to current one. But this is not always true.

    Consider the case:

    a = [6, 4] b = [1000]

    You won't apply the operation on 4, because it would be substituted to > 4(1000 -4), but if you've used that you should've got a non-decreasing array.

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

.

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

Thanks for the round )

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

Hey, Proof_by_QED can you please add the implementations of the problems? Thank you for your attention.

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

in B initially my code got accepted now shows wrong on testcase 3 wow :<

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

Proof_by_QED 2065D - Skibidus and Sigma Problem D: In the editorial, it is mentioned to sort each array in descending order (last paragraph) but it is not allowed to do so in the problem. We only have to sort the arrays in descending order according to their sum.

If it was allowed to rearrange the array, then definitely sorting each array would give the maximum score!

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

I started from the end in C2 problem, and maximize the element but less then its next element, but i get wrong answer.

can anyone tell why this approach is different from the given approach

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

    May be you have not considered the case for less than or equal to. Or maybe some implementation issue!

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

ARE RATINGS UPDATED?

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

forgive

»
4 weeks ago, # |
  Vote: I like it 0 Vote: I do not like it
void solve() {
  ll n,m;
  cin>>n>>m;
  vi a(n),b(m);
  get(a,n);get(b,m);
  if(n==1){yes;return;}
  vi c(n);
  f(i,0,n){c[i]=b[0]-a[i];}
  vector<vi>dp(n,vi(2,0));
  dp[0][0]=1,dp[0][1]=1;
  f(i,1,n){
    if(a[i]>=a[i-1] && dp[i-1][0]){
      dp[i][0]=1;
    }
    if(a[i]>=c[i-1] && dp[i-1][1]){
      dp[i][0]=1;
    }
    if(c[i]>=a[i-1] && dp[i-1][0]){
      dp[i][1]=1;
    }
    if(c[i]>=c[i-1] && dp[i-1][1]){
      dp[i][1]=1;
    }
  }
  if(dp[n-1][0] or dp[n-1][1]){yes;return;}
  no;
  
}[problem:2065C1][contest:1003div4](Alternative approach for C1 using dp)
»
4 weeks ago, # |
  Vote: I like it 0 Vote: I do not like it

hi everyone ! Could anyone please help me? Got some troubles on C2, it falls on a 2nd test, but ~7000th token. Cant figure out what the problem is:( 305525156

  • »
    »
    4 weeks ago, # ^ |
      Vote: I like it +1 Vote: I do not like it
    Spoiler
»
4 weeks ago, # |
Rev. 2   Vote: I like it 0 Vote: I do not like it

My idea for H: Let $$$dp_0$$$ being the sum of all sequences ending at 0, $$$dp_1$$$ is defined the same way, $$$nums_0$$$ is the number of subsequences ending at 0 before position i, $$$nums_1$$$ defined the same way.

The brute force code looks like this:

               if (i)
               {
                   if (s[i - 1] - '0')
                       num1 += (1 << (i - 1));
                   else
                       num0 += (1 << (i - 1));
               }
               dp = {dp[0] + dp[1] + (num1 + 1) * (s[i] == '0'), dp[0] + dp[1] + (num0 + 1) * (s[i] == '1')};

So, how do we optimize this? Matrix multiplication is looking good here. Let's use matrix multiplication:

$$$\begin{pmatrix}dp_0 & dp_1 & nums_0 & nums_1 & 1\end{pmatrix}:=\begin{pmatrix}dp_0 & dp_1 & nums_0 & nums_1 & 1\end{pmatrix} \begin{pmatrix}1 & 1 & 0 & 0 & 0 \\ 1 & 1 & 0 & 0 & 0 \\ 0 & [s_i=1]&1&0&0\\ [s_i=0] & 0&0&1&0\\ [s_i=0]*(1+[s_{i-1}=1]*2^{i-1}) & [s_i=1]*(1+[s_{i-1}=0]*2^{i-1})&[s_{i-1}=0]*2^{i-1}&[s_{i-1}=1]*2^{i-1}&1\end{pmatrix}.$$$

The only thing left to do is to use a segment tree, which I implemented in 305304142.

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

This is my submission to C2, I believe it is the same idea as the one in the editorial. I don't understand why it takes WA on test 2 and I don't know how to use the case it failed on, can anyone explain it? 305304592

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

https://codeforces.net/contest/2065/submission/305566685 I don't understand why. Wrong answer 2 ?

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

Am I the only who is getting TLE in H after using segment trees effeciently(as far as i know) Can someone help me to optimize it ? 305573607

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

    I have noticed a huge inefficiency in your code. You used vector<vector<ll>> as your node type, which stores a lot of useless data when the node is only 2x2. Replacing them with constant sized arrays make the code 30x faster (300ms vs 9s). Also, why is the seg array size $$$3n+10$$$ instead of $$$4n$$$? If you want to optimize on memory, consider an iterative segment tree instead :).

    305585533

»
4 weeks ago, # |
  Vote: I like it 0 Vote: I do not like it
  • »
    »
    4 weeks ago, # ^ |
    Rev. 2   Vote: I like it +1 Vote: I do not like it
    Spoiler
»
4 weeks ago, # |
Rev. 2   Vote: I like it +17 Vote: I do not like it

This was a great contest, which I thoroughly enjoyed virtualling with AG-88301, however I must say macaquedev's editorials are significantly lacking in their accuracy.

On line 1 of his editorial for D, he introduces a new term $$$c_2$$$, which appears from nowhere, and is clearly meant to be $$$b_3$$$...

In the editorial for E, he also says WLOG $$$n > m$$$ when the correct assumption to make is $$$n \ge m$$$, since you cannot assume they are not equal...

Can we have more proofreading of editorials as I find this frankly unacceptable that such simple mistakes were able to come through both macaquedev's editorals, and the seemingly non-rigourous proofreading by higher ups. I hope I will never see this kind of inaccuracy again.

User macaquedev is also reknowned for his use of the word "trivial", and I did not find it mentioned ONCE in this editorial set... This is frankly unacceptable behaviour and should be dealt with immediately!

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

    Clearly someone stole his identity if the word trivial is not found anywhere in the text

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

    as a tester, i can say for all involved that we are sincerely sorry for this trivial oversight. in order to hopefully rectify this issue, we will be enforcing strict regulations to ensure that user macaquedev will be as trivial as possible. sorry for the inconvenience, and we hope that, going forward, reading macaquedev's work will be one of, if not, the trivialist of trivialities.

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

    It's ironic that you complain about mistakes in my editorials when you can't spell "renowned".

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

Who has came up with the names :)

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

Nice Div. 4 contest. As a virtual contestant, I think the thoughts of these problems are fluid. And the difficulty setting of the questions is smooth.

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

Can somebody explain me why my solution for problem 4 doesn't work correctly?

#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
using namespace std;

int binSearch(vector<int>& arr, int itm1, int itm2)
{
    int l = 0, r = arr.size();
    while (l + 1 < r)
    {
        int m = l + (r - l) / 2;
        if (arr[m] - itm1 < itm2)
        {
            l = m;
        }
        else
        {
            r = m;
        }
    }
    if (r != arr.size() && arr[r] - itm1 > itm2)
    {
        return arr[r];
    }
    else
    {
        return -1;
    }
}

void solve()
{
    int n, m; cin >> n >> m;
    vector<int> arr1(n);
    vector<int> arr2(m);
    for (int i = 0; i < n; ++i) cin >> arr1[i];
    for (int i = 0; i < m; ++i) cin >> arr2[i];
    sort(arr2.begin(), arr2.end());
    arr1[0] = min(arr2[0] - arr1[0], arr1[0]);
    for (int i = 1; i < n; ++i)
    {
        int itm = binSearch(arr2, arr1[i], arr1[i - 1]);
        if (itm == -1)
        {
            if (arr1[i] < arr1[i - 1])
            {
                break;
            }
        }
        else
        {
            arr1[i] = min(itm - arr1[i], arr1[i]);
        }
    }
    cout << (is_sorted(arr1.begin(), arr1.end()) ? "YES\n" : "NO\n") << "\n";
}
int main()
{
    int t; cin >> t;
    while (t--)
    {
        solve();
    }
    
    return 0;
}

  • »
    »
    4 weeks ago, # ^ |
      Vote: I like it 0 Vote: I do not like it
    #include <iostream>
    #include <string>
    #include <algorithm>
    #include <map>
    #include <set>
    #include <vector>
    
    using namespace std;
    
    #define ll long long
    
    void solve()
    {
        
        int n; cin >> n;
        vector<int> a(n); for (int i = 0; i < n; i++){ cin >> a[i]; }
        
        sort(a.begin(), a.end());
    
        bool flag = false;
        for (int i = 1; i < (n - 2); i++){
            if ((a[i] == a[i + 1]) && ((a[i - 1] + a[i] + a[i + 1]) > a[i + 2])){
                cout << a[i - 1] << ' ' << a[i] << ' ' << a[i + 1] << ' ' << a[i + 2] << '\n';
                flag = true;
                break;
            }
        }
    
        if (!flag){
            int aa = a[0];
            int bb = a[1];
            if (aa == bb){
                for (int i = 2; i < (n - 1); i++){
                    if ((aa + bb + a[i]) > a[i + 1]){
                        cout << aa << ' ' << bb << ' ' << a[i] << ' ' << a[i + 1] << '\n';
                        flag = true;
                        break;
                    }
                }
            }
        }
        if (!flag){
            int aa = a[n - 2];
            int bb = a[n - 1];
            if (aa == bb){
                for (int i = 0; i < (n - 3); i++){
                    if ((aa + bb + a[i]) > a[i + 1]){
                        cout << aa << ' ' << bb << ' ' << a[i] << ' ' << a[i + 1] << '\n';
                        flag = true;
                        break;
                    }
                }
            }
        }
        if (!flag){
            vector<pair<int, int>> g(n - 1);
            for (int i = 0; i < (n - 1); i++){
                g[i].first = a[i + 1] - a[i];
                g[i].second = i;
            }
            sort(g.begin(), g.end());
            for (int i = 0; i < (n - 1); i++){
                if (a[i] == a[i + 1]){
                    for (int j = 0; j < (n - 1); j++){
                        int idx = g[j].second;
                        if (idx != (i - 1) && idx != i && idx != (i + 1)){
                            if ((a[i] + a[i + 1]) > g[j].first){
                                cout << a[i] << ' ' << a[i + 1] << ' ' << a[idx] << ' ' << a[idx + 1] << '\n';
                                flag = true;
                            }
                            break;
                        }
                    }
                    if (flag){
                        break;
                    }
                }
            }
    
    
    
        }
        if (!flag){
            cout << -1 << '\n';
        }
    
    
    
    
    
    
    
    
    
    
    
    }
        
    int main()
    {   
        ios::sync_with_stdio(false);
        cin.tie(nullptr); 
        cout.tie(nullptr);
        int t = 1;
        cin >> t;
        while (t--){
            solve();
        }
        return 0;
    }
    
    
»
4 weeks ago, # |
  Vote: I like it 0 Vote: I do not like it

Why is my solution wa on test 2? its the same approach as editorial. 306102484

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

    You had forget to check that for an a[i] if you don't get any b[j] such that b[j]-a[i] >= a[i — 1], in that case if a[i] >= a[i — 1] then you don't need to touch a[i]. In the below test case ans is YES but your code is giving NO. 1 5 1 800 100 50 25 999 1000

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

In 2065C, what if we apply a similar logic from the back (i.e. start from the last index, try to maximize it, then for index i, pick the greatest value of a[i] that is <= a[i+1], then proceed to i-1 and keep doing this repeatedly). Will this not work? If not, why?

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

    Yes it will work, because if we able to make the array a sorted by processing it in ascending order, then we should also able to make it sorted by processing in the descending order, because for all the choices of array b with m elements for which we had replaced the element a[i] with b[j] — a[i] will also be exact same in both cases, I had tried to check both cases in the below code.

    1.In a[i] start from first to last index — 306614358

    1. In a[i] start from last index to first index — 306634111
»
3 weeks ago, # |
  Vote: I like it 0 Vote: I do not like it

Damn my solution to D seems correct, though I wrongly assumed vl would be sufficient instead of vll.

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

Can someone explain what is the use of the "-15" bit in the solution for problem C ?

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

Hi together, can someone spot the problem in my code for exercise D?

https://codeforces.net/contest/2065/submission/308289286

Specifically, on test 3 I get a runtime error, which I cannot resolve.

I created a testcase which consists of just one instance with n=200, m=1000 and and every entry is 1. After thorough debugging I found that somehow at some point, around 200 calls to comp in (it seems to vary slightly), the sorting function starts calling my comparator with a vector of size 1002 but 0 capacity as p, and a regular one with size 1001 and capacity 1001 for q.

Then it crashes when it tries to access data in p. I could not figure out why the sorting function would ever call comp with such a weird vector p.

I hope this is the right place to pose this question, if not feel free to let me know. Thanks in advance for any help!

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

In solution of problem H, fix the sumI[s[j]\oplus1] += 2^(j-1) line.