BC #66 GTW likes gt
2015-12-12 23:10
447 查看
问题描述
输入描述
输出描述
输入样例
输出样例
Hint
首先这道题有一个很显然的O(n*logn)O(n∗logn)的做法,直接区间加,求区间最大值即可。
但是此题还有一个O(n)O(n)的做法。我们发现b_1,b_2,...,b_xb1,b2,...,bx都加11就相当于b_{x+1},b_{x+2},...,b_nbx+1,bx+2,...,bn都减11。然后我们可以倒着做,记一下最大值,如果遇到了修改操作,就把最大值减11,然后判断一下这个人会不会被消灭掉,然后再更新一下最大值。
好好题目我竟然想的这么复杂,没有敲出来。。。就是没想到吧,还需要多加训练那。。。。
下面似乎是一种比较常用的方法,我没有想到。。。
直接叠加预处理好a[]数组,挖草,这都没想到,我到底是在干嘛。。。
从前,有<span class="katex" style="font-size: 1.21em; font-family: KaTeX_Main; line-height: 1.2; white-space: nowrap;"><span class="katex-mathml" style="position: absolute; padding: 0px; border: 0px; height: 1px; width: 1px; overflow: hidden;">n</span><span class="katex-html" style="display: inline-block;"><span class="strut" style="display: inline-block; height: 0.43056em;"></span><span class="strut bottom" style="display: inline-block; height: 0.43056em; vertical-align: 0em;"></span><span class="base textstyle uncramped" style="display: inline-block;"><span class="mord mathit" style="font-family: KaTeX_Math; font-style: italic;">n</span></span></span></span>只萌萌的GT,他们分成了两组在一起玩游戏。他们会排列成一排,第<span class="katex" style="font-size: 1.21em; font-family: KaTeX_Main; line-height: 1.2; white-space: nowrap;"><span class="katex-mathml" style="position: absolute; padding: 0px; border: 0px; height: 1px; width: 1px; overflow: hidden;">i</span><span class="katex-html" style="display: inline-block;"><span class="strut" style="display: inline-block; height: 0.65952em;"></span><span class="strut bottom" style="display: inline-block; height: 0.65952em; vertical-align: 0em;"></span><span class="base textstyle uncramped" style="display: inline-block;"><span class="mord mathit" style="font-family: KaTeX_Math; font-style: italic;">i</span></span></span></span>只GT会随机得到一个能力值<span class="katex" style="font-size: 1.21em; font-family: KaTeX_Main; line-height: 1.2; white-space: nowrap;"><span class="katex-mathml" style="position: absolute; padding: 0px; border: 0px; height: 1px; width: 1px; overflow: hidden;">b_i</span><span class="katex-html" style="display: inline-block;"><span class="strut" style="display: inline-block; height: 0.69444em;"></span><span class="strut bottom" style="display: inline-block; height: 0.84444em; vertical-align: -0.15em;"></span><span class="base textstyle uncramped" style="display: inline-block;"><span class="mord"><span class="mord mathit" style="font-family: KaTeX_Math; font-style: italic;">b</span><span class="vlist" style="display: inline-block;"><span style="display: block; height: 0px; position: relative; top: 0.15em; margin-right: 0.05em; margin-left: 0em;"><span class="fontsize-ensurer reset-size5 size5" style="display: inline-block; font-size: 1em;"><span style="font-size: 0em;"></span></span><span class="reset-textstyle scriptstyle cramped" style="display: inline-block; font-size: 0.7em;"><span class="mord mathit" style="font-family: KaTeX_Math; font-style: italic;">i</span></span></span><span class="baseline-fix" style="display: inline-table; height: 0px; position: relative; table-layout: fixed;"><span class="fontsize-ensurer reset-size5 size5" style="display: inline-block; font-size: 1em;"><span style="font-size: 0em;"></span></span></span></span></span></span></span></span>。在第<span class="katex" style="font-size: 1.21em; font-family: KaTeX_Main; line-height: 1.2; white-space: nowrap;"><span class="katex-mathml" style="position: absolute; padding: 0px; border: 0px; height: 1px; width: 1px; overflow: hidden;">i</span><span class="katex-html" style="display: inline-block;"><span class="strut" style="display: inline-block; height: 0.65952em;"></span><span class="strut bottom" style="display: inline-block; height: 0.65952em; vertical-align: 0em;"></span><span class="base textstyle uncramped" style="display: inline-block;"><span class="mord mathit" style="font-family: KaTeX_Math; font-style: italic;">i</span></span></span></span>秒的时候,第<span class="katex" style="font-size: 1.21em; font-family: KaTeX_Main; line-height: 1.2; white-space: nowrap;"><span class="katex-mathml" style="position: absolute; padding: 0px; border: 0px; height: 1px; width: 1px; overflow: hidden;">i</span><span class="katex-html" style="display: inline-block;"><span class="strut" style="display: inline-block; height: 0.65952em;"></span><span class="strut bottom" style="display: inline-block; height: 0.65952em; vertical-align: 0em;"></span><span class="base textstyle uncramped" style="display: inline-block;"><span class="mord mathit" style="font-family: KaTeX_Math; font-style: italic;">i</span></span></span></span>只GT可以消灭掉所有排在他前面的和他不是同一组的且能力值小于他的GT。 为了使游戏更加有趣,GT的首领GTW会发功<span class="katex" style="font-size: 1.21em; font-family: KaTeX_Main; line-height: 1.2; white-space: nowrap;"><span class="katex-mathml" style="position: absolute; padding: 0px; border: 0px; height: 1px; width: 1px; overflow: hidden;">m</span><span class="katex-html" style="display: inline-block;"><span class="strut" style="display: inline-block; height: 0.43056em;"></span><span class="strut bottom" style="display: inline-block; height: 0.43056em; vertical-align: 0em;"></span><span class="base textstyle uncramped" style="display: inline-block;"><span class="mord mathit" style="font-family: KaTeX_Math; font-style: italic;">m</span></span></span></span>次,第<span class="katex" style="font-size: 1.21em; font-family: KaTeX_Main; line-height: 1.2; white-space: nowrap;"><span class="katex-mathml" style="position: absolute; padding: 0px; border: 0px; height: 1px; width: 1px; overflow: hidden;">i</span><span class="katex-html" style="display: inline-block;"><span class="strut" style="display: inline-block; height: 0.65952em;"></span><span class="strut bottom" style="display: inline-block; height: 0.65952em; vertical-align: 0em;"></span><span class="base textstyle uncramped" style="display: inline-block;"><span class="mord mathit" style="font-family: KaTeX_Math; font-style: italic;">i</span></span></span></span>次发功的时间为<span class="katex" style="font-size: 1.21em; font-family: KaTeX_Main; line-height: 1.2; white-space: nowrap;"><span class="katex-mathml" style="position: absolute; padding: 0px; border: 0px; height: 1px; width: 1px; overflow: hidden;">c_i</span><span class="katex-html" style="display: inline-block;"><span class="strut" style="display: inline-block; height: 0.43056em;"></span><span class="strut bottom" style="display: inline-block; height: 0.58056em; vertical-align: -0.15em;"></span><span class="base textstyle uncramped" style="display: inline-block;"><span class="mord"><span class="mord mathit" style="font-family: KaTeX_Math; font-style: italic;">c</span><span class="vlist" style="display: inline-block;"><span style="display: block; height: 0px; position: relative; top: 0.15em; margin-right: 0.05em; margin-left: 0em;"><span class="fontsize-ensurer reset-size5 size5" style="display: inline-block; font-size: 1em;"><span style="font-size: 0em;"></span></span><span class="reset-textstyle scriptstyle cramped" style="display: inline-block; font-size: 0.7em;"><span class="mord mathit" style="font-family: KaTeX_Math; font-style: italic;">i</span></span></span><span class="baseline-fix" style="display: inline-table; height: 0px; position: relative; table-layout: fixed;"><span class="fontsize-ensurer reset-size5 size5" style="display: inline-block; font-size: 1em;"><span style="font-size: 0em;"></span></span></span></span></span></span></span></span>,则在第<span class="katex" style="font-size: 1.21em; font-family: KaTeX_Main; line-height: 1.2; white-space: nowrap;"><span class="katex-mathml" style="position: absolute; padding: 0px; border: 0px; height: 1px; width: 1px; overflow: hidden;">c_i</span><span class="katex-html" style="display: inline-block;"><span class="strut" style="display: inline-block; height: 0.43056em;"></span><span class="strut bottom" style="display: inline-block; height: 0.58056em; vertical-align: -0.15em;"></span><span class="base textstyle uncramped" style="display: inline-block;"><span class="mord"><span class="mord mathit" style="font-family: KaTeX_Math; font-style: italic;">c</span><span class="vlist" style="display: inline-block;"><span style="display: block; height: 0px; position: relative; top: 0.15em; margin-right: 0.05em; margin-left: 0em;"><span class="fontsize-ensurer reset-size5 size5" style="display: inline-block; font-size: 1em;"><span style="font-size: 0em;"></span></span><span class="reset-textstyle scriptstyle cramped" style="display: inline-block; font-size: 0.7em;"><span class="mord mathit" style="font-family: KaTeX_Math; font-style: italic;">i</span></span></span><span class="baseline-fix" style="display: inline-table; height: 0px; position: relative; table-layout: fixed;"><span class="fontsize-ensurer reset-size5 size5" style="display: inline-block; font-size: 1em;"><span style="font-size: 0em;"></span></span></span></span></span></span></span></span>秒结束后,<span class="katex" style="font-size: 1.21em; font-family: KaTeX_Main; line-height: 1.2; white-space: nowrap;"><span class="katex-mathml" style="position: absolute; padding: 0px; border: 0px; height: 1px; width: 1px; overflow: hidden;">b_1,b_2,...,b_{c_i}</span><span class="katex-html" style="display: inline-block;"><span class="strut" style="display: inline-block; height: 0.69444em;"></span><span class="strut bottom" style="display: inline-block; height: 0.94944em; vertical-align: -0.255em;"></span><span class="base textstyle uncramped" style="display: inline-block;"><span class="mord"><span class="mord mathit" style="font-family: KaTeX_Math; font-style: italic;">b</span><span class="vlist" style="display: inline-block;"><span style="display: block; height: 0px; position: relative; top: 0.15em; margin-right: 0.05em; margin-left: 0em;"><span class="fontsize-ensurer reset-size5 size5" style="display: inline-block; font-size: 1em;"><span style="font-size: 0em;"></span></span><span class="reset-textstyle scriptstyle cramped" style="display: inline-block; font-size: 0.7em;"><span class="mord">1</span></span></span><span class="baseline-fix" style="display: inline-table; height: 0px; position: relative; table-layout: fixed;"><span class="fontsize-ensurer reset-size5 size5" style="display: inline-block; font-size: 1em;"><span style="font-size: 0em;"></span></span></span></span></span><span class="mpunct">,</span><span class="mord" style="margin-left: 0.16667em;"><span class="mord mathit" style="font-family: KaTeX_Math; font-style: italic;">b</span><span class="vlist" style="display: inline-block;"><span style="display: block; height: 0px; position: relative; top: 0.15em; margin-right: 0.05em; margin-left: 0em;"><span class="fontsize-ensurer reset-size5 size5" style="display: inline-block; font-size: 1em;"><span style="font-size: 0em;"></span></span><span class="reset-textstyle scriptstyle cramped" style="display: inline-block; font-size: 0.7em;"><span class="mord">2</span></span></span><span class="baseline-fix" style="display: inline-table; height: 0px; position: relative; table-layout: fixed;"><span class="fontsize-ensurer reset-size5 size5" style="display: inline-block; font-size: 1em;"><span style="font-size: 0em;"></span></span></span></span></span><span class="mpunct">,</span><span class="mord" style="margin-left: 0.16667em;">.</span><span class="mord">.</span><span class="mord">.</span><span class="mpunct">,</span><span class="mord" style="margin-left: 0.16667em;"><span class="mord mathit" style="font-family: KaTeX_Math; font-style: italic;">b</span><span class="vlist" style="display: inline-block;"><span style="display: block; height: 0px; position: relative; top: 0.15em; margin-right: 0.05em; margin-left: 0em;"><span class="fontsize-ensurer reset-size5 size5" style="display: inline-block; font-size: 1em;"><span style="font-size: 0em;"></span></span><span class="reset-textstyle scriptstyle cramped" style="display: inline-block; font-size: 0.7em;"><span class="mord scriptstyle cramped"><span class="mord"><span class="mord mathit" style="font-family: KaTeX_Math; font-style: italic;">c</span><span class="vlist" style="display: inline-block;"><span style="display: block; height: 0px; position: relative; top: 0.15em; margin-right: 0.0714286em; margin-left: 0em;"><span class="fontsize-ensurer reset-size5 size5" style="display: inline-block; font-size: 1em;"><span style="font-size: 0em;"></span></span><span class="reset-scriptstyle scriptscriptstyle cramped" style="display: inline-block; font-size: 0.71429em;"><span class="mord mathit" style="font-family: KaTeX_Math; font-style: italic;">i</span></span></span><span class="baseline-fix" style="display: inline-table; height: 0px; position: relative; table-layout: fixed;"><span class="fontsize-ensurer reset-size5 size5" style="display: inline-block; font-size: 1em;"><span style="font-size: 0em;"></span></span></span></span></span></span></span></span><span class="baseline-fix" style="display: inline-table; height: 0px; position: relative; table-layout: fixed;"><span class="fontsize-ensurer reset-size5 size5" style="display: inline-block; font-size: 1em;"><span style="font-size: 0em;"></span></span></span></span></span></span></span></span>都会增加1。 现在,GTW想知道在第<span class="katex" style="font-size: 1.21em; font-family: KaTeX_Main; line-height: 1.2; white-space: nowrap;"><span class="katex-mathml" style="position: absolute; padding: 0px; border: 0px; height: 1px; width: 1px; overflow: hidden;">n</span><span class="katex-html" style="display: inline-block;"><span class="strut" style="display: inline-block; height: 0.43056em;"></span><span class="strut bottom" style="display: inline-block; height: 0.43056em; vertical-align: 0em;"></span><span class="base textstyle uncramped" style="display: inline-block;"><span class="mord mathit" style="font-family: KaTeX_Math; font-style: italic;">n</span></span></span></span>秒之后,会有几只GT存活下来。
输入描述
第一行只有一个整数<span class="katex" style="font-size: 1.21em; font-family: KaTeX_Main; line-height: 1.2; white-space: nowrap;"><span class="katex-mathml" style="position: absolute; padding: 0px; border: 0px; height: 1px; width: 1px; overflow: hidden;">T(T\leq 5)</span><span class="katex-html" style="display: inline-block;"><span class="strut" style="display: inline-block; height: 0.75em;"></span><span class="strut bottom" style="display: inline-block; height: 1em; vertical-align: -0.25em;"></span><span class="base textstyle uncramped" style="display: inline-block;"><span class="mord mathit" style="font-family: KaTeX_Math; font-style: italic; margin-right: 0.13889em;">T</span><span class="mopen">(</span><span class="mord mathit" style="font-family: KaTeX_Math; font-style: italic; margin-right: 0.13889em;">T</span><span class="mrel" style="margin-left: 0.27778em;">≤</span><span class="mord" style="margin-left: 0.27778em;">5</span><span class="mclose">)</span></span></span></span>,表示测试数据组数。 第二行有两个整数<span class="katex" style="font-size: 1.21em; font-family: KaTeX_Main; line-height: 1.2; white-space: nowrap;"><span class="katex-mathml" style="position: absolute; padding: 0px; border: 0px; height: 1px; width: 1px; overflow: hidden;">n,m</span><span class="katex-html" style="display: inline-block;"><span class="strut" style="display: inline-block; height: 0.43056em;"></span><span class="strut bottom" style="display: inline-block; height: 0.625em; vertical-align: -0.19444em;"></span><span class="base textstyle uncramped" style="display: inline-block;"><span class="mord mathit" style="font-family: KaTeX_Math; font-style: italic;">n</span><span class="mpunct">,</span><span class="mord mathit" style="font-family: KaTeX_Math; font-style: italic; margin-left: 0.16667em;">m</span></span></span></span>。表示GT的个数和GTW发功的次数。(<span class="katex" style="font-size: 1.21em; font-family: KaTeX_Main; line-height: 1.2; white-space: nowrap;"><span class="katex-mathml" style="position: absolute; padding: 0px; border: 0px; height: 1px; width: 1px; overflow: hidden;">1\leq n \leq 50000,1\leq m\leq 50000</span><span class="katex-html" style="display: inline-block;"><span class="strut" style="display: inline-block; height: 0.64444em;"></span><span class="strut bottom" style="display: inline-block; height: 0.83888em; vertical-align: -0.19444em;"></span><span class="base textstyle uncramped" style="display: inline-block;"><span class="mord">1</span><span class="mrel" style="margin-left: 0.27778em;">≤</span><span class="mord mathit" style="font-family: KaTeX_Math; font-style: italic; margin-left: 0.27778em;">n</span><span class="mrel" style="margin-left: 0.27778em;">≤</span><span class="mord" style="margin-left: 0.27778em;">5</span><span class="mord">0</span><span class="mord">0</span><span class="mord">0</span><span class="mord">0</span><span class="mpunct">,</span><span class="mord" style="margin-left: 0.16667em;">1</span><span class="mrel" style="margin-left: 0.27778em;">≤</span><span class="mord mathit" style="font-family: KaTeX_Math; font-style: italic; margin-left: 0.27778em;">m</span><span class="mrel" style="margin-left: 0.27778em;">≤</span><span class="mord" style="margin-left: 0.27778em;">5</span><span class="mord">0</span><span class="mord">0</span><span class="mord">0</span><span class="mord">0</span></span></span></span>) 第三到<span class="katex" style="font-size: 1.21em; font-family: KaTeX_Main; line-height: 1.2; white-space: nowrap;"><span class="katex-mathml" style="position: absolute; padding: 0px; border: 0px; height: 1px; width: 1px; overflow: hidden;">n+2</span><span class="katex-html" style="display: inline-block;"><span class="strut" style="display: inline-block; height: 0.64444em;"></span><span class="strut bottom" style="display: inline-block; height: 0.72777em; vertical-align: -0.08333em;"></span><span class="base textstyle uncramped" style="display: inline-block;"><span class="mord mathit" style="font-family: KaTeX_Math; font-style: italic;">n</span><span class="mbin" style="margin-left: 0.22222em;">+</span><span class="mord" style="margin-left: 0.22222em;">2</span></span></span></span>行,每行有两个整数<span class="katex" style="font-size: 1.21em; font-family: KaTeX_Main; line-height: 1.2; white-space: nowrap;"><span class="katex-mathml" style="position: absolute; padding: 0px; border: 0px; height: 1px; width: 1px; overflow: hidden;">a_i,b_i</span><span class="katex-html" style="display: inline-block;"><span class="strut" style="display: inline-block; height: 0.69444em;"></span><span class="strut bottom" style="display: inline-block; height: 0.88888em; vertical-align: -0.19444em;"></span><span class="base textstyle uncramped" style="display: inline-block;"><span class="mord"><span class="mord mathit" style="font-family: KaTeX_Math; font-style: italic;">a</span><span class="vlist" style="display: inline-block;"><span style="display: block; height: 0px; position: relative; top: 0.15em; margin-right: 0.05em; margin-left: 0em;"><span class="fontsize-ensurer reset-size5 size5" style="display: inline-block; font-size: 1em;"><span style="font-size: 0em;"></span></span><span class="reset-textstyle scriptstyle cramped" style="display: inline-block; font-size: 0.7em;"><span class="mord mathit" style="font-family: KaTeX_Math; font-style: italic;">i</span></span></span><span class="baseline-fix" style="display: inline-table; height: 0px; position: relative; table-layout: fixed;"><span class="fontsize-ensurer reset-size5 size5" style="display: inline-block; font-size: 1em;"><span style="font-size: 0em;"></span></span></span></span></span><span class="mpunct">,</span><span class="mord" style="margin-left: 0.16667em;"><span class="mord mathit" style="font-family: KaTeX_Math; font-style: italic;">b</span><span class="vlist" style="display: inline-block;"><span style="display: block; height: 0px; position: relative; top: 0.15em; margin-right: 0.05em; margin-left: 0em;"><span class="fontsize-ensurer reset-size5 size5" style="display: inline-block; font-size: 1em;"><span style="font-size: 0em;"></span></span><span class="reset-textstyle scriptstyle cramped" style="display: inline-block; font-size: 0.7em;"><span class="mord mathit" style="font-family: KaTeX_Math; font-style: italic;">i</span></span></span><span class="baseline-fix" style="display: inline-table; height: 0px; position: relative; table-layout: fixed;"><span class="fontsize-ensurer reset-size5 size5" style="display: inline-block; font-size: 1em;"><span style="font-size: 0em;"></span></span></span></span></span></span></span></span>,表示第<span class="katex" style="font-size: 1.21em; font-family: KaTeX_Main; line-height: 1.2; white-space: nowrap;"><span class="katex-mathml" style="position: absolute; padding: 0px; border: 0px; height: 1px; width: 1px; overflow: hidden;">i</span><span class="katex-html" style="display: inline-block;"><span class="strut" style="display: inline-block; height: 0.65952em;"></span><span class="strut bottom" style="display: inline-block; height: 0.65952em; vertical-align: 0em;"></span><span class="base textstyle uncramped" style="display: inline-block;"><span class="mord mathit" style="font-family: KaTeX_Math; font-style: italic;">i</span></span></span></span>只GT在哪个组和他的能力值 <span class="katex" style="font-size: 1.21em; font-family: KaTeX_Main; line-height: 1.2; white-space: nowrap;"><span class="katex-mathml" style="position: absolute; padding: 0px; border: 0px; height: 1px; width: 1px; overflow: hidden;">(0\leq a[i]\leq 1,1\leq b[i]\leq 10^6)</span><span class="katex-html" style="display: inline-block;"><span class="strut" style="display: inline-block; height: 0.814108em;"></span><span class="strut bottom" style="display: inline-block; height: 1.06411em; vertical-align: -0.25em;"></span><span class="base textstyle uncramped" style="display: inline-block;"><span class="mopen">(</span><span class="mord">0</span><span class="mrel" style="margin-left: 0.27778em;">≤</span><span class="mord mathit" style="font-family: KaTeX_Math; font-style: italic; margin-left: 0.27778em;">a</span><span class="mopen">[</span><span class="mord mathit" style="font-family: KaTeX_Math; font-style: italic;">i</span><span class="mclose">]</span><span class="mrel" style="margin-left: 0.27778em;">≤</span><span class="mord" style="margin-left: 0.27778em;">1</span><span class="mpunct">,</span><span class="mord" style="margin-left: 0.16667em;">1</span><span class="mrel" style="margin-left: 0.27778em;">≤</span><span class="mord mathit" style="font-family: KaTeX_Math; font-style: italic; margin-left: 0.27778em;">b</span><span class="mopen">[</span><span class="mord mathit" style="font-family: KaTeX_Math; font-style: italic;">i</span><span class="mclose">]</span><span class="mrel" style="margin-left: 0.27778em;">≤</span><span class="mord" style="margin-left: 0.27778em;">1</span><span class="mord"><span class="mord">0</span><span class="vlist" style="display: inline-block;"><span style="display: block; height: 0px; position: relative; top: -0.363em; margin-right: 0.05em;"><span class="fontsize-ensurer reset-size5 size5" style="display: inline-block; font-size: 1em;"><span style="font-size: 0em;"></span></span><span class="reset-textstyle scriptstyle uncramped" style="display: inline-block; font-size: 0.7em;"><span class="mord">6</span></span></span><span class="baseline-fix" style="display: inline-table; height: 0px; position: relative; table-layout: fixed;"><span class="fontsize-ensurer reset-size5 size5" style="display: inline-block; font-size: 1em;"><span style="font-size: 0em;"></span></span></span></span></span><span class="mclose">)</span></span></span></span> 第<span class="katex" style="font-size: 1.21em; font-family: KaTeX_Main; line-height: 1.2; white-space: nowrap;"><span class="katex-mathml" style="position: absolute; padding: 0px; border: 0px; height: 1px; width: 1px; overflow: hidden;">n+3</span><span class="katex-html" style="display: inline-block;"><span class="strut" style="display: inline-block; height: 0.64444em;"></span><span class="strut bottom" style="display: inline-block; height: 0.72777em; vertical-align: -0.08333em;"></span><span class="base textstyle uncramped" style="display: inline-block;"><span class="mord mathit" style="font-family: KaTeX_Math; font-style: italic;">n</span><span class="mbin" style="margin-left: 0.22222em;">+</span><span class="mord" style="margin-left: 0.22222em;">3</span></span></span></span>行到第<span class="katex" style="font-size: 1.21em; font-family: KaTeX_Main; line-height: 1.2; white-space: nowrap;"><span class="katex-mathml" style="position: absolute; padding: 0px; border: 0px; height: 1px; width: 1px; overflow: hidden;">n+m+2</span><span class="katex-html" style="display: inline-block;"><span class="strut" style="display: inline-block; height: 0.64444em;"></span><span class="strut bottom" style="display: inline-block; height: 0.72777em; vertical-align: -0.08333em;"></span><span class="base textstyle uncramped" style="display: inline-block;"><span class="mord mathit" style="font-family: KaTeX_Math; font-style: italic;">n</span><span class="mbin" style="margin-left: 0.22222em;">+</span><span class="mord mathit" style="font-family: KaTeX_Math; font-style: italic; margin-left: 0.22222em;">m</span><span class="mbin" style="margin-left: 0.22222em;">+</span><span class="mord" style="margin-left: 0.22222em;">2</span></span></span></span>行,每行有一个整数<span class="katex" style="font-size: 1.21em; font-family: KaTeX_Main; line-height: 1.2; white-space: nowrap;"><span class="katex-mathml" style="position: absolute; padding: 0px; border: 0px; height: 1px; width: 1px; overflow: hidden;">c_i</span><span class="katex-html" style="display: inline-block;"><span class="strut" style="display: inline-block; height: 0.43056em;"></span><span class="strut bottom" style="display: inline-block; height: 0.58056em; vertical-align: -0.15em;"></span><span class="base textstyle uncramped" style="display: inline-block;"><span class="mord"><span class="mord mathit" style="font-family: KaTeX_Math; font-style: italic;">c</span><span class="vlist" style="display: inline-block;"><span style="display: block; height: 0px; position: relative; top: 0.15em; margin-right: 0.05em; margin-left: 0em;"><span class="fontsize-ensurer reset-size5 size5" style="display: inline-block; font-size: 1em;"><span style="font-size: 0em;"></span></span><span class="reset-textstyle scriptstyle cramped" style="display: inline-block; font-size: 0.7em;"><span class="mord mathit" style="font-family: KaTeX_Math; font-style: italic;">i</span></span></span><span class="baseline-fix" style="display: inline-table; height: 0px; position: relative; table-layout: fixed;"><span class="fontsize-ensurer reset-size5 size5" style="display: inline-block; font-size: 1em;"><span style="font-size: 0em;"></span></span></span></span></span></span></span></span>,表示GTW第<span class="katex" style="font-size: 1.21em; font-family: KaTeX_Main; line-height: 1.2; white-space: nowrap;"><span class="katex-mathml" style="position: absolute; padding: 0px; border: 0px; height: 1px; width: 1px; overflow: hidden;">i</span><span class="katex-html" style="display: inline-block;"><span class="strut" style="display: inline-block; height: 0.65952em;"></span><span class="strut bottom" style="display: inline-block; height: 0.65952em; vertical-align: 0em;"></span><span class="base textstyle uncramped" style="display: inline-block;"><span class="mord mathit" style="font-family: KaTeX_Math; font-style: italic;">i</span></span></span></span>次发功的时间。<span class="katex" style="font-size: 1.21em; font-family: KaTeX_Main; line-height: 1.2; white-space: nowrap;"><span class="katex-mathml" style="position: absolute; padding: 0px; border: 0px; height: 1px; width: 1px; overflow: hidden;">1\leq c[i]\leq n</span><span class="katex-html" style="display: inline-block;"><span class="strut" style="display: inline-block; height: 0.75em;"></span><span class="strut bottom" style="display: inline-block; height: 1em; vertical-align: -0.25em;"></span><span class="base textstyle uncramped" style="display: inline-block;"><span class="mord">1</span><span class="mrel" style="margin-left: 0.27778em;">≤</span><span class="mord mathit" style="font-family: KaTeX_Math; font-style: italic; margin-left: 0.27778em;">c</span><span class="mopen">[</span><span class="mord mathit" style="font-family: KaTeX_Math; font-style: italic;">i</span><span class="mclose">]</span><span class="mrel" style="margin-left: 0.27778em;">≤</span><span class="mord mathit" style="font-family: KaTeX_Math; font-style: italic; margin-left: 0.27778em;">n</span></span></span></span>
输出描述
总共<span class="katex" style="font-size: 1.21em; font-family: KaTeX_Main; line-height: 1.2; white-space: nowrap;"><span class="katex-mathml" style="position: absolute; padding: 0px; border: 0px; height: 1px; width: 1px; overflow: hidden;">T</span><span class="katex-html" style="display: inline-block;"><span class="strut" style="display: inline-block; height: 0.68333em;"></span><span class="strut bottom" style="display: inline-block; height: 0.68333em; vertical-align: 0em;"></span><span class="base textstyle uncramped" style="display: inline-block;"><span class="mord mathit" style="font-family: KaTeX_Math; font-style: italic; margin-right: 0.13889em;">T</span></span></span></span>行,第<span class="katex" style="font-size: 1.21em; font-family: KaTeX_Main; line-height: 1.2; white-space: nowrap;"><span class="katex-mathml" style="position: absolute; padding: 0px; border: 0px; height: 1px; width: 1px; overflow: hidden;">i</span><span class="katex-html" style="display: inline-block;"><span class="strut" style="display: inline-block; height: 0.65952em;"></span><span class="strut bottom" style="display: inline-block; height: 0.65952em; vertical-align: 0em;"></span><span class="base textstyle uncramped" style="display: inline-block;"><span class="mord mathit" style="font-family: KaTeX_Math; font-style: italic;">i</span></span></span></span>行表示第<span class="katex" style="font-size: 1.21em; font-family: KaTeX_Main; line-height: 1.2; white-space: nowrap;"><span class="katex-mathml" style="position: absolute; padding: 0px; border: 0px; height: 1px; width: 1px; overflow: hidden;">i</span><span class="katex-html" style="display: inline-block;"><span class="strut" style="display: inline-block; height: 0.65952em;"></span><span class="strut bottom" style="display: inline-block; height: 0.65952em; vertical-align: 0em;"></span><span class="base textstyle uncramped" style="display: inline-block;"><span class="mord mathit" style="font-family: KaTeX_Math; font-style: italic;">i</span></span></span></span>组数据中,GT存活的个数。
输入样例
1 4 3 0 3 1 2 0 3 1 1 1 3 4
输出样例
3
Hint
第<span class="katex" style="font-size: 1.21em; font-family: KaTeX_Main; line-height: 1.2; white-space: nowrap;"><span class="katex-mathml" style="position: absolute; padding: 0px; border: 0px; height: 1px; width: 1px; overflow: hidden;">1</span><span class="katex-html" style="display: inline-block;"><span class="strut" style="display: inline-block; height: 0.64444em;"></span><span class="strut bottom" style="display: inline-block; height: 0.64444em; vertical-align: 0em;"></span><span class="base textstyle uncramped" style="display: inline-block;"><span class="mord">1</span></span></span></span>秒后 能力值为<span class="katex" style="font-size: 1.21em; font-family: KaTeX_Main; line-height: 1.2; white-space: nowrap;"><span class="katex-mathml" style="position: absolute; padding: 0px; border: 0px; height: 1px; width: 1px; overflow: hidden;">4\ 2\ 3\ 1</span><span class="katex-html" style="display: inline-block;"><span class="strut" style="display: inline-block; height: 0.64444em;"></span><span class="strut bottom" style="display: inline-block; height: 0.64444em; vertical-align: 0em;"></span><span class="base textstyle uncramped" style="display: inline-block;"><span class="mord">4</span><span class="mord mspace" style="display: inline-block;"> </span><span class="mord">2</span><span class="mord mspace" style="display: inline-block;"> </span><span class="mord">3</span><span class="mord mspace" style="display: inline-block;"> </span><span class="mord">1</span></span></span></span> 第<span class="katex" style="font-size: 1.21em; font-family: KaTeX_Main; line-height: 1.2; white-space: nowrap;"><span class="katex-mathml" style="position: absolute; padding: 0px; border: 0px; height: 1px; width: 1px; overflow: hidden;">2</span><span class="katex-html" style="display: inline-block;"><span class="strut" style="display: inline-block; height: 0.64444em;"></span><span class="strut bottom" style="display: inline-block; height: 0.64444em; vertical-align: 0em;"></span><span class="base textstyle uncramped" style="display: inline-block;"><span class="mord">2</span></span></span></span>秒后 能力值为<span class="katex" style="font-size: 1.21em; font-family: KaTeX_Main; line-height: 1.2; white-space: nowrap;"><span class="katex-mathml" style="position: absolute; padding: 0px; border: 0px; height: 1px; width: 1px; overflow: hidden;">4\ 2\ 3\ 1</span><span class="katex-html" style="display: inline-block;"><span class="strut" style="display: inline-block; height: 0.64444em;"></span><span class="strut bottom" style="display: inline-block; height: 0.64444em; vertical-align: 0em;"></span><span class="base textstyle uncramped" style="display: inline-block;"><span class="mord">4</span><span class="mord mspace" style="display: inline-block;"> </span><span class="mord">2</span><span class="mord mspace" style="display: inline-block;"> </span><span class="mord">3</span><span class="mord mspace" style="display: inline-block;"> </span><span class="mord">1</span></span></span></span> 第<span class="katex" style="font-size: 1.21em; font-family: KaTeX_Main; line-height: 1.2; white-space: nowrap;"><span class="katex-mathml" style="position: absolute; padding: 0px; border: 0px; height: 1px; width: 1px; overflow: hidden;">3</span><span class="katex-html" style="display: inline-block;"><span class="strut" style="display: inline-block; height: 0.64444em;"></span><span class="strut bottom" style="display: inline-block; height: 0.64444em; vertical-align: 0em;"></span><span class="base textstyle uncramped" style="display: inline-block;"><span class="mord">3</span></span></span></span>秒后 能力值为<span class="katex" style="font-size: 1.21em; font-family: KaTeX_Main; line-height: 1.2; white-space: nowrap;"><span class="katex-mathml" style="position: absolute; padding: 0px; border: 0px; height: 1px; width: 1px; overflow: hidden;">5\ 3\ 4\ 1</span><span class="katex-html" style="display: inline-block;"><span class="strut" style="display: inline-block; height: 0.64444em;"></span><span class="strut bottom" style="display: inline-block; height: 0.64444em; vertical-align: 0em;"></span><span class="base textstyle uncramped" style="display: inline-block;"><span class="mord">5</span><span class="mord mspace" style="display: inline-block;"> </span><span class="mord">3</span><span class="mord mspace" style="display: inline-block;"> </span><span class="mord">4</span><span class="mord mspace" style="display: inline-block;"> </span><span class="mord">1</span></span></span></span>,第<span class="katex" style="font-size: 1.21em; font-family: KaTeX_Main; line-height: 1.2; white-space: nowrap;"><span class="katex-mathml" style="position: absolute; padding: 0px; border: 0px; height: 1px; width: 1px; overflow: hidden;">2</span><span class="katex-html" style="display: inline-block;"><span class="strut" style="display: inline-block; height: 0.64444em;"></span><span class="strut bottom" style="display: inline-block; height: 0.64444em; vertical-align: 0em;"></span><span class="base textstyle uncramped" style="display: inline-block;"><span class="mord">2</span></span></span></span>只GT被第<span class="katex" style="font-size: 1.21em; font-family: KaTeX_Main; line-height: 1.2; white-space: nowrap;"><span class="katex-mathml" style="position: absolute; padding: 0px; border: 0px; height: 1px; width: 1px; overflow: hidden;">3</span><span class="katex-html" style="display: inline-block;"><span class="strut" style="display: inline-block; height: 0.64444em;"></span><span class="strut bottom" style="display: inline-block; height: 0.64444em; vertical-align: 0em;"></span><span class="base textstyle uncramped" style="display: inline-block;"><span class="mord">3</span></span></span></span>只GT消灭掉了 第<span class="katex" style="font-size: 1.21em; font-family: KaTeX_Main; line-height: 1.2; white-space: nowrap;"><span class="katex-mathml" style="position: absolute; padding: 0px; border: 0px; height: 1px; width: 1px; overflow: hidden;">4</span><span class="katex-html" style="display: inline-block;"><span class="strut" style="display: inline-block; height: 0.64444em;"></span><span class="strut bottom" style="display: inline-block; height: 0.64444em; vertical-align: 0em;"></span><span class="base textstyle uncramped" style="display: inline-block;"><span class="mord">4</span></span></span></span>秒后 能力值为<span class="katex" style="font-size: 1.21em; font-family: KaTeX_Main; line-height: 1.2; white-space: nowrap;"><span class="katex-mathml" style="position: absolute; padding: 0px; border: 0px; height: 1px; width: 1px; overflow: hidden;">6\ 4\ 5\ 2</span><span class="katex-html" style="display: inline-block;"><span class="strut" style="display: inline-block; height: 0.64444em;"></span><span class="strut bottom" style="display: inline-block; height: 0.64444em; vertical-align: 0em;"></span><span class="base textstyle uncramped" style="display: inline-block;"><span class="mord">6</span><span class="mord mspace" style="display: inline-block;"> </span><span class="mord">4</span><span class="mord mspace" style="display: inline-block;"> </span><span class="mord">5</span><span class="mord mspace" style="display: inline-block;"> </span><span class="mord">2</span></span></span></span> <span class="katex" style="font-size: 1.21em; font-family: KaTeX_Main; line-height: 1.2; white-space: nowrap;"><span class="katex-mathml" style="position: absolute; padding: 0px; border: 0px; height: 1px; width: 1px; overflow: hidden;">c_i</span><span class="katex-html" style="display: inline-block;"><span class="strut" style="display: inline-block; height: 0.43056em;"></span><span class="strut bottom" style="display: inline-block; height: 0.58056em; vertical-align: -0.15em;"></span><span class="base textstyle uncramped" style="display: inline-block;"><span class="mord"><span class="mord mathit" style="font-family: KaTeX_Math; font-style: italic;">c</span><span class="vlist" style="display: inline-block;"><span style="display: block; height: 0px; position: relative; top: 0.15em; margin-right: 0.05em; margin-left: 0em;"><span class="fontsize-ensurer reset-size5 size5" style="display: inline-block; font-size: 1em;"><span style="font-size: 0em;"></span></span><span class="reset-textstyle scriptstyle cramped" style="display: inline-block; font-size: 0.7em;"><span class="mord mathit" style="font-family: KaTeX_Math; font-style: italic;">i</span></span></span><span class="baseline-fix" style="display: inline-table; height: 0px; position: relative; table-layout: fixed;"><span class="fontsize-ensurer reset-size5 size5" style="display: inline-block; font-size: 1em;"><span style="font-size: 0em;"></span></span></span></span></span></span></span></span>并不是有序的
首先这道题有一个很显然的O(n*logn)O(n∗logn)的做法,直接区间加,求区间最大值即可。
但是此题还有一个O(n)O(n)的做法。我们发现b_1,b_2,...,b_xb1,b2,...,bx都加11就相当于b_{x+1},b_{x+2},...,b_nbx+1,bx+2,...,bn都减11。然后我们可以倒着做,记一下最大值,如果遇到了修改操作,就把最大值减11,然后判断一下这个人会不会被消灭掉,然后再更新一下最大值。
好好题目我竟然想的这么复杂,没有敲出来。。。就是没想到吧,还需要多加训练那。。。。
#include <cstdio> #include <iostream> #include <cstring> #include <string> #include <cstdlib> #include <algorithm> #include <cmath> #include <vector> #include <set> #include <list> #include <queue> #include <map> using namespace std; #define L(i) i<<1 #define R(i) i<<1|1 #define INF 0x3f3f3f3f #define pi acos(-1.0) #define eps 1e-4 #define maxn 50010 #define MOD 1000000007 int n,m; struct node { int num,val; }a[maxn]; int b[maxn],c[maxn]; int main() { int t; scanf("%d",&t); while(t--) { scanf("%d%d",&n,&m); for(int i = 1; i <= n; i++) scanf("%d%d",&a[i].num,&a[i].val); memset(c,0,sizeof(c)); for(int i = 0; i < m; i++) scanf("%d",&b[i]); sort(b,b+m); int ans = 0,k = m-1; int max0 = 0,max1 = 0; for(int i = n; i >= 1; i--) { while(b[k] == i) //这里要用while,不能用if,因为b[k]之中可能有相同的 { max0--; max1--; k--; } if(a[i].num == 0) { if(max1 <= a[i].val) ans++; max0 = max(max0,a[i].val); } else { if(max0 <= a[i].val) ans++; max1 = max(max1,a[i].val); } } printf("%d\n",ans); } return 0; }
下面似乎是一种比较常用的方法,我没有想到。。。
直接叠加预处理好a[]数组,挖草,这都没想到,我到底是在干嘛。。。
#include <cstdio> #include <iostream> #include <cstring> #include <string> #include <cstdlib> #include <algorithm> #include <cmath> #include <vector> #include <set> #include <list> #include <queue> #include <map> using namespace std; #define L(i) i<<1 #define R(i) i<<1|1 #define INF 0x3f3f3f3f #define pi acos(-1.0) #define eps 1e-4 #define maxn 50010 #define MOD 1000000007 int n,m; struct node { int num,val; }a[maxn]; int b[maxn],c[maxn]; int main() { int t; scanf("%d",&t); while(t--) { scanf("%d%d",&n,&m); for(int i = 1; i <= n; i++) scanf("%d%d",&a[i].num,&a[i].val); memset(c,0,sizeof(c)); for(int i = 0; i < m; i++) { scanf("%d",&b[i]); c[b[i]]++; } for(int i = n; i >= 1; i--) { c[i] += c[i+1]; a[i].val += c[i]; } int ans = 0,k = m-1; int max0 = 0,max1 = 0; for(int i = n; i >= 1; i--) { if(a[i].num == 0) { if(max1 <= a[i].val) ans++; max0 = max(max0,a[i].val); } else { if(max0 <= a[i].val) ans++; max1 = max(max1,a[i].val); } } printf("%d\n",ans); } return 0; }
相关文章推荐
- 使用ShareSDK实现新浪微博的一键分享功能
- memcache的简单介绍和使用
- Android post表单到服务器
- redis(9)、redis集群之redis Cluster使用
- select 查询优化
- jQuery工作原理解析以及源代码示例
- 如何安全登入mysql server之Login Paths
- 链表之打印两个有序链表的公共部分
- poj3461 Oulipo
- [hdoj试题]A+B for Input-Output Practice (IV)
- EF+MVC+Bootstrap 项目实践 Day4
- ubuntu 下root用户无法访问声音设备的解决方案
- Redhat通过yum安装配置gcc
- 唉,不太顺呢
- nodepad++ 配置gcc
- JVM内存回收总结
- 15个热门的编程趋势及15个逐步走向衰落的编程方向
- 基于Ubuntu15系统的tiny4412SD卡烧录裸机程序
- 设计模式 -- 责任链模式或者叫职责链模式(Chain of Responsibility(CoR))
- JSON-lib框架,转换JSON、XML不再困难