{"raw_statement":[{"iden":"statement","content":"The difference between easy and hard version are the constraints on n\n\nYou are given an array of $n$ integers (a1, a2, a3, ....... an)\n\nYou have to find the number of pairs such that a[i] xor a[j] = a[i]\n\nFirst line has a single integer $t$, number of tests [1 <= $t$ <= 1000]\n\nFirst line of each test has a single integer $n$, size of array [1 <= $n$ <= 1e5]\n\nSecond line of each test has $n$ integers, the array elements [0 <= $a [ i ]$ <= 1e9]\n\nIt is guaranteed that sum of n among all tests do not exceed 1e5\n\nFor each test, print a single integer, the number of pairs\n\n"},{"iden":"input","content":"First line has a single integer $t$, number of tests [1 <= $t$ <= 1000]First line of each test has a single integer $n$, size of array [1 <= $n$ <= 1e5]Second line of each test has $n$ integers, the array elements [0 <= $a [ i ]$ <= 1e9]It is guaranteed that sum of n among all tests do not exceed 1e5"},{"iden":"output","content":"For each test, print a single integer, the number of pairs"}],"translated_statement":"[{\"iden\":\"statement\",\"content\":\"_Biodiverse Subsequence 和 Biodiverse Subarray 的问题陈述几乎完全相同，区别仅在于所采样的珊瑚必须构成给定序列的_子序列_还是_子数组_。尽管如此，这两个问题是截然不同的。_\\n\\n生物多样性是任何生态系统中最重要的特性之一，无论是在森林、红树林还是海洋中。菲律宾拥有大量该国特有的动植物物种。Cindy 是一位热衷于潜水的爱好者，她随同一群生物学家前往韦尔德岛通道，采集一些珊瑚物种用于研究。当然，所选择的样本必须准确反映珊瑚三角区海洋生物的多样性。\\n\\n他们发现了一排 $N$ 个珊瑚，并从中识别出 $K$ 种不同的物种。我们将此建模为一个由 $N$ 个正整数 $A_1, A_2, dots.h, A_N$ 组成的序列。从 $1$ 到 $K$ 的每个整数至少出现一次，且序列中仅出现这些整数。如果一个数字序列中从 $1$ 到 $K$ 的每个整数都至少出现一次，则称该序列为 _biodiverse_（生物多样）的。\\n\\n为了保护栖息地的特性，研究人员必须选择一个生物多样性的 _子数组_ 进行采样。子数组是指一个 _连续_ 的元素子序列 $A_l, A_(l + 1), dots.h A_r$，其中 $1 lt.eq l lt.eq r lt.eq N$。为了决定采样哪些珊瑚，研究人员请 Cindy 计算序列 $A$ 中生物多样性子数组的数量。\\n\\n帮助 Cindy 吧？\\n\\n输入的第一行包含两个用空格分隔的整数 $N$ 和 $K$，分别表示珊瑚的数量和不同物种的数量。\\n\\n第二行输入包含 $N$ 个用空格分隔的整数 $A_1$, $A_2$, $dots.h.c$, $A_N$，其中 $A_i$ 表示第 $i$ 个珊瑚的物种。\\n\\n请输出一行，包含一个整数，表示 $A$ 中生物多样性子数组的数量。\\n\\n$1 lt.eq K lt.eq N lt.eq 2 dot.op 10^5$\\n\\n$1 lt.eq A_i lt.eq K$ 对所有 $i$ 成立。\\n\\n对于所有从 $1$ 到 $K$ 的 $k$，都存在某个 $i$ 使得 $A_i = k$。\\n\\n*子任务 1*（40 分）：\\n\\n$N lt.eq 100$\\n\\n*子任务 2*（20 分）：\\n\\n$N lt.eq 2000$\\n\\n*子任务 3*（20 分）：\\n\\n$K lt.eq 2$\\n\\n*子任务 4*（20 分）：\\n\\n无其他限制。\\n\\n下图展示了第一个样例测试用例中研究人员可选择的六个生物多样性子数组。 \\n\\n\"},{\"iden\":\"input\",\"content\":\"输入的第一行包含两个用空格分隔的整数 $N$ 和 $K$，分别表示珊瑚的数量和不同物种的数量。第二行输入包含 $N$ 个用空格分隔的整数 $A_1$, $A_2$, $dots.h.c$, $A_N$，其中 $A_i$ 表示第 $i$ 个珊瑚的物种。\"},{\"iden\":\"output\",\"content\":\"请输出一行，包含一个整数，表示 $A$ 中生物多样性子数组的数量。\"},{\"iden\":\"scoring\",\"content\":\"$1 lt.eq K lt.eq N lt.eq 2 dot.op 10^5$$1 lt.eq A_i lt.eq K$ 对所有 $i$ 成立。对于所有从 $1$ 到 $K$ 的 $k$，都存在某个 $i$ 使得 $A_i = k$。*子任务 1*（40 分）：$N lt.eq 100$*子任务 2*（20 分）：$N lt.eq 2000$*子任务 3*（20 分）：$K lt.eq 2$*子任务 4*（20 分）：无其他限制。\"},{\"iden\":\"examples\",\"content\":\"输入\\n4 2\\n1 2 1 2\\n输出\\n6\\n输入\\n14 9\\n3 1 4 1 5 9 2 6 5 3 5 8 9 7\\n输出\\n3\\n\"},{\"iden\":\"note\",\"content\":\"下图展示了第一个样例测试用例中研究人员可选择的六个生物多样性子数组。    下图展示了第二个样例测试用例中研究人员可选择的三个生物多样性子数组。   \"}]}","sample_group":[],"show_order":[],"formal_statement":"**Definitions**  \nLet $ N, K \\in \\mathbb{Z}^+ $ with $ 1 \\leq K \\leq N \\leq 2 \\cdot 10^5 $.  \nLet $ A = (A_1, A_2, \\dots, A_N) $ be a sequence of integers where $ A_i \\in \\{1, 2, \\dots, K\\} $, and each integer from $ 1 $ to $ K $ appears at least once.\n\nA **biodiverse subarray** is a contiguous subarray $ A[l:r] = (A_l, A_{l+1}, \\dots, A_r) $ with $ 1 \\leq l \\leq r \\leq N $, such that the set $ \\{A_l, A_{l+1}, \\dots, A_r\\} $ contains all integers from $ 1 $ to $ K $.\n\n**Constraints**  \n1. $ 1 \\leq K \\leq N \\leq 2 \\cdot 10^5 $  \n2. $ 1 \\leq A_i \\leq K $ for all $ i \\in \\{1, \\dots, N\\} $  \n3. $ \\forall k \\in \\{1, \\dots, K\\}, \\exists i \\in \\{1, \\dots, N\\} $ such that $ A_i = k $\n\n**Objective**  \nCompute the number of subarrays $ A[l:r] $ that are biodiverse, i.e.,  \n$$\n\\left| \\left\\{ (l, r) \\mid 1 \\leq l \\leq r \\leq N, \\ \\{A_l, A_{l+1}, \\dots, A_r\\} = \\{1, 2, \\dots, K\\} \\right\\} \\right|\n$$","simple_statement":null,"has_page_source":false}