#P7384. 「EZEC-6」分组

「EZEC-6」分组

Description

You are given nn numbers. Split them into any number of groups (they do not need to be contiguous). For each group, take the bitwise OR of the numbers in that group, and then sum the results of all groups. Under the condition that this total sum is minimized, find the maximum possible number of groups.

Input Format

The first line contains a positive integer nn.

The second line contains nn non-negative integers aia_i.

Output Format

Output one positive integer: the maximum number of groups in an optimal solution.

6
1 1 4 5 1 4
1
7
1 9 1 9 8 1 0
2
8
1 9 2 6 0 8 1 7
2
9
3 1 4 1 5 9 2 6 5
1
9
9 9 8 2 4 4 3 5 3
1
6
1 2 3 4 8 12
2

Hint

Below is one possible construction for each sample.

  • {1,1,4,5,1,4}\{1,1,4,5,1,4\}
  • {1,9,1,9,8,1},{0}\{1,9,1,9,8,1\},\{0\}
  • {1,9,2,6,8,1,7},{0}\{1,9,2,6,8,1,7\},\{0\}
  • {3,1,4,1,5,9,2,6,5}\{3,1,4,1,5,9,2,6,5\}
  • {9,9,8,2,4,4,3,5,3}\{9,9,8,2,4,4,3,5,3\}
  • {1,2,3},{4,8,12}\{1,2,3\},\{4,8,12\}

For sample 66, {1,2,3,4,8,12}\{1,2,3,4,8,12\} is also a solution that minimizes the answer, but {1,2,3},{4,8,12}\{1,2,3\},\{4,8,12\} produces more groups.

This problem uses bundled test scoring.

  • Subtask 11: n8n\leq8, 2020 points.
  • Subtask 22: n103n\leq10^3, 2020 points.
  • Subtask 33: ai{0,1}a_i\in\{0,1\}, 55 points.
  • Subtask 44: n=106n=10^6, and the testdata is guaranteed to be random, 55 points.
  • Subtask 55: n106n\leq10^6, 3030 points.
  • Subtask 66: n107n\leq10^7, 2020 points.

Constraints: for all testdata, 0ai10180\leq a_i\leq10^{18}, 1n1071\leq n\leq10^7.

If you do not know what bitwise OR is, please click here.

This problem enables O2 optimization by default.

This problem provides an input optimization method.

Using read(x); to read any integer x is equivalent to scanf("%d", &x);, where %d can be automatically recognized as the corresponding type.

#define getchar()(p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2)?EOF:*p1++)
char buf[1<<21],*p1=buf,*p2=buf;
template <typename T>
inline void read(T& r) {
	r=0;bool w=0; char ch=getchar();
	while(ch<'0'||ch>'9') w=ch=='-'?1:0,ch=getchar();
	while(ch>='0'&&ch<='9') r=r*10+(ch^48), ch=getchar();
	r=w?-r:r;
}

Translated by ChatGPT 5