Bzoj 4300: A great problem binary

Source: Internet
Author: User

This is the question of the road rules, okay. I thought about it before I went to bed last night. Combined with the previous experience of solving problems, the first thing about binary operations is that many of them are independent, so we can make this problem, set A[i] for if J's binary I bit is a maximum length that can be obtained, and then the number of all binary of J is 1 to take a[i] maximum, and update The other bits. That's it, come on! It's pretty smooth.

This ran for 48 milliseconds.

1#include <cstdio>2#include <iostream>3 #defineRep (i,j,k) for (int i = j; I <= K; i++)4 #defineMAXN 1000055 using namespacestd;6 inta[ *] = {0};7 8 intRead ()9 {Ten     ints =0, t =1;Charc =GetChar (); One      while( !IsDigit (c)) { A         if(c = ='-') T =-1; c =GetChar (); -     } -      while(IsDigit (c)) { thes = S *Ten+ C-'0'; c =GetChar (); -     } -     returnS *T; - } +  - intMain () + { A     intn =read (); atRep (I,1, N) { -         intx =read (); -         inty = x, tot =0, Maxl =0; -          while(y) { -             if(y&1 ) { -                 if(A[tot] +1> Maxl) Maxl = A[tot] +1; in             } -Y >>=1, tot++; to         } +y = x, tot =0; -          while(y) { the             if(y&1 ){ *A[tot] =Maxl; $             }Panax NotoginsengY >>=1, tot++; -         } the     } +     intAns =0; ARep (I,0, to)if(A[i] > ans) ans =A[i]; thecout<<ans<<Endl; +     return 0;  -}

Bzoj 4300: A great problem binary

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.