4300: Fantastic title time limit:1 Sec Memory limit:128 MB
submit:540 solved:278
[Submit] [Status] [Discuss] Description given an n-length sequence AI, the longest length of the AI's subsequence bi is satisfied with bi&bi-1!=0 (2<=i<=len).
Input file total 2 rows. The first line includes an integer n. The second line includes n integers, and the first integer represents AI.
Output file has a single row. Includes an integer that represents the longest length of the subsequence bi.
Sample Input3
1 2 3Sample Output2HINT
For 100% of data, 1<=n<=100000,ai<=10^9.
Source
by Oxer
The subject was so domineering, but the water inside was a crushing defeat. However, it is not difficult to think O (N2) algorithm, is a simple lis, the conditions are different. Add a bit of optimization, we can not be difficult to know we just choose from the front of a maximum plus 1 on the line (the LIS is doing so), so we need a quick find things. We think of the numbers as binary (longest and only 31 bits), so we just need to know that the current number of a certain bits and the front of the 1, then the result of the & operation is certainly not 0. It's simple. This becomes the O (nlog2ai) algorithm. Although the expression is a bit strange, but people understand the line.
#include <cstdio>#include<cstring>#include<algorithm>using namespacestd;intmaxbit[ *], a, n; voidUpdateintXintDelx) { for(inti =0; X! =0; (x >>=1), ++i)if(X &1) Maxbit[i] =Max (Maxbit[i], delx);} intQueryintx) { intMaxt =0; for(inti =0; X! =0; (x >>=1), ++i)if(X &1) Maxt =Max (Maxt, Maxbit[i]); returnMaxt;} intMain () {scanf ("%d", &N); scanf ("%d", &a); intAns =1; memset (Maxbit,0,sizeof(maxbit)); Update (A,1); for(inti =1; I < n; ++i) {scanf ("%d", &a); intMaxnow = Query (a) +1; Update (A, maxnow); Ans=Max (ans, maxnow); } printf ("%d\n", ans); return 0;}
"Bzoj 4300" excellent title