{"trustable":true,"prependHtml":"\u003cstyle type\u003d\"text/css\"\u003edd \u003e pre {\n display: block;\n padding: 9.5px;\n margin: 0 0 10px;\n font-size: 13px;\n line-height: 1.42857143;\n word-break: break-all;\n word-wrap: break-word;\n color: #333;\n background-color: #f5f5f5;\n border: 1px solid #ccc;\n border-radius: 4px;\n}\u003c/style\u003e","sections":[{"title":"Description","value":{"format":"HTML","content":"\u003cdiv\u003e\r\n\u003cdiv\u003eMato同学从各路神犇以各种方式(你们懂的)收集了许多资料,这些资料一共有n份,每份有一个大小和一个编号\u003c/div\u003e\r\n\u003cdiv\u003e。为了防止他人偷拷,这些资料都是加密过的,只能用Mato自己写的程序才能访问。Mato每天随机选一个区间[l,r\u003c/div\u003e\r\n\u003cdiv\u003e],他今天就看编号在此区间内的这些资料。Mato有一个习惯,他总是从文件大小从小到大看资料。他先把要看的\u003c/div\u003e\r\n\u003cdiv\u003e文件按编号顺序依次拷贝出来,再用他写的排序程序给文件大小排序。排序程序可以在1单位时间内交换2个相邻的\u003c/div\u003e\r\n\u003cdiv\u003e文件(因为加密需要,不能随机访问)。Mato想要使文件交换次数最小,你能告诉他每天需要交换多少次吗?\u003c/div\u003e\r\n\u003c/div\u003e"}},{"title":"Input","value":{"format":"HTML","content":"\u003cdiv\u003e第一行一个正整数n,表示Mato的资料份数。\u003c/div\u003e\r\n\u003cdiv\u003e第二行由空格隔开的n个正整数,第i个表示编号为i的资料的大小。\u003c/div\u003e\r\n\u003cdiv\u003e第三行一个正整数q,表示Mato会看几天资料。\u003c/div\u003e\r\n\u003cdiv\u003e之后q行每行两个正整数l、r,表示Mato这天看[l,r]区间的文件。\u003c/div\u003e\r\n\u003cdiv\u003en,q \u0026lt;\u003d 50000\u003c/div\u003e"}},{"title":"Output","value":{"format":"HTML","content":"\u003cp\u003eq行,每行一个正整数,表示Mato这天需要交换的次数。\u003c/p\u003e"}},{"title":"Sample","value":{"format":"HTML","content":"\u003ctable class\u003d\"vjudge_sample\"\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\u003e4\r\n1 4 2 3\r\n2\r\n1 2\r\n2 4\u003c/pre\u003e\u003c/td\u003e\n \u003ctd\u003e\u003cpre\u003e0\r\n2\r\n//样例解释:第一天,Mato不需要交换\r\n第二天,Mato可以把2号交换2次移到最后。\u003c/pre\u003e\u003c/td\u003e\n \u003c/tr\u003e\n\u003c/tbody\u003e\n\u003c/table\u003e\n"}},{"title":"Hint","value":{"format":"HTML","content":"\u003ch3\u003eSource\u003c/h3\u003eBy taorunz"}}]}