{"problem":{"name":"A. Subarrays Beauty","description":{"content":"You are given an array a consisting of n integers. A subarray (l, r) from array a is defined as non-empty sequence of consecutive elements al, al + 1, ..., ar. The beauty of a subarray (l, r) is calc","description_type":"Markdown"},"platform":"Codeforces","limit":{"time_limit":1000,"memory_limit":262144},"difficulty":"None","is_remote":true,"is_sync":true,"sync_url":null,"sign":"CF10153A"},"statements":[{"statement_type":"Markdown","content":"You are given an array a consisting of n integers. A subarray (l, r) from array a is defined as non-empty sequence of consecutive elements al, al + 1, ..., ar.\n\nThe beauty of a subarray (l, r) is calculated as the _bitwise AND_ for all elements in the subarray: \n\nYour task is to calculate the summation of the beauty of all subarrays (l, r) (1 ≤ l ≤ r ≤ n): \n\nThe first line contains an integer T, where T is the number of test cases.\n\nThe first line of each test case contains an integer n (1 ≤ n ≤ 105), where n is the size of the array a.\n\nThe second line of each test case contains n integers a1, a2, ..., an (1 ≤ ai ≤ 106), giving the array a.\n\nFor each test case, print a single line containing the summation of the beauty of all subarrays in the given array.\n\nAs input/output can reach huge size it is recommended to use fast input/output methods: for example, prefer to use _scanf/printf_ instead of _cin/cout_ in C++, prefer to use _BufferedReader/PrintWriter_ instead of _Scanner/System.out_ in Java.\n\nA _bitwise AND_ takes two equal-length binary representations and performs the logical _AND_ operation on each pair of the corresponding bits, by multiplying them. Thus, if both bits in the compared position are 1, the bit in the resulting binary representation is 1 (1  ×  1 = 1); otherwise, the result is 0 (1  ×  0 = 0 and 0  ×  0 = 0). This operation exists in all modern programming languages, for example in language C++ and Java it is marked as *&*.\n\nIn the first test case, the answer is calculated as summation of 6 subarrays as follow: \n\n## Input\n\nThe first line contains an integer T, where T is the number of test cases.The first line of each test case contains an integer n (1 ≤ n ≤ 105), where n is the size of the array a.The second line of each test case contains n integers a1, a2, ..., an (1 ≤ ai ≤ 106), giving the array a.\n\n## Output\n\nFor each test case, print a single line containing the summation of the beauty of all subarrays in the given array.\n\n[samples]\n\n## Note\n\nAs input/output can reach huge size it is recommended to use fast input/output methods: for example, prefer to use _scanf/printf_ instead of _cin/cout_ in C++, prefer to use _BufferedReader/PrintWriter_ instead of _Scanner/System.out_ in Java.A _bitwise AND_ takes two equal-length binary representations and performs the logical _AND_ operation on each pair of the corresponding bits, by multiplying them. Thus, if both bits in the compared position are 1, the bit in the resulting binary representation is 1 (1  ×  1 = 1); otherwise, the result is 0 (1  ×  0 = 0 and 0  ×  0 = 0). This operation exists in all modern programming languages, for example in language C++ and Java it is marked as *&*.In the first test case, the answer is calculated as summation of 6 subarrays as follow: Beauty(1, 1) + Beauty(l, 2) + Beauty(1, 3) + Beauty(2, 2) + Beauty(2, 3) + Beauty(3, 3)  (7) + (7 & 11) + (7 & 11 & 9) + (11) + (11 & 9) + (9) = 40","is_translate":false,"language":"English"},{"statement_type":"Markdown","content":"**Definitions**  \nLet $ T \\in \\mathbb{Z} $ be the number of test cases.  \nFor each test case $ k \\in \\{1, \\dots, T\\} $:  \n- Let $ n_k \\in \\mathbb{Z} $ denote the length of the array.  \n- Let $ A_k = (a_{k,1}, a_{k,2}, \\dots, a_{k,n_k}) $ be the array of integers, where $ a_{k,i} \\in \\mathbb{Z}^+ $.  \n\nA subarray $ (l, r) $ is defined for $ 1 \\leq l \\leq r \\leq n_k $, and its beauty is $ \\bigwedge_{i=l}^{r} a_{k,i} $, the bitwise AND of all elements in the subarray.\n\n**Constraints**  \n1. $ 1 \\leq T \\leq 10^4 $ (implied by constraints on $ n $ and typical CF bounds)  \n2. For each test case $ k $:  \n   - $ 1 \\leq n_k \\leq 10^5 $  \n   - $ 1 \\leq a_{k,i} \\leq 10^6 $ for all $ i \\in \\{1, \\dots, n_k\\} $\n\n**Objective**  \nFor each test case $ k $, compute:  \n$$\nS_k = \\sum_{l=1}^{n_k} \\sum_{r=l}^{n_k} \\left( \\bigwedge_{i=l}^{r} a_{k,i} \\right)\n$$  \nOutput $ S_k $ for each test case.","is_translate":false,"language":"Formal"}],"meta":{"iden":"CF10153A","tags":[],"sample_group":[],"created_at":"2026-03-03 11:00:39"}}