{"trustable":true,"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":"\u003cdiv class\u003d\"panel_content\"\u003eMex是定义在整数集合上的一个函数,通常用于中立博弈理论。对于一个非负整数集合S,mex(S)被定义为S中未出现的最小非负整数。现在我们的问题是关于序列上的mex函数。\u003cbr\u003e\u003cbr\u003e考虑一个非负整数序列{ai},我们定义mex(L,R)为从aL到aR(包括两端)的连续子序列中未出现的最小非负整数。现在我们想要计算所有1 \u003c\u003d L \u003c\u003d R \u003c\u003d n时的mex(L,R)之和。\u003c/div\u003e"}},{"title":"输入","value":{"format":"HTML","content":"输入包含最多20个测试用例。\u003cbr\u003e对于每个测试用例,第一行包含一个整数n,表示序列的长度。\u003cbr\u003e接下来一行包含n个用空格分隔的非整数,表示序列。\u003cbr\u003e(1 \u003c\u003d n \u003c\u003d 200000, 0 \u003c\u003d ai \u003c\u003d 10^9)\u003cbr\u003e输入以n \u003d 0结束。"}},{"title":"输出","value":{"format":"HTML","content":"对于每个测试用例,输出一行包含一个整数,表示答案。"}},{"title":"示例","value":{"format":"HTML","content":"\u003ctable class\u003d\u0027vjudge_sample\u0027\u003e\n\u003cthead\u003e\n \u003ctr\u003e\n \u003cth\u003eInput\u003c/th\u003e\n \u003cth\u003eOutput\u003c/th\u003e\n \u003c/tr\u003e\n\u003c/thead\u003e\n\u003ctbody\u003e\n \u003ctr\u003e\n \u003ctd\u003e\u003cpre\u003e3\r\n0 1 3\r\n5\r\n1 0 2 0 1\r\n0\r\n\u003c/pre\u003e\u003c/td\u003e\n \u003ctd\u003e\u003cpre\u003e5\r\n24\u003c/pre\u003e\u003c/td\u003e\n \u003c/tr\u003e\n\u003c/tbody\u003e\n\u003c/table\u003e"}},{"title":"提示","value":{"format":"HTML","content":"\u003cbr\u003e对于第一个测试用例:\u003cbr\u003emex(1,1)\u003d1, mex(1,2)\u003d2, mex(1,3)\u003d2, mex(2,2)\u003d0, mex(2,3)\u003d0, mex(3,3)\u003d0。\u003cbr\u003e 1 + 2 + 2 + 0 + 0 + 0 \u003d 5。\u003cbr\u003e"}}]}