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