LGMVasa's blog

By LGMVasa, 14 months ago, In English

So a few hours ago I was doing a problem which I will write here when I finish this short story. Now, I didn't have any idea of how to solve it, but then, I started thinking really hard, and found a CRAZY idea. I decided to call it fast, because this algorithm finishes even faster than you do (assuming you have someone to finish with).

So consider the following problem:

You are given a strictly increasing array a of size n and q queries, n, q <=2*10^5. There are 2 types of queries:

1 ind, val change the value of a[ind] to val, it is guaranteed that 1<ind<n, and a[ind-1]<val, and a[ind+1]>val.

2 val find the index where val appears.

Now in case you didn't notice, the array remains sorted after all queries. Now this is key.

I found a way to solve this problem in O(N+QlogN) using this algorithm:

For type 1 query we just update the array manually For type 2 query, we initialize l=1 and r=n. Next we check the element exaclty in the middle, and if it is bigger then the wanted value, then we know it's to the right of the wanted value, so we move r, because all the elements greater on indices greater than r are bigger than val. Now, we do the similar in symmetrical case. If the element is equal to val, then we found the index, and if l and r meet and we haven't fount it that means there is no elements val in the array. Now this alrogithm works in logN per query, because each iteration it cuts the search space in 2.

To end things off, I think this algorithm is really cool and overpowered, and I'm looking forward to problems containing it as the main solution. If anyone here wants to give me a CS degree for this great contribution to the CS world, I'm open to discussion.

I will here update the blog with the common questions:

  1. LGMVasa, Thank you for your BIG... contribution to the CS world. And to that I answer, no problem!

  2. LGMVasa, but I don't finish faster than this algorithm. Yes you do, don't lie to me.

Full text and comments »

  • Vote: I like it
  • -42
  • Vote: I do not like it

By LGMVasa, history, 15 months ago, In English

How much money do you think would tbe IOI medals be able to sell for? Answer for gold silver and bronze seperately

Full text and comments »

  • Vote: I like it
  • -29
  • Vote: I do not like it

By LGMVasa, history, 15 months ago, In English

After a lot of dedication, and 1 year of CP, i finally hit expert on todays cotest (even tho I was 15 minutes late to it). You can ask me anything you want.

Ps: wxhtzdy orz he will win gold on IOI 2023

Full text and comments »

  • Vote: I like it
  • -41
  • Vote: I do not like it