{"trustable":false,"prependHtml":"\u003cscript\u003e window.katexOptions \u003d { disable: true }; \u003c/script\u003e\n\u003cscript type\u003d\"text/x-mathjax-config\"\u003e\n MathJax.Hub.Config({\n tex2jax: {\n inlineMath: [[\u0027$$$\u0027,\u0027$$$\u0027], [\u0027$\u0027,\u0027$\u0027]],\n displayMath: [[\u0027$$$$$$\u0027,\u0027$$$$$$\u0027], [\u0027$$\u0027,\u0027$$\u0027]]\n }\n });\n\u003c/script\u003e\n\u003cscript async src\u003d\"https://mathjax.codeforces.org/MathJax.js?config\u003dTeX-AMS-MML_HTMLorMML\" type\u003d\"text/javascript\"\u003e\u003c/script\u003e","sections":[{"title":"","value":{"format":"HTML","content":"\u003cscript type\u003d\u0027text/x-mathjax-config\u0027\u003eMathJax.Hub.Config({tex2jax: { inlineMath: [[\u0027$\u0027,\u0027$\u0027]] } }); \u003c/script\u003e\n\u003cscript type\u003d\u0027text/javascript\u0027 src\u003d\u0027https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.1/MathJax.js?config\u003dTeX-AMS-MML_HTMLorMML\u0027\u003e\u003c/script\u003e\n\u003cscript type\u003d\u0027text/javascript\u0027\u003esetTimeout(function(){MathJax.Hub.Queue([\u0027Typeset\u0027, MathJax.Hub, \u0027left_view\u0027]);}, 2000);\u003c/script\u003e\n\u003cdiv class\u003d\"panel_content\"\u003e\n After inventing Turing Tree, 3xian always felt boring when solving problems about intervals, because Turing Tree could easily have the solution. As well, wily 3xian made lots of new problems about intervals. So, today, this sick thing happens again... \n \u003cbr\u003e \n \u003cbr\u003eNow given a sequence of N numbers A1, A2, ..., AN and a number of Queries(i, j) (1≤i≤j≤N). For each Query(i, j), you are to caculate the sum of distinct values in the subsequence Ai, Ai+1, ..., Aj. \n\u003c/div\u003e\n给定一个长度为n的序列,给定m个查询,每次查询区间[L,R]范围内不同元素的和。"}},{"title":"Input","value":{"format":"HTML","content":"The first line is an integer T (1 ≤ T ≤ 10), indecating the number of testcases below. \n\u003cbr\u003eFor each case, the input format will be like this: \n\u003cbr\u003e * Line 1: N (1 ≤ N ≤ 30,000). \n\u003cbr\u003e * Line 2: N integers A1, A2, ..., AN (0 ≤ Ai ≤ 1,000,000,000). \n\u003cbr\u003e * Line 3: Q (1 ≤ Q ≤ 100,000), the number of Queries. \n\u003cbr\u003e * Next Q lines: each line contains 2 integers i, j representing a Query (1 ≤ i ≤ j ≤ N).\n第一个整数T,表示数据组数。\u003c/br\u003e\n对于每组数据,第一行一个整数n,表示序列中元素个数。\u003c/br\u003e\n第二行n个元素。\u003c/br\u003e\n第三行一个整数q,表示询问的组数。\u003c/br\u003e\n接下来q行,每行两个整数L和R\u003c/br\u003e"}},{"title":"Output","value":{"format":"HTML","content":"For each Query, print the sum of distinct values of the specified subsequence in one line.\u003c/br\u003e\n对于每个询问,输出结果。"}},{"title":"Sample Input","value":{"format":"HTML","content":"\u003cpre\u003e2\n3\n1 1 4\n2\n1 2\n2 3\n5\n1 1 2 1 3\n3\n1 5\n2 4\n3 5\u003c/pre\u003e"}},{"title":"Sample Output","value":{"format":"HTML","content":"\u003cpre\u003e1\n5\n6\n3\n6\u003c/pre\u003e"}}]}