#PS0000303. Đếm tập con theo AND (And Subset Count)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Đếm tập con theo AND (And Subset Count)
And Subset Count
Source: CSES
Version: Phuoc Hung OJ Extended
Problem Statement
Given an array of nonnegative integers, a selection is a nonempty subset of indices . Its value is the bitwise AND of all entries with . For a single selected index, its value is that entry itself.
Selections are different when their index sets differ, even if the selected values coincide.
For each integer from through , count selections whose value is exactly . Report each count modulo .
Input
The first line contains an integer , the length of the array.
The second line contains integers in index order from to .
Output
Print integers on one line in order , each reduced modulo .
Subtasks
- Subtask 1 (20 points): ; (for every ).
- Subtask 2 (30 points): ; (for every ).
- Subtask 3 (50 points): ; (for every ).
Example 1
Input
4
3 1 3 4
Output
7 4 0 3 1
Explanation
Here and the array is , giving nonempty index subsets.
- Select from positions , both equal to : choices give AND .
- Select position (value ), exclude position , and optionally select positions : choices give AND .
- Select only position : one choice gives AND .
- Select position and at least one of the other three positions: choices give AND , since shares no set bit with or .
No selection gives AND . The counts sum to , so print 7 4 0 3 1.