Hastorius's blog

By Hastorius, history, 17 months ago, In English

So I suck at binary search, and just mess around with +1s until it seems to work, get a WA or two, mess around with more +1s, and occasionally get it right by accident. But while talking to iframe_, I learned about a binary search implementation that is significantly more intuitive, cleaner, and shorter called Bitwise Binary Search. You can probably figure out how it works from just the name. Instead of storing a range with a left and right bound, you store it in a single int(or long). The current range of values in the nth iteration is the 1 through n-1th largest bits in the number to those bits followed by all 1s. This is fairly intuitive, as each binary search iteration will decrease the the search range by half. The first iteration will determine whether the largest bit of the integer is 1 or 0, and depending on which it is, this will limit the range to the bottom or top half. The rest of the bits work in a similar manner. You iteratively find the ith largest bit of the answer each time. There's a couple of really cool features that this has. First of all, it's easy to write:

int current = start;

for(int step = 1<<20; step > 0; step /= 2)
  if(works(current+step)) current += step;

This is clearly a lot shorter than a normal binary search implementation, and the answer will be stored in current. But on top of that, this will, by default, work for both lowerbound and upperbound. It will find the most extreme value that works, whether works returns true for the bottom x values or top x. This is intuitive as well, so implementing it in contest will take minimal time. It can also be very easily adapted to floating point binary search on answers with similar syntax:

float current = start, maxstep = 1e6, minstep = 1e-6;

for(float step = maxstep; step >= minstep; step /= 2)
  if(works(current+step)) current += step;

I finally learned binary search after reaching expert!

Full text and comments »

  • Vote: I like it
  • +46
  • Vote: I do not like it

By Hastorius, history, 2 years ago, In English

So about half an hour ago I made a post arguing for the previous contest to be rated, at least for those with positive deltas. Whether you agree or not, it's not a particularly extreme opinion, yet my blog post was removed from codeforces within minutes. This is rather hypocritical action from a platform that very strongly supports durov on the basis of free speech, yet at even just a suggestion from a random pupil they go straight to deleting posts. Without getting too political, I think we can all agree that there is worse stuff on Telegram than disagreeing with making a contest unrated. I doubt this post will even be up for a couple of minutes, but regardless, codeforces admin should have significantly better ways of resolving issues than silencing those that even slightly disagree on relatively meaningless issues.

Edit: This was relegated to draft status randomly about 10 minutes ago. I reposted shortly after and the upvotes/comments are unchanged but it was most definitely removed from top prior to me reposting it.

Edit 2: The number of upvotes on this post was rising at first. However, in the past 20 minutes or so, I've seen a rapid decrease in this number, which is unexpected given the rapid rate of decline and the lack of any changes I've made that would alter public perception of this post to the extent that it would halve it's upvote count this quickly.

Full text and comments »

  • Vote: I like it
  • +8
  • Vote: I do not like it