#P8434. 「WHOI-2」D&D

    ID: 9447 远端评测题 1000~3000ms 128MiB 尝试: 0 已通过: 0 难度: 8 上传者: 标签>动态规划 DP搜索数学二分洛谷原创O2优化位运算双指针 two-pointer

「WHOI-2」D&D

Background

Have you noticed that something is missing?

Our miku decided to go shopping. But by an unfortunate coincidence, there are very few decorations in her home, and she only has some numbers that can be used as decorations.

However, miku found that if there is a set of numbers AA formed by several decorations, then the subset f(A)f(A) of AA is the best-looking one (although we do not know why). So this problem was created.

But since you have seen the title, you should know where miku is going (just kidding).

Problem Description

Given a set without duplicates AA, define its decorative subset as

f(A)={aAbA{a},abb}f(A)=\{a\in A|\forall b\in A-\{a\},a|b\not= b \}

Here, "|"\texttt{"|"} denotes bitwise OR. Also, bA{a}b\in A-\{a\} means bAb\in A and bab\not=a.

miku has a positive integer sequence aia_i of length nn. You need to partition this sequence into several (at least one) contiguous substrings. It is required that the decorative subsets of the sets without duplicates formed by the elements of these substrings are the same.

Compute the number of valid partitioning schemes modulo 109+710^9+7.

Input Format

The first line contains one positive integer nn.

The next line contains a positive integer sequence of length nn, representing aia_i.

Output Format

Output one positive integer, the answer.

10
1 2 3 4 5 5 4 3 2 1
2
9
1 2 2 1 1 1 2 2 1
16

Hint

[Explanation for Sample #1] It can be proven that the two ways are:

[1,2,3,4,5,5,4,3,2,1][1,2,3,4,5,5,4,3,2,1] [1,2,3,4,5],[5,4,3,2,1][1,2,3,4,5],[5,4,3,2,1]

The sets without duplicates formed by these three subsets are all {1,2,3,4,5}\{1,2,3,4,5\}. Their decorative subsets are all {3,5}\{3,5\}. The details are as follows:

  • 1:13=31:1|3=3, so it does not belong.
  • 2:23=32:2|3=3, so it does not belong.
  • 3:31=3,32=3,34=7,35=73:3|1=3,3|2=3,3|4=7,3|5=7, so it belongs.
  • 4:45=54:4|5=5, so it does not belong.
  • 5:51=5,52=7,53=7,54=55:5|1=5,5|2=7,5|3=7,5|4=5, so it belongs.

This problem uses bundled testdata.

  • subtask1(5pts):n10\text{subtask1(5pts)}:n\leq10.
  • subtask2(10pts):ai7\text{subtask2(10pts)}:a_i\leq7.
  • subtask3(20pts):ai=2a+2b\text{subtask3(20pts)}:a_i=2^a+2^b. Where aba\not = b.
  • subtask4(20pts):ai=2a+2b\text{subtask4(20pts)}:a_i=2^a+2^b. Where it is not guaranteed that aba\not =b.
  • subtask5(10pts):\text{subtask5(10pts)}: It is guaranteed that aia_i is generated randomly.
  • subtask6(35pts):\text{subtask6(35pts)}: No special restrictions. The time limit is 3s3s.

For 100%100\% of the data, it is guaranteed that 1n3×106,0ai2×1061\leq n\leq 3\times10^6,0\leq a_i\leq2\times 10^6.

Input Format

The first line contains one positive integer nn.

The next line contains a positive integer sequence of length nn, representing aia_i.

Output Format

Output one positive integer, the answer.

Hint

Constraints: For 100%100\% of the data, it is guaranteed that 1n3×106,0ai2×1061\leq n\leq 3\times10^6,0\leq a_i\leq2\times 10^6.

Translated by ChatGPT 5