"Bzoj 4300" excellent title

Source: Internet
Author: User

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

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.