You are not logged in. Please login at www.codechef.com to post your questions!

×

New to manipulation

hello everyone i am fairly new to bits.I was trying to solve 2 questions..1st one and 2nd one i was able to fetch the 1st one with 52 points but i have no idea to get 100pts and i am facing difficulty with its editorial and not even getting the second question.can anybody tell me how to get comfortable with these type of questions as i have seen many many times in the contests.Is this called bits masking??If yes can anybody help me to understand these concepts.. :) :)

asked 11 Feb '15, 12:24

doodle90's gravatar image

2★doodle90
96212
accept rate: 7%

edited 11 Feb '15, 12:38


I think you should know about Binary numbers and conversions of binary to decimal...Google it if you donot know... I can help you with the first question it does not uses bitmasking.. AND has a property that if both the bits are 1 then only it will return.. Clearly N is so high it is impossible to pass all cases in O(N^2) What we do in that question is breakdown each number into bits in so called bit array and we keep on summing it ... I mean take A[i] change it into binary representation and add 1s to the corresponding places in binary notation... Now We can compute it in O(32*N) assuming int to be 32 bits ... Now the grreat thing is we will get number of bits that were both true in that position when we Choose 2 from any bit place..Hence the number of pairs which will result in an 1 in binary notation is simply = Number of true bits in that position Choose 2.. Now we have teh pairs we can multiply it to 2^the bit place (Changing Binary number to decimal)....

link

answered 11 Feb '15, 13:08

anh1l1ator's gravatar image

6★anh1l1ator
142618
accept rate: 11%

toggle preview
Preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported
  • mathemetical formulas in Latex between $ symbol

Question tags:

×77
×8

question asked: 11 Feb '15, 12:24

question was seen: 619 times

last updated: 11 Feb '15, 13:08