PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#PS0000301. Ba phép đếm theo mặt nạ bit (SOS Bit Problem)
HỌC THEO LỘ TRÌNH
1 lộ trìnhBài tập thuộc lộ trình
Mục lục đề ⌄
Đang đọc
Ba phép đếm theo mặt nạ bit (SOS Bit Problem)
SOS Bit Problem
Source: CSES
Version: Phuoc Hung OJ Extended
Problem Statement
Given a sequence of positive integers , consider each entry and all entries with .
Compute three separate counts:
- The number of entries satisfying , where denotes bitwise OR.
- The number of entries satisfying , where denotes bitwise AND.
- The number of entries satisfying .
Count each position separately, including repeated values. The position is also considered.
Input
The first line contains an integer , the length of the sequence.
The second line contains integers in order.
Output
Print lines of three counts in the specified order, following the input order.
Subtasks
- Subtask 1 (20 points): ; (for every ).
- Subtask 2 (30 points): ; (for every ).
- Subtask 3 (50 points): ; (for every ).
Example 1
Input
5
3 7 2 9 2
Output
3 2 5
4 1 5
2 4 4
1 1 3
2 4 4
Explanation
The five entries are ; the two positions containing count separately.
- For , OR equals at positions ; AND equals at ; AND is nonzero at all five positions. The result is
3 2 5. - For , OR equals at ; AND equals at ; AND is nonzero at all five positions. The result is
4 1 5. - For , OR equals at ; AND equals at , which are also the positions with nonzero AND. The result is
2 4 4. - For , only position gives OR equal to or AND equal to ; AND is nonzero at . The result is
1 1 3. - The final entry is also , so its result is
2 4 4.