﻿<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/"><channel><title>C++博客-ACM___________________________-随笔分类-ACM ( 线段树 )</title><link>http://www.cppblog.com/MiYu/category/14861.html</link><description>                             ______________白白の屋</description><language>zh-cn</language><lastBuildDate>Tue, 16 Nov 2010 20:50:44 GMT</lastBuildDate><pubDate>Tue, 16 Nov 2010 20:50:44 GMT</pubDate><ttl>60</ttl><item><title>HDU 3468 HDOJ 3468 A Simple Problem with Integers ACM 3468 IN HDU</title><link>http://www.cppblog.com/MiYu/archive/2010/11/16/133824.html</link><dc:creator>MiYu</dc:creator><author>MiYu</author><pubDate>Tue, 16 Nov 2010 13:28:00 GMT</pubDate><guid>http://www.cppblog.com/MiYu/archive/2010/11/16/133824.html</guid><wfw:comment>http://www.cppblog.com/MiYu/comments/133824.html</wfw:comment><comments>http://www.cppblog.com/MiYu/archive/2010/11/16/133824.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/MiYu/comments/commentRss/133824.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/MiYu/services/trackbacks/133824.html</trackback:ping><description><![CDATA[&nbsp;&nbsp;&nbsp;&nbsp; 摘要: MiYu原创, 转帖请注明 : 转载自&nbsp;______________白白の屋&nbsp;&nbsp;&nbsp;&nbsp;代码&lt;pre&nbsp;lang="cpp"&nbsp;line="1"&gt;/*Mail&nbsp;to&nbsp;&nbsp;&nbsp;:&nbsp;miyubai@gamil.comMy&nbsp;Blog&nbsp;&nbsp;&nbsp;:&nb...&nbsp;&nbsp;<a href='http://www.cppblog.com/MiYu/archive/2010/11/16/133824.html'>阅读全文</a><img src ="http://www.cppblog.com/MiYu/aggbug/133824.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/MiYu/" target="_blank">MiYu</a> 2010-11-16 21:28 <a href="http://www.cppblog.com/MiYu/archive/2010/11/16/133824.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>PKU 2528 POJ 2528 Mayor's posters ( 线段树+离散化 ) ACM 2528 IN PKU</title><link>http://www.cppblog.com/MiYu/archive/2010/10/15/PKU-2528.html</link><dc:creator>MiYu</dc:creator><author>MiYu</author><pubDate>Fri, 15 Oct 2010 03:12:00 GMT</pubDate><guid>http://www.cppblog.com/MiYu/archive/2010/10/15/PKU-2528.html</guid><wfw:comment>http://www.cppblog.com/MiYu/comments/129997.html</wfw:comment><comments>http://www.cppblog.com/MiYu/archive/2010/10/15/PKU-2528.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/MiYu/comments/commentRss/129997.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/MiYu/services/trackbacks/129997.html</trackback:ping><description><![CDATA[&nbsp;&nbsp;&nbsp;&nbsp; 摘要: MiYu原创, 转帖请注明 : 转载自&nbsp;______________白白の屋&nbsp;&nbsp;&nbsp;&nbsp;题目地址 :	http://poj.org/problem?id=2528题目描述:Mayor's postersTime Limit:&nbsp;1000MSMemory Limit:&nbsp;65536KTotal Submissions:&nbsp;1572...&nbsp;&nbsp;<a href='http://www.cppblog.com/MiYu/archive/2010/10/15/PKU-2528.html'>阅读全文</a><img src ="http://www.cppblog.com/MiYu/aggbug/129997.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/MiYu/" target="_blank">MiYu</a> 2010-10-15 11:12 <a href="http://www.cppblog.com/MiYu/archive/2010/10/15/PKU-2528.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>PKU 2352 POJ 2352 Stars ( 线段树版 ) ACM 2352 IN PKU</title><link>http://www.cppblog.com/MiYu/archive/2010/10/13/PKU-2352-POJ-2352-Stars-ACM-2352-IN-PKU.html</link><dc:creator>MiYu</dc:creator><author>MiYu</author><pubDate>Wed, 13 Oct 2010 14:29:00 GMT</pubDate><guid>http://www.cppblog.com/MiYu/archive/2010/10/13/PKU-2352-POJ-2352-Stars-ACM-2352-IN-PKU.html</guid><wfw:comment>http://www.cppblog.com/MiYu/comments/129780.html</wfw:comment><comments>http://www.cppblog.com/MiYu/archive/2010/10/13/PKU-2352-POJ-2352-Stars-ACM-2352-IN-PKU.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/MiYu/comments/commentRss/129780.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/MiYu/services/trackbacks/129780.html</trackback:ping><description><![CDATA[<p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; font-family: verdana, 'courier new'; font-size: 14px; line-height: 21px; ">MiYu原创, 转帖请注明 : 转载自&nbsp;<a href="http://www.cnblogs.com/MiYu"><font  color="#000000">______________白白の屋</font></a>&nbsp;&nbsp;<img src="http://www.cnblogs.com/Emoticons/baimantou/223332482.gif" alt="">&nbsp;&nbsp;</p><p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; font-family: verdana, 'courier new'; font-size: 14px; line-height: 21px; ">题目地址 :</p><p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; font-family: verdana, 'courier new'; font-size: 14px; line-height: 21px; "><span class="Apple-tab-span" style="white-space: pre; ">	</span><a href="http://poj.org/problem?id=2352">http://poj.org/problem?id=2352</a></p><p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; font-family: verdana, 'courier new'; font-size: 14px; line-height: 21px; ">题目描述:</p><div class="cnblogs_code" style="background-color: rgb(245, 245, 245); font-family: 'Courier New'; font-size: 13px; border-left-color: rgb(204, 204, 204); padding-top: 5px; padding-right: 5px; padding-bottom: 5px; padding-left: 5px; word-break: break-all; overflow-x: auto; overflow-y: auto; line-height: 21px; "><div><font  color="#800080"><span  style="font-family: Simsun; color: rgb(0, 0, 0); line-height: normal; font-size: medium; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; "><div class="ptt" lang="en-US" style="text-align: center; font-family: Arial, Helvetica, sans-serif; font-size: 18pt; font-weight: bold; color: blue; ">Stars</div><div class="plm" style="text-align: center; font-family: Arial, Helvetica, sans-serif; font-size: 12pt; "><table align="center"><tbody><tr><td><strong>Time Limit:</strong>&nbsp;1000MS</td><td width="10px"></td><td><strong>Memory Limit:</strong>&nbsp;65536K</td></tr><tr><td><strong>Total Submissions:</strong>&nbsp;14814</td><td width="10px"></td><td><strong>Accepted:</strong>&nbsp;6404</td></tr></tbody></table></div><p class="pst" style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; text-align: left; font-family: Arial, Helvetica, sans-serif; font-size: 18pt; font-weight: bold; color: blue; ">Description</p><div class="ptx" lang="en-US" style="font-family: 'Times New Roman', Times, serif; font-size: 12pt; ">Astronomers often examine star maps where stars are represented by points on a plane and each star has Cartesian coordinates. Let the level of a star be an amount of the stars that are not higher and not to the right of the given star. Astronomers want to know the distribution of the levels of the stars.&nbsp;<br><center><img src="http://poj.org/images/2352_1.jpg"></center><br>For example, look at the map shown on the figure above. Level of the star number 5 is equal to 3 (it's formed by three stars with a numbers 1, 2 and 4). And the levels of the stars numbered by 2 and 4 are 1. At this map there are only one star of the level 0, two stars of the level 1, one star of the level 2, and one star of the level 3.&nbsp;<br><br>You are to write a program that will count the amounts of the stars of each level on a given map.</div><p class="pst" style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; text-align: left; font-family: Arial, Helvetica, sans-serif; font-size: 18pt; font-weight: bold; color: blue; ">Input</p><div class="ptx" lang="en-US" style="font-family: 'Times New Roman', Times, serif; font-size: 12pt; ">The first line of the input file contains a number of stars N (1&lt;=N&lt;=15000). The following N lines describe coordinates of stars (two integers X and Y per line separated by a space, 0&lt;=X,Y&lt;=32000). There can be only one star at one point of the plane. Stars are listed in ascending order of Y coordinate. Stars with equal Y coordinates are listed in ascending order of X coordinate.&nbsp;<br></div><p class="pst" style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; text-align: left; font-family: Arial, Helvetica, sans-serif; font-size: 18pt; font-weight: bold; color: blue; ">Output</p><div class="ptx" lang="en-US" style="font-family: 'Times New Roman', Times, serif; font-size: 12pt; ">The output should contain N lines, one number per line. The first line contains amount of stars of the level 0, the second does amount of stars of the level 1 and so on, the last line contains amount of stars of the level N-1.</div><p class="pst" style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; text-align: left; font-family: Arial, Helvetica, sans-serif; font-size: 18pt; font-weight: bold; color: blue; ">Sample Input</p><pre class="sio" style="font-family: 'Courier New', Courier, monospace; font-size: 12pt; ">5
1 1
5 1
7 1
3 3
5 5</pre><p class="pst" style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; text-align: left; font-family: Arial, Helvetica, sans-serif; font-size: 18pt; font-weight: bold; color: blue; ">Sample Output</p><pre class="sio" style="font-family: 'Courier New', Courier, monospace; font-size: 12pt; ">1
2
1
1
0</pre><pre class="sio" style="font-family: 'Courier New', Courier, monospace; font-size: 12pt; "> 与树状数组的解法一样,  查询更新就可以了. </pre><pre class="sio" style="font-family: 'Courier New', Courier, monospace; font-size: 12pt; "><span class="Apple-tab-span" style="font-family: 'Courier New'; white-space: pre; ">	</span>树状数组 解法传送门 :&nbsp;<span  style="font-family: Simsun; white-space: normal; font-size: medium; "><a href="http://www.cnblogs.com/MiYu/archive/2010/08/26/1808963.html">http://www.cnblogs.com/MiYu/archive/2010/08/26/1808963.html</a><span  style="font-family: 'Courier New', Courier, monospace; font-size: 16px; white-space: pre; "> </span></span></pre><pre class="sio" style="font-family: 'Courier New', Courier, monospace; font-size: 12pt; ">代码如下 : </pre><pre class="sio" style="font-family: 'Courier New', Courier, monospace; font-size: 12pt; "><font  face="'Courier New', Courier, monospace">/*
Mail to   : miyubai@gamil.com
Link      : http://www.cnblogs.com/MiYu  || http://www.cppblog.com/MiYu
Author By : MiYu
Test      : 1
Complier  : g++ mingw32-3.4.2
Program   : POJ_2352
Doc Name  : Stars
*/
//#pragma warning( disable:4789 )
#include &lt;iostream&gt;
#include &lt;fstream&gt;
#include &lt;sstream&gt;
#include &lt;algorithm&gt;
#include &lt;string&gt;
#include &lt;set&gt;
#include &lt;map&gt;
#include &lt;utility&gt;
#include &lt;queue&gt;
#include &lt;stack&gt;
#include &lt;list&gt;
#include &lt;vector&gt;
#include &lt;cstdio&gt;
#include &lt;cstdlib&gt;
#include &lt;cstring&gt;
#include &lt;cmath&gt;
#include &lt;ctime&gt;
using namespace std;
struct P{
       int x, y;
}p[15010];
int seg[100000];
int NN = 32768, res[15010];
int get ( int &amp;n ) {
    int i = 1;
    while ( i &lt; n ) i &lt;&lt; 1;
    return i;    
}
void modify ( int &amp;pos ) {
     pos += NN;
     seg[pos] ++;
     while ( pos &gt; 1 ) {
           if ( ~pos &amp; 1 ) seg[pos&gt;&gt;1] ++;
           pos &gt;&gt;= 1;
     }
}
int query ( int pos ) {
     pos += NN;  
     int sum = seg[pos];
     while ( pos &gt; 1 ) {
            if ( pos &amp; 1 ) {
                 sum += seg[pos&gt;&gt;1];  
            }      
            pos &gt;&gt;= 1;
     }   
     return sum;
}
int main ()
{
    int N;
    while ( scanf ( "%d", &amp;N ) == 1 ) {
           int pos;
           memset ( res, 0, sizeof ( res ) );
           memset ( seg, 0, sizeof ( seg ) );
           for ( int i = 0; i &lt; N; ++ i ) {
                  scanf ( "%d%*d", &amp;pos );
                  res[ query ( pos ) ] ++;
                  modify ( pos );   
           }   
           for ( int i = 0; i &lt; N; ++ i ) {
                printf ( "%d\n", res[i] );     
           } 
    }
    return 0;
}</font>
</pre><div><br></div></span></font></div></div><p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; font-family: verdana, 'courier new'; font-size: 14px; line-height: 21px; "></p><p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; font-family: verdana, 'courier new'; font-size: 14px; line-height: 21px; ">&nbsp;</p>
<img src ="http://www.cppblog.com/MiYu/aggbug/129780.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/MiYu/" target="_blank">MiYu</a> 2010-10-13 22:29 <a href="http://www.cppblog.com/MiYu/archive/2010/10/13/PKU-2352-POJ-2352-Stars-ACM-2352-IN-PKU.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>HDU 3016  HDOJ 3016 Man Down ACM 3016 IN HDU</title><link>http://www.cppblog.com/MiYu/archive/2010/10/13/HDU-2871-HDOJ-2871-Memory-Control-ACM-2871-IN-HDU.html</link><dc:creator>MiYu</dc:creator><author>MiYu</author><pubDate>Wed, 13 Oct 2010 13:26:00 GMT</pubDate><guid>http://www.cppblog.com/MiYu/archive/2010/10/13/HDU-2871-HDOJ-2871-Memory-Control-ACM-2871-IN-HDU.html</guid><wfw:comment>http://www.cppblog.com/MiYu/comments/129775.html</wfw:comment><comments>http://www.cppblog.com/MiYu/archive/2010/10/13/HDU-2871-HDOJ-2871-Memory-Control-ACM-2871-IN-HDU.html#Feedback</comments><slash:comments>2</slash:comments><wfw:commentRss>http://www.cppblog.com/MiYu/comments/commentRss/129775.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/MiYu/services/trackbacks/129775.html</trackback:ping><description><![CDATA[<p style="LINE-HEIGHT: 21px; TEXT-INDENT: 0px; MARGIN: 5px auto; FONT-FAMILY: verdana, 'courier new'; FONT-SIZE: 14px">MiYu原创, 转帖请注明 : 转载自&nbsp;<a href="http://www.cnblogs.com/MiYu"><font color=#000000>______________白白の屋</font></a>&nbsp;&nbsp;<img alt="" src="http://www.cnblogs.com/Emoticons/baimantou/223332482.gif">&nbsp;&nbsp;</p>
<p style="LINE-HEIGHT: 21px; TEXT-INDENT: 0px; MARGIN: 5px auto; FONT-FAMILY: verdana, 'courier new'; FONT-SIZE: 14px">题目地址 :</p>
<p style="LINE-HEIGHT: 21px; TEXT-INDENT: 0px; MARGIN: 5px auto; FONT-FAMILY: verdana, 'courier new'; FONT-SIZE: 14px"><span style="WHITE-SPACE: pre" class=Apple-tab-span></span><a href="http://acm.hdu.edu.cn/showproblem.php?pid=3016">http://acm.hdu.edu.cn/showproblem.php?pid=3016</a></p>
<p style="LINE-HEIGHT: 21px; TEXT-INDENT: 0px; MARGIN: 5px auto; FONT-FAMILY: verdana, 'courier new'; FONT-SIZE: 14px">题目描述:</p>
<div style="PADDING-BOTTOM: 5px; LINE-HEIGHT: 21px; OVERFLOW-X: auto; OVERFLOW-Y: auto; BACKGROUND-COLOR: rgb(245,245,245); PADDING-LEFT: 5px; PADDING-RIGHT: 5px; FONT-FAMILY: 'Courier New'; FONT-SIZE: 13px; BORDER-LEFT-COLOR: rgb(204,204,204); WORD-BREAK: break-all; PADDING-TOP: 5px" class=cnblogs_code>
<div><font color=#800080><span style="LINE-HEIGHT: normal; FONT-FAMILY: 'Times New Roman'; COLOR: rgb(0,0,0); FONT-SIZE: medium">
<h1 style="TEXT-ALIGN: center; COLOR: rgb(26,92,200)">Man Down</h1>
<font size=+0><strong><span style="FONT-FAMILY: Arial; COLOR: green; FONT-SIZE: 12px; FONT-WEIGHT: bold">Time Limit: 2000/1000 MS (Java/Others)&nbsp;&nbsp;&nbsp;&nbsp;Memory Limit: 32768/32768 K (Java/Others)<br>Total Submission(s): 618&nbsp;&nbsp;&nbsp;&nbsp;Accepted Submission(s): 197<br></span></strong></font><br><br>
<div style="BACKGROUND-IMAGE: url(http://acm.hdu.edu.cn/images/panel-title.png); PADDING-BOTTOM: 0px; BACKGROUND-COLOR: transparent; PADDING-LEFT: 14px; PADDING-RIGHT: 14px; FONT-FAMILY: Arial; BACKGROUND-POSITION: 0% 100%; HEIGHT: 38px; COLOR: rgb(124,169,237); FONT-SIZE: 18px; FONT-WEIGHT: bold; PADDING-TOP: 0px; background-origin: initial; background-clip: initial" class=panel_title align=left>Problem Description</div>
<div style="BACKGROUND-IMAGE: url(http://acm.hdu.edu.cn/images/panel-content.png); TEXT-ALIGN: left; PADDING-BOTTOM: 0px; MARGIN: 0px; PADDING-LEFT: 20px; PADDING-RIGHT: 20px; FONT-FAMILY: 'Times New Roman'; HEIGHT: auto; FONT-SIZE: 14px; PADDING-TOP: 0px; background-origin: initial; background-clip: initial" class=panel_content>The Game &#8220;Man Down 100 floors&#8221; is an famous and interesting game.You can enjoy the game from&nbsp;<br>http://hi.baidu.com/abcdxyzk/blog/item/16398781b4f2a5d1bd3e1eed.html<br>
<center><img style="BORDER-BOTTOM-STYLE: none; BORDER-RIGHT-STYLE: none; BORDER-TOP-STYLE: none; BORDER-LEFT-STYLE: none" src="http://acm.hdu.edu.cn/data/images/exe3016-1.JPG"></center><br>We take a simplified version of this game. We have only two kinds of planks. One kind of the planks contains food and the other one contains nails. And if the man falls on the plank which contains food his energy will increase but if he falls on the plank which contains nails his energy will decrease. The man can only fall down vertically .We assume that the energy he can increase is unlimited and no borders exist on the left and the right.<br><br>First the man has total energy 100 and stands on the topmost plank of all. Then he can choose to go left or right to fall down. If he falls down from the position (Xi,Yi),he will fall onto the nearest plank which satisfies (xl &lt;= xi &lt;= xr)(xl is the leftmost position of the plank and xr is the rightmost).If no planks satisfies that, the man will fall onto the floor and he finishes his mission. But if the man&#8217;s energy is below or equal to 0 , he will die and the game is Over.<br><br>Now give you the height and position of all planks. And ask you whether the man can falls onto the floor successfully. If he can, try to calculate the maximum energy he can own when he is on the floor.(Assuming that the floor is infinite and its height is 0,and all the planks are located at different height).</div>
<div style="BACKGROUND-IMAGE: url(http://acm.hdu.edu.cn/images/panel-bottom.png); MARGIN: 0px; BACKGROUND-POSITION: 0% 0%; HEIGHT: auto; background-origin: initial; background-clip: initial" class=panel_bottom>&nbsp;</div>
<br>
<div style="BACKGROUND-IMAGE: url(http://acm.hdu.edu.cn/images/panel-title.png); PADDING-BOTTOM: 0px; BACKGROUND-COLOR: transparent; PADDING-LEFT: 14px; PADDING-RIGHT: 14px; FONT-FAMILY: Arial; BACKGROUND-POSITION: 0% 100%; HEIGHT: 38px; COLOR: rgb(124,169,237); FONT-SIZE: 18px; FONT-WEIGHT: bold; PADDING-TOP: 0px; background-origin: initial; background-clip: initial" class=panel_title align=left>Input</div>
<div style="BACKGROUND-IMAGE: url(http://acm.hdu.edu.cn/images/panel-content.png); TEXT-ALIGN: left; PADDING-BOTTOM: 0px; MARGIN: 0px; PADDING-LEFT: 20px; PADDING-RIGHT: 20px; FONT-FAMILY: 'Times New Roman'; HEIGHT: auto; FONT-SIZE: 14px; PADDING-TOP: 0px; background-origin: initial; background-clip: initial" class=panel_content>There are multiple test cases.<br><br>For each test case, The first line contains one integer N (2 &lt;= N &lt;= 100,000) representing the number of planks.<br><br>Then following N lines representing N planks, each line contain 4 integers (h,xl,xr,value)(h &gt; 0, 0 &lt; xl &lt; xr &lt; 100,000, -1000 &lt;= value &lt;= 1000), h represents the plank&#8217;s height, xl is the leftmost position of the plank and xr is the rightmost position. Value represents the energy the man will increase by( if value &gt; 0) or decrease by( if value &lt; 0) when he falls onto this plank.</div>
<div style="BACKGROUND-IMAGE: url(http://acm.hdu.edu.cn/images/panel-bottom.png); MARGIN: 0px; BACKGROUND-POSITION: 0% 0%; HEIGHT: auto; background-origin: initial; background-clip: initial" class=panel_bottom>&nbsp;</div>
<br>
<div style="BACKGROUND-IMAGE: url(http://acm.hdu.edu.cn/images/panel-title.png); PADDING-BOTTOM: 0px; BACKGROUND-COLOR: transparent; PADDING-LEFT: 14px; PADDING-RIGHT: 14px; FONT-FAMILY: Arial; BACKGROUND-POSITION: 0% 100%; HEIGHT: 38px; COLOR: rgb(124,169,237); FONT-SIZE: 18px; FONT-WEIGHT: bold; PADDING-TOP: 0px; background-origin: initial; background-clip: initial" class=panel_title align=left>Output</div>
<div style="BACKGROUND-IMAGE: url(http://acm.hdu.edu.cn/images/panel-content.png); TEXT-ALIGN: left; PADDING-BOTTOM: 0px; MARGIN: 0px; PADDING-LEFT: 20px; PADDING-RIGHT: 20px; FONT-FAMILY: 'Times New Roman'; HEIGHT: auto; FONT-SIZE: 14px; PADDING-TOP: 0px; background-origin: initial; background-clip: initial" class=panel_content>If the man can falls onto the floor successfully just output the maximum energy he can own when he is on the floor. But if the man can not fall down onto the floor anyway ,just output &#8220;-1&#8221;(not including the quote)</div>
<div style="BACKGROUND-IMAGE: url(http://acm.hdu.edu.cn/images/panel-bottom.png); MARGIN: 0px; BACKGROUND-POSITION: 0% 0%; HEIGHT: auto; background-origin: initial; background-clip: initial" class=panel_bottom>&nbsp;</div>
<br>
<div style="BACKGROUND-IMAGE: url(http://acm.hdu.edu.cn/images/panel-title.png); PADDING-BOTTOM: 0px; BACKGROUND-COLOR: transparent; PADDING-LEFT: 14px; PADDING-RIGHT: 14px; FONT-FAMILY: Arial; BACKGROUND-POSITION: 0% 100%; HEIGHT: 38px; COLOR: rgb(124,169,237); FONT-SIZE: 18px; FONT-WEIGHT: bold; PADDING-TOP: 0px; background-origin: initial; background-clip: initial" class=panel_title align=left>Sample Input</div>
<div style="BACKGROUND-IMAGE: url(http://acm.hdu.edu.cn/images/panel-content.png); TEXT-ALIGN: left; PADDING-BOTTOM: 0px; MARGIN: 0px; PADDING-LEFT: 20px; PADDING-RIGHT: 20px; FONT-FAMILY: 'Times New Roman'; HEIGHT: auto; FONT-SIZE: 14px; PADDING-TOP: 0px; background-origin: initial; background-clip: initial" class=panel_content>
<pre style="MARGIN: 0px; FONT-SIZE: 14px">
<div style="FONT-FAMILY: 'Courier New', Courier, monospace">4
10 5 10 10
5 3 6 -100
4 7 11 20
2 2 1000 10</div>
</pre>
</div>
<div style="BACKGROUND-IMAGE: url(http://acm.hdu.edu.cn/images/panel-bottom.png); MARGIN: 0px; BACKGROUND-POSITION: 0% 0%; HEIGHT: auto; background-origin: initial; background-clip: initial" class=panel_bottom>&nbsp;</div>
<br>
<div style="BACKGROUND-IMAGE: url(http://acm.hdu.edu.cn/images/panel-title.png); PADDING-BOTTOM: 0px; BACKGROUND-COLOR: transparent; PADDING-LEFT: 14px; PADDING-RIGHT: 14px; FONT-FAMILY: Arial; BACKGROUND-POSITION: 0% 100%; HEIGHT: 38px; COLOR: rgb(124,169,237); FONT-SIZE: 18px; FONT-WEIGHT: bold; PADDING-TOP: 0px; background-origin: initial; background-clip: initial" class=panel_title align=left>Sample Output</div>
<div style="BACKGROUND-IMAGE: url(http://acm.hdu.edu.cn/images/panel-content.png); TEXT-ALIGN: left; PADDING-BOTTOM: 0px; MARGIN: 0px; PADDING-LEFT: 20px; PADDING-RIGHT: 20px; FONT-FAMILY: 'Times New Roman'; HEIGHT: auto; FONT-SIZE: 14px; PADDING-TOP: 0px; background-origin: initial; background-clip: initial" class=panel_content>
<pre style="MARGIN: 0px; FONT-SIZE: 14px">
<div style="FONT-FAMILY: 'Courier New', Courier, monospace">140</div>
</pre>
</div>
<div style="BACKGROUND-IMAGE: url(http://acm.hdu.edu.cn/images/panel-bottom.png); MARGIN: 0px; BACKGROUND-POSITION: 0% 0%; HEIGHT: auto; background-origin: initial; background-clip: initial" class=panel_bottom>&nbsp;</div>
<div><br></div>
<p style="TEXT-INDENT: 0px; MARGIN: 5px auto">&nbsp;/*</p>
<p style="TEXT-INDENT: 0px; MARGIN: 5px auto">&nbsp;&nbsp;题目描述: &nbsp;</p>
<p style="TEXT-INDENT: 0px; MARGIN: 5px auto">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;不同高度处有不同的水平板，跳到该板会有血量变化v，</p>
<p style="TEXT-INDENT: 0px; MARGIN: 5px auto">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;问当一个人从最高板开始，可以向左或者向右，</p>
<p style="TEXT-INDENT: 0px; MARGIN: 5px auto">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;竖直跳到下面的板，求下落到地面的最大血量，或者-1。</p>
<p style="TEXT-INDENT: 0px; MARGIN: 5px auto">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;线段树+dp &nbsp;</p>
<p style="TEXT-INDENT: 0px; MARGIN: 5px auto">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;需要用线段树查询得到每个板的两个端点下落后会到哪个板；</p>
<p style="TEXT-INDENT: 0px; MARGIN: 5px auto">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;然后根据这个从最高的开始dp就可以了</p>
<p style="TEXT-INDENT: 0px; MARGIN: 5px auto">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;dp[i] = max ( dp[i], dp[i^].v ) &nbsp;// dp[i^] 代表能走到 i 的线段&nbsp;</p>
<p style="TEXT-INDENT: 0px; MARGIN: 5px auto">/*&nbsp;</p>
<p style="TEXT-INDENT: 0px; MARGIN: 5px auto"><br></p>
<p style="TEXT-INDENT: 0px; MARGIN: 5px auto">/*</p>
<p style="TEXT-INDENT: 0px; MARGIN: 5px auto">Mail to &nbsp; : miyubai@gamil.com</p>
<p style="TEXT-INDENT: 0px; MARGIN: 5px auto">Link &nbsp; &nbsp; &nbsp;: http://www.cnblogs.com/MiYu &nbsp;|| http://www.cppblog.com/MiYu</p>
<p style="TEXT-INDENT: 0px; MARGIN: 5px auto">Author By : MiYu</p>
<p style="TEXT-INDENT: 0px; MARGIN: 5px auto">Test &nbsp; &nbsp; &nbsp;: 1</p>
<p style="TEXT-INDENT: 0px; MARGIN: 5px auto">Complier &nbsp;: g++ mingw32-3.4.2</p>
<p style="TEXT-INDENT: 0px; MARGIN: 5px auto">Program &nbsp; : HDU_3016</p>
<p style="TEXT-INDENT: 0px; MARGIN: 5px auto">Doc Name &nbsp;: Man Down</p>
<p style="TEXT-INDENT: 0px; MARGIN: 5px auto">*/</p>
<p style="TEXT-INDENT: 0px; MARGIN: 5px auto">//#pragma warning( disable:4789 )</p>
<p style="TEXT-INDENT: 0px; MARGIN: 5px auto">#include &lt;iostream&gt;</p>
<p style="TEXT-INDENT: 0px; MARGIN: 5px auto">#include &lt;fstream&gt;</p>
<p style="TEXT-INDENT: 0px; MARGIN: 5px auto">#include &lt;sstream&gt;</p>
<p style="TEXT-INDENT: 0px; MARGIN: 5px auto">#include &lt;algorithm&gt;</p>
<p style="TEXT-INDENT: 0px; MARGIN: 5px auto">#include &lt;string&gt;</p>
<p style="TEXT-INDENT: 0px; MARGIN: 5px auto">#include &lt;set&gt;</p>
<p style="TEXT-INDENT: 0px; MARGIN: 5px auto">#include &lt;map&gt;</p>
<p style="TEXT-INDENT: 0px; MARGIN: 5px auto">#include &lt;utility&gt;</p>
<p style="TEXT-INDENT: 0px; MARGIN: 5px auto">#include &lt;queue&gt;</p>
<p style="TEXT-INDENT: 0px; MARGIN: 5px auto">#include &lt;stack&gt;</p>
<p style="TEXT-INDENT: 0px; MARGIN: 5px auto">#include &lt;list&gt;</p>
<p style="TEXT-INDENT: 0px; MARGIN: 5px auto">#include &lt;vector&gt;</p>
<p style="TEXT-INDENT: 0px; MARGIN: 5px auto">#include &lt;cstdio&gt;</p>
<p style="TEXT-INDENT: 0px; MARGIN: 5px auto">#include &lt;cstdlib&gt;</p>
<p style="TEXT-INDENT: 0px; MARGIN: 5px auto">#include &lt;cstring&gt;</p>
<p style="TEXT-INDENT: 0px; MARGIN: 5px auto">#include &lt;cmath&gt;</p>
<p style="TEXT-INDENT: 0px; MARGIN: 5px auto">#include &lt;ctime&gt;</p>
<p style="TEXT-INDENT: 0px; MARGIN: 5px auto">using namespace std;</p>
<p style="TEXT-INDENT: 0px; MARGIN: 5px auto">struct seg_tree {</p>
<p style="TEXT-INDENT: 0px; MARGIN: 5px auto">&nbsp;&nbsp; &nbsp;int id, left, right;</p>
<p style="TEXT-INDENT: 0px; MARGIN: 5px auto">&nbsp;&nbsp; &nbsp;int mid () { return ( left + right )&gt;&gt;1; } &nbsp;</p>
<p style="TEXT-INDENT: 0px; MARGIN: 5px auto">}seg[333333];</p>
<p style="TEXT-INDENT: 0px; MARGIN: 5px auto">inline void creat ( int x, int y, int rt = 1 ) {</p>
<p style="TEXT-INDENT: 0px; MARGIN: 5px auto">&nbsp;&nbsp; &nbsp; seg[rt].left = x;</p>
<p style="TEXT-INDENT: 0px; MARGIN: 5px auto">&nbsp;&nbsp; &nbsp; seg[rt].right = y;</p>
<p style="TEXT-INDENT: 0px; MARGIN: 5px auto">&nbsp;&nbsp; &nbsp; //0 代表地面 其他的自然数代表各层的木板编号 &nbsp;-1 代表有多条线段覆盖&nbsp;</p>
<p style="TEXT-INDENT: 0px; MARGIN: 5px auto">&nbsp;&nbsp; &nbsp; seg[rt].id = 0; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</p>
<p style="TEXT-INDENT: 0px; MARGIN: 5px auto">&nbsp;&nbsp; &nbsp; if ( x == y ) return ;</p>
<p style="TEXT-INDENT: 0px; MARGIN: 5px auto">&nbsp;&nbsp; &nbsp; int mid = seg[rt].mid();</p>
<p style="TEXT-INDENT: 0px; MARGIN: 5px auto">&nbsp;&nbsp; &nbsp; creat ( x, mid, rt &lt;&lt; 1 );</p>
<p style="TEXT-INDENT: 0px; MARGIN: 5px auto">&nbsp;&nbsp; &nbsp; creat ( mid + 1, y, rt &lt;&lt; 1 | 1 ); &nbsp; &nbsp;&nbsp;</p>
<p style="TEXT-INDENT: 0px; MARGIN: 5px auto">}</p>
<p style="TEXT-INDENT: 0px; MARGIN: 5px auto">inline void modify ( int x, int y, int id, int rt = 1 ) {</p>
<p style="TEXT-INDENT: 0px; MARGIN: 5px auto">&nbsp;&nbsp; &nbsp; //找到了线段, 直接修改ID 覆盖掉&nbsp;</p>
<p style="TEXT-INDENT: 0px; MARGIN: 5px auto">&nbsp;&nbsp; &nbsp; if ( seg[rt].left == x &amp;&amp; seg[rt].right == y ) {</p>
<p style="TEXT-INDENT: 0px; MARGIN: 5px auto">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; seg[rt].id = id;</p>
<p style="TEXT-INDENT: 0px; MARGIN: 5px auto">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; return; &nbsp;&nbsp;</p>
<p style="TEXT-INDENT: 0px; MARGIN: 5px auto">&nbsp;&nbsp; &nbsp; }</p>
<p style="TEXT-INDENT: 0px; MARGIN: 5px auto">&nbsp;&nbsp; &nbsp; int LL = rt &lt;&lt; 1, RR = rt &lt;&lt; 1 | 1, mid = seg[rt].mid();</p>
<p style="TEXT-INDENT: 0px; MARGIN: 5px auto">&nbsp;&nbsp; &nbsp; // 前面没有return掉, 那么这条线段肯定是被覆盖的, 将它的标记下传后标记为-1&nbsp;</p>
<p style="TEXT-INDENT: 0px; MARGIN: 5px auto">&nbsp;&nbsp; &nbsp; if ( seg[rt].id != -1 ) { &nbsp; &nbsp; &nbsp;</p>
<p style="TEXT-INDENT: 0px; MARGIN: 5px auto">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; seg[LL].id = seg[RR].id = seg[rt].id; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</p>
<p style="TEXT-INDENT: 0px; MARGIN: 5px auto">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; seg[rt].id = -1;</p>
<p style="TEXT-INDENT: 0px; MARGIN: 5px auto">&nbsp;&nbsp; &nbsp; } &nbsp; &nbsp; &nbsp;</p>
<p style="TEXT-INDENT: 0px; MARGIN: 5px auto">&nbsp;&nbsp; &nbsp; if ( y &lt;= mid ) modify ( x, y, id, LL ); //分段修改&nbsp;</p>
<p style="TEXT-INDENT: 0px; MARGIN: 5px auto">&nbsp;&nbsp; &nbsp; else if ( x &gt; mid ) modify ( x, y, id, RR );</p>
<p style="TEXT-INDENT: 0px; MARGIN: 5px auto">&nbsp;&nbsp; &nbsp; else {</p>
<p style="TEXT-INDENT: 0px; MARGIN: 5px auto">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;modify ( x, mid, id, LL );</p>
<p style="TEXT-INDENT: 0px; MARGIN: 5px auto">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;modify ( mid + 1, y, id, RR ); &nbsp; &nbsp;&nbsp;</p>
<p style="TEXT-INDENT: 0px; MARGIN: 5px auto">&nbsp;&nbsp; &nbsp; }</p>
<p style="TEXT-INDENT: 0px; MARGIN: 5px auto">}</p>
<p style="TEXT-INDENT: 0px; MARGIN: 5px auto">inline int query ( int pos, int rt = 1 ) { &nbsp; // 查询 Pos 所在线段的 id &nbsp;</p>
<p style="TEXT-INDENT: 0px; MARGIN: 5px auto">&nbsp;&nbsp; &nbsp;if ( seg[rt].id != -1 ) return seg[rt].id; //线段被覆盖 直接返回 ID&nbsp;</p>
<p style="TEXT-INDENT: 0px; MARGIN: 5px auto">&nbsp;&nbsp; &nbsp;int LL = rt &lt;&lt; 1, RR = rt &lt;&lt; 1 | 1, mid = seg[rt].mid();</p>
<p style="TEXT-INDENT: 0px; MARGIN: 5px auto">&nbsp;&nbsp; &nbsp;if ( pos &lt;= mid ) return query ( pos, LL ); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //分段查询&nbsp;</p>
<p style="TEXT-INDENT: 0px; MARGIN: 5px auto">&nbsp;&nbsp; &nbsp;else return query ( pos, RR ); &nbsp; &nbsp;</p>
<p style="TEXT-INDENT: 0px; MARGIN: 5px auto">}</p>
<p style="TEXT-INDENT: 0px; MARGIN: 5px auto">inline bool scan_d(int &amp;num) &nbsp;//整数输入</p>
<p style="TEXT-INDENT: 0px; MARGIN: 5px auto">{</p>
<p style="TEXT-INDENT: 0px; MARGIN: 5px auto">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;char in;bool IsN=false;</p>
<p style="TEXT-INDENT: 0px; MARGIN: 5px auto">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;in=getchar();</p>
<p style="TEXT-INDENT: 0px; MARGIN: 5px auto">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;if(in==EOF) return false;</p>
<p style="TEXT-INDENT: 0px; MARGIN: 5px auto">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;while(in!='-'&amp;&amp;(in&lt;'0'||in&gt;'9')) in=getchar();</p>
<p style="TEXT-INDENT: 0px; MARGIN: 5px auto">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;if(in=='-'){ IsN=true;num=0;}</p>
<p style="TEXT-INDENT: 0px; MARGIN: 5px auto">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;else num=in-'0';</p>
<p style="TEXT-INDENT: 0px; MARGIN: 5px auto">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;while(in=getchar(),in&gt;='0'&amp;&amp;in&lt;='9'){</p>
<p style="TEXT-INDENT: 0px; MARGIN: 5px auto">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;num*=10,num+=in-'0';</p>
<p style="TEXT-INDENT: 0px; MARGIN: 5px auto">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;}</p>
<p style="TEXT-INDENT: 0px; MARGIN: 5px auto">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;if(IsN) num=-num;</p>
<p style="TEXT-INDENT: 0px; MARGIN: 5px auto">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;return true;</p>
<p style="TEXT-INDENT: 0px; MARGIN: 5px auto">}</p>
<p style="TEXT-INDENT: 0px; MARGIN: 5px auto">struct Plank {</p>
<p style="TEXT-INDENT: 0px; MARGIN: 5px auto">&nbsp;&nbsp; &nbsp; &nbsp; int x,y,h,v,left,right;&nbsp;</p>
<p style="TEXT-INDENT: 0px; MARGIN: 5px auto">&nbsp;&nbsp; &nbsp; &nbsp; //按高排序 &nbsp; &nbsp; &nbsp;&nbsp;</p>
<p style="TEXT-INDENT: 0px; MARGIN: 5px auto">&nbsp;&nbsp; &nbsp; &nbsp; friend bool operator &lt; ( const Plank &amp;a, const Plank &amp;b ) {</p>
<p style="TEXT-INDENT: 0px; MARGIN: 5px auto">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;return a.h &lt; b.h;</p>
<p style="TEXT-INDENT: 0px; MARGIN: 5px auto">&nbsp;&nbsp; &nbsp; &nbsp; }</p>
<p style="TEXT-INDENT: 0px; MARGIN: 5px auto">}pk[100010];</p>
<p style="TEXT-INDENT: 0px; MARGIN: 5px auto">int dp[100010];</p>
<p style="TEXT-INDENT: 0px; MARGIN: 5px auto">int main ()</p>
<p style="TEXT-INDENT: 0px; MARGIN: 5px auto">{</p>
<p style="TEXT-INDENT: 0px; MARGIN: 5px auto">&nbsp;&nbsp; &nbsp;int N, M;</p>
<p style="TEXT-INDENT: 0px; MARGIN: 5px auto">&nbsp;&nbsp; &nbsp;creat ( 1, 100000 );</p>
<p style="TEXT-INDENT: 0px; MARGIN: 5px auto">&nbsp;&nbsp; &nbsp;while ( scan_d ( N ) ) {</p>
<p style="TEXT-INDENT: 0px; MARGIN: 5px auto">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; M = -1;</p>
<p style="TEXT-INDENT: 0px; MARGIN: 5px auto">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; for ( int i = 1; i &lt;= N; ++ i ) {</p>
<p style="TEXT-INDENT: 0px; MARGIN: 5px auto">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;scan_d ( pk[i].h );scan_d ( pk[i].x );scan_d ( pk[i].y );scan_d ( pk[i].v );</p>
<p style="TEXT-INDENT: 0px; MARGIN: 5px auto">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if ( pk[i].y &gt; M ) M = pk[i].y; &nbsp; &nbsp; &nbsp; // 记录 区间最大值, 加速用的&nbsp;</p>
<p style="TEXT-INDENT: 0px; MARGIN: 5px auto">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }</p>
<p style="TEXT-INDENT: 0px; MARGIN: 5px auto">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; modify &nbsp;( 1, M, 0 );</p>
<p style="TEXT-INDENT: 0px; MARGIN: 5px auto">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; sort ( pk + 1, pk + N + 1 ); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // 按高排序&nbsp;</p>
<p style="TEXT-INDENT: 0px; MARGIN: 5px auto">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; memset ( dp, 0, sizeof ( dp ) );</p>
<p style="TEXT-INDENT: 0px; MARGIN: 5px auto">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; dp[N] = 100 + pk[N].v;</p>
<p style="TEXT-INDENT: 0px; MARGIN: 5px auto">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // 自底向上 更新 线段, 记录 每条线段 左右端点能到达的 线段 ID&nbsp;</p>
<p style="TEXT-INDENT: 0px; MARGIN: 5px auto">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; for ( int i = 1; i &lt;= N; ++ i ) { &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</p>
<p style="TEXT-INDENT: 0px; MARGIN: 5px auto">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;int x = pk[i].left = query ( pk[i].x );</p>
<p style="TEXT-INDENT: 0px; MARGIN: 5px auto">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;int y = pk[i].right = query ( pk[i].y );</p>
<p style="TEXT-INDENT: 0px; MARGIN: 5px auto">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;modify ( pk[i].x, pk[i].y, i );</p>
<p style="TEXT-INDENT: 0px; MARGIN: 5px auto">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }</p>
<p style="TEXT-INDENT: 0px; MARGIN: 5px auto">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; int res = -1;</p>
<p style="TEXT-INDENT: 0px; MARGIN: 5px auto">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //自顶向下 DP &nbsp; &nbsp;dp[i] = max ( dp[i], dp[i^].v ) &nbsp;</p>
<p style="TEXT-INDENT: 0px; MARGIN: 5px auto">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // dp[i^] 代表能走到 i 的线段&nbsp;</p>
<p style="TEXT-INDENT: 0px; MARGIN: 5px auto">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; for ( int i = N; i &gt;= 1; -- i ) { &nbsp;&nbsp;</p>
<p style="TEXT-INDENT: 0px; MARGIN: 5px auto">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if ( dp[ pk[i].left ] &lt; dp[i] + pk[ pk[i].left ].v )</p>
<p style="TEXT-INDENT: 0px; MARGIN: 5px auto">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;dp[ pk[i].left ] = dp[i] + pk[ pk[i].left ].v;</p>
<p style="TEXT-INDENT: 0px; MARGIN: 5px auto">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if ( dp[ pk[i].right ] &lt; dp[i] + pk[ pk[i].right ].v )</p>
<p style="TEXT-INDENT: 0px; MARGIN: 5px auto">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;dp[ pk[i].right ] = dp[i] + pk[ pk[i].right ].v;&nbsp;</p>
<p style="TEXT-INDENT: 0px; MARGIN: 5px auto">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }&nbsp;</p>
<p style="TEXT-INDENT: 0px; MARGIN: 5px auto">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; printf ( "%d\n",dp[0] &gt; 0 ? dp[0] : -1 );</p>
<p style="TEXT-INDENT: 0px; MARGIN: 5px auto">&nbsp;&nbsp; &nbsp;}</p>
<p style="TEXT-INDENT: 0px; MARGIN: 5px auto">&nbsp;&nbsp; &nbsp;return 0;</p>
<p style="TEXT-INDENT: 0px; MARGIN: 5px auto">}</p>
<div><br></div>
<p style="TEXT-INDENT: 0px; MARGIN: 5px auto">&nbsp;</p>
</span></font></div>
</div>
<p style="LINE-HEIGHT: 21px; TEXT-INDENT: 0px; MARGIN: 5px auto; FONT-FAMILY: verdana, 'courier new'; FONT-SIZE: 14px"></p>
<p style="LINE-HEIGHT: 21px; TEXT-INDENT: 0px; MARGIN: 5px auto; FONT-FAMILY: verdana, 'courier new'; FONT-SIZE: 14px">&nbsp;</p>
<img src ="http://www.cppblog.com/MiYu/aggbug/129775.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/MiYu/" target="_blank">MiYu</a> 2010-10-13 21:26 <a href="http://www.cppblog.com/MiYu/archive/2010/10/13/HDU-2871-HDOJ-2871-Memory-Control-ACM-2871-IN-HDU.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>HDU 2871 HDOJ 2871 Memory Control ACM 2871 IN HDU</title><link>http://www.cppblog.com/MiYu/archive/2010/10/07/128951.html</link><dc:creator>MiYu</dc:creator><author>MiYu</author><pubDate>Thu, 07 Oct 2010 13:49:00 GMT</pubDate><guid>http://www.cppblog.com/MiYu/archive/2010/10/07/128951.html</guid><wfw:comment>http://www.cppblog.com/MiYu/comments/128951.html</wfw:comment><comments>http://www.cppblog.com/MiYu/archive/2010/10/07/128951.html#Feedback</comments><slash:comments>1</slash:comments><wfw:commentRss>http://www.cppblog.com/MiYu/comments/commentRss/128951.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/MiYu/services/trackbacks/128951.html</trackback:ping><description><![CDATA[&nbsp;&nbsp;&nbsp;&nbsp; 摘要: MiYu原创, 转帖请注明 : 转载自&nbsp;______________白白の屋&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;题目地址:	http://acm.hdu.edu.cn/showproblem.php?pid=2871题目描述:Memory ControlTime Limit: 2000/1000 MS (Java/Others)&nbsp;&nbsp;&nbsp;...&nbsp;&nbsp;<a href='http://www.cppblog.com/MiYu/archive/2010/10/07/128951.html'>阅读全文</a><img src ="http://www.cppblog.com/MiYu/aggbug/128951.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/MiYu/" target="_blank">MiYu</a> 2010-10-07 21:49 <a href="http://www.cppblog.com/MiYu/archive/2010/10/07/128951.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>PKU 3667 HDOJ 3667 Hotel ACM 3667 IN HDU</title><link>http://www.cppblog.com/MiYu/archive/2010/10/07/128936.html</link><dc:creator>MiYu</dc:creator><author>MiYu</author><pubDate>Thu, 07 Oct 2010 09:36:00 GMT</pubDate><guid>http://www.cppblog.com/MiYu/archive/2010/10/07/128936.html</guid><wfw:comment>http://www.cppblog.com/MiYu/comments/128936.html</wfw:comment><comments>http://www.cppblog.com/MiYu/archive/2010/10/07/128936.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/MiYu/comments/commentRss/128936.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/MiYu/services/trackbacks/128936.html</trackback:ping><description><![CDATA[&nbsp;&nbsp;&nbsp;&nbsp; 摘要: MiYu原创, 转帖请注明 : 转载自&nbsp;______________白白の屋&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;题目地址 :	http://poj.org/problem?id=3667题目描述:HotelTime Limit:&nbsp;3000MSMemory Limit:&nbsp;65536KTotal Submissions:&nbsp;2993Acce...&nbsp;&nbsp;<a href='http://www.cppblog.com/MiYu/archive/2010/10/07/128936.html'>阅读全文</a><img src ="http://www.cppblog.com/MiYu/aggbug/128936.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/MiYu/" target="_blank">MiYu</a> 2010-10-07 17:36 <a href="http://www.cppblog.com/MiYu/archive/2010/10/07/128936.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>HDU 1540 HDOJ 1540 Tunnel Warfare ACM 1540 IN HDU</title><link>http://www.cppblog.com/MiYu/archive/2010/10/06/128767.html</link><dc:creator>MiYu</dc:creator><author>MiYu</author><pubDate>Wed, 06 Oct 2010 03:06:00 GMT</pubDate><guid>http://www.cppblog.com/MiYu/archive/2010/10/06/128767.html</guid><wfw:comment>http://www.cppblog.com/MiYu/comments/128767.html</wfw:comment><comments>http://www.cppblog.com/MiYu/archive/2010/10/06/128767.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/MiYu/comments/commentRss/128767.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/MiYu/services/trackbacks/128767.html</trackback:ping><description><![CDATA[&nbsp;&nbsp;&nbsp;&nbsp; 摘要: MiYu原创, 转帖请注明 : 转载自&nbsp;______________白白の屋&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;题目地址:	http://acm.hdu.edu.cn/showproblem.php?pid=1540题目描述:Tunnel WarfareTime Limit: 4000/2000 MS (Java/Others)&nbsp;&nbsp;&nbsp;...&nbsp;&nbsp;<a href='http://www.cppblog.com/MiYu/archive/2010/10/06/128767.html'>阅读全文</a><img src ="http://www.cppblog.com/MiYu/aggbug/128767.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/MiYu/" target="_blank">MiYu</a> 2010-10-06 11:06 <a href="http://www.cppblog.com/MiYu/archive/2010/10/06/128767.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>线段树的一种简化实现[转] by 踏雪赤兔 </title><link>http://www.cppblog.com/MiYu/archive/2010/10/04/128568.html</link><dc:creator>MiYu</dc:creator><author>MiYu</author><pubDate>Mon, 04 Oct 2010 08:11:00 GMT</pubDate><guid>http://www.cppblog.com/MiYu/archive/2010/10/04/128568.html</guid><wfw:comment>http://www.cppblog.com/MiYu/comments/128568.html</wfw:comment><comments>http://www.cppblog.com/MiYu/archive/2010/10/04/128568.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/MiYu/comments/commentRss/128568.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/MiYu/services/trackbacks/128568.html</trackback:ping><description><![CDATA[



<div><br></div><div><p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; font-family: verdana, 'courier new'; font-size: 14px; line-height: 21px; ">&nbsp;转载自&nbsp;<a href="http://www.cnitblog.com/cockerel/archive/2006/09/13/16806.html">http://www.cnitblog.com/cockerel/archive/2006/09/13/16806.html</a></p><p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; font-family: verdana, Arial, helvetica, sans-seriff; line-height: 19px; font-size: 12px; color: rgb(75, 75, 75); ">相信对算法设计或者数据结构有一定了解的人对线段树都不会太陌生。它是能够在log(MaxLen)时间内完成线段的添加、删除、查询等操作。但一般的实现都有点复杂（我自写的是要递归的，比较多行）。而线段树应用中有一种是专门针对点的。（点树？）它的实现却非常简单。<br>　　这种数据结构有什么用？我们先来考虑一下下面的需求（全部要求在LogN时间内完成）：如何知道一个点在一个点集里的大小&#8220;排名&#8221;？很简单，开一个点数组，排个序，再二分查找就行了；如何在一个点集内动态增删点？也很简单，弄个平衡树就行了（本来平衡树比线段树复杂得多，但自从世界上有了STL set这么个好东东，就&#8230;&#8230;^_^）那如果我既要动态增删点，也要随时查询到一个点的排名呢？那对不起，可能就要出动到我们的&#8220;点树&#8221;了。<br>　　其实现原理很简单：每当增加（或删除）一个大小为X的点时，就在树上添加（或删除）一条(X,MaxLen)的线段（不含端点），当要查询一个点的排名时，只要看看其上有多少条线段就可以了。针对这一需求，这里有个非常简单的实现（见以下代码，十多行，够短了吧？）其中clear()用于清空点集；add()用于添加一个点；cntLs()返回小于n的点的个数，也就是n的升序排名，类似地cntGt是降序排名。<br>　　这个点树有什么用呢？其中一个应用时在O(NlogN)时间内求出一个排列的逆序数（<a href="http://acm.zju.edu.cn/show_problem.php?pid=1484" style="color: rgb(0, 0, 0); ">http://acm.zju.edu.cn/show_problem.php?pid=1484</a>，你有更好的算法吗？欢迎交流）方法是每读到一个数x，就让逆序数+=cntGt(x);然后再add(x)。<br>　　这个实现还可以进行一些扩展。比如删除del(int n)，只要把add(int n)中的++size换成--size，把a[i/2]++改成a[i/2]--即可。另外还可以通过二分查找功能在O(logN)时间内查到排名第n的点的大小。应该也可以三四行内搞定。</p><div style="padding-right: 5px; padding-left: 4px; font-size: 13px; padding-bottom: 4px; border-left-color: rgb(204, 204, 204); width: 566px; word-break: break-all; padding-top: 4px; background-color: rgb(238, 238, 238); font-family: verdana, Arial, helvetica, sans-seriff; line-height: 19px; color: rgb(75, 75, 75); "><img src="http://www.cnitblog.com/Images/OutliningIndicators/None.gif" align="top">&nbsp;<span style="color: rgb(0, 0, 0); ">template</span>&nbsp;<span style="color: rgb(0, 0, 0); ">&lt;</span>&nbsp;<span style="color: rgb(0, 0, 255); ">int</span>&nbsp;<span style="color: rgb(0, 0, 0); ">&nbsp;N</span>&nbsp;<span style="color: rgb(0, 0, 0); ">&gt;</span>&nbsp;<span style="color: rgb(0, 128, 0); ">//</span>&nbsp;<span style="color: rgb(0, 128, 0); ">表示可用区间为[0,N)，其中N必须是2的幂数;&nbsp;</span>&nbsp;<span style="color: rgb(0, 128, 0); "><br><img id="Codehighlighter1_48_453_Open_Image" src="http://www.cnitblog.com/Images/OutliningIndicators/ExpandedBlockStart.gif" align="top">&nbsp;</span><span style="color: rgb(0, 0, 255); ">class</span>&nbsp;<span style="color: rgb(0, 0, 0); ">&nbsp;PointTree</span>&nbsp;<span id="Codehighlighter1_48_453_Open_Text"><span style="color: rgb(0, 0, 0); ">{<br><img src="http://www.cnitblog.com/Images/OutliningIndicators/InBlock.gif" align="top">&nbsp;&nbsp;&nbsp;&nbsp;</span>&nbsp;<span style="color: rgb(0, 0, 255); ">int</span>&nbsp;<span style="color: rgb(0, 0, 0); ">&nbsp;a[</span>&nbsp;<span style="color: rgb(0, 0, 0); ">2</span>&nbsp;<span style="color: rgb(0, 0, 0); ">*</span>&nbsp;<span style="color: rgb(0, 0, 0); ">N];<br><img src="http://www.cnitblog.com/Images/OutliningIndicators/InBlock.gif" align="top">&nbsp;&nbsp;&nbsp;&nbsp;</span>&nbsp;<span style="color: rgb(0, 0, 255); ">int</span>&nbsp;<span style="color: rgb(0, 0, 0); ">&nbsp;size;&nbsp;<br><img id="Codehighlighter1_97_128_Open_Image" src="http://www.cnitblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top">&nbsp;&nbsp;&nbsp;&nbsp;</span>&nbsp;<span style="color: rgb(0, 0, 255); ">void</span>&nbsp;<span style="color: rgb(0, 0, 0); ">&nbsp;clear()</span>&nbsp;<span id="Codehighlighter1_97_128_Open_Text"><span style="color: rgb(0, 0, 0); ">{&nbsp;memset(</span>&nbsp;<span style="color: rgb(0, 0, 255); ">this</span>&nbsp;<span style="color: rgb(0, 0, 0); ">,</span>&nbsp;<span style="color: rgb(0, 0, 0); ">0</span>&nbsp;<span style="color: rgb(0, 0, 0); ">,</span>&nbsp;<span style="color: rgb(0, 0, 255); ">sizeof</span>&nbsp;<span style="color: rgb(0, 0, 0); ">(</span>&nbsp;<span style="color: rgb(0, 0, 0); ">*</span>&nbsp;<span style="color: rgb(0, 0, 255); ">this</span>&nbsp;<span style="color: rgb(0, 0, 0); ">));}</span>&nbsp;</span><span style="color: rgb(0, 0, 0); ">&nbsp;<br><img id="Codehighlighter1_150_246_Open_Image" src="http://www.cnitblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top">&nbsp;&nbsp;&nbsp;&nbsp;</span>&nbsp;<span style="color: rgb(0, 0, 255); ">void</span>&nbsp;<span style="color: rgb(0, 0, 0); ">&nbsp;add(</span>&nbsp;<span style="color: rgb(0, 0, 255); ">int</span>&nbsp;<span style="color: rgb(0, 0, 0); ">&nbsp;n)</span>&nbsp;<span id="Codehighlighter1_150_246_Open_Text"><span style="color: rgb(0, 0, 0); ">{<br><img src="http://www.cnitblog.com/Images/OutliningIndicators/InBlock.gif" align="top">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span>&nbsp;<span style="color: rgb(0, 0, 255); ">int</span>&nbsp;<span style="color: rgb(0, 0, 0); ">&nbsp;i</span>&nbsp;<span style="color: rgb(0, 0, 0); ">=</span>&nbsp;<span style="color: rgb(0, 0, 0); ">N</span>&nbsp;<span style="color: rgb(0, 0, 0); ">+</span>&nbsp;<span style="color: rgb(0, 0, 0); ">n;&nbsp;</span>&nbsp;<span style="color: rgb(0, 0, 0); ">++</span>&nbsp;<span style="color: rgb(0, 0, 0); ">size;&nbsp;<br><img src="http://www.cnitblog.com/Images/OutliningIndicators/InBlock.gif" align="top">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span>&nbsp;<span style="color: rgb(0, 0, 255); ">for</span>&nbsp;<span style="color: rgb(0, 0, 0); ">(</span>&nbsp;<span style="color: rgb(0, 0, 0); ">++</span>&nbsp;<span style="color: rgb(0, 0, 0); ">a[i];&nbsp;i</span>&nbsp;<span style="color: rgb(0, 0, 0); ">&gt;</span>&nbsp;<span style="color: rgb(0, 0, 0); ">1</span>&nbsp;<span style="color: rgb(0, 0, 0); ">;&nbsp;i</span>&nbsp;<span style="color: rgb(0, 0, 0); ">/=</span>&nbsp;<span style="color: rgb(0, 0, 0); ">2</span>&nbsp;<span style="color: rgb(0, 0, 0); ">)<br><img src="http://www.cnitblog.com/Images/OutliningIndicators/InBlock.gif" align="top">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span>&nbsp;<span style="color: rgb(0, 0, 255); ">if</span>&nbsp;<span style="color: rgb(0, 0, 0); ">(</span>&nbsp;<span style="color: rgb(0, 0, 0); ">~</span>&nbsp;<span style="color: rgb(0, 0, 0); ">i</span>&nbsp;<span style="color: rgb(0, 0, 0); ">&amp;</span>&nbsp;<span style="color: rgb(0, 0, 0); ">1</span>&nbsp;<span style="color: rgb(0, 0, 0); ">)&nbsp;a[i</span>&nbsp;<span style="color: rgb(0, 0, 0); ">/</span>&nbsp;<span style="color: rgb(0, 0, 0); ">2</span>&nbsp;<span style="color: rgb(0, 0, 0); ">]</span>&nbsp;<span style="color: rgb(0, 0, 0); ">++</span>&nbsp;<span style="color: rgb(0, 0, 0); ">;<br><img src="http://www.cnitblog.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top">&nbsp;&nbsp;&nbsp;&nbsp;}</span>&nbsp;</span><span style="color: rgb(0, 0, 0); ">&nbsp;<br><img id="Codehighlighter1_269_397_Open_Image" src="http://www.cnitblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top">&nbsp;&nbsp;&nbsp;&nbsp;</span>&nbsp;<span style="color: rgb(0, 0, 255); ">int</span>&nbsp;<span style="color: rgb(0, 0, 0); ">&nbsp;cntLs(</span>&nbsp;<span style="color: rgb(0, 0, 255); ">int</span>&nbsp;<span style="color: rgb(0, 0, 0); ">&nbsp;n)</span>&nbsp;<span id="Codehighlighter1_269_397_Open_Text"><span style="color: rgb(0, 0, 0); ">{</span>&nbsp;<span style="color: rgb(0, 128, 0); ">//</span>&nbsp;<span style="color: rgb(0, 128, 0); ">统计小于&nbsp;</span>&nbsp;<span style="color: rgb(0, 128, 0); "><br><img src="http://www.cnitblog.com/Images/OutliningIndicators/InBlock.gif" align="top">&nbsp;</span><span style="color: rgb(0, 0, 0); ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span>&nbsp;<span style="color: rgb(0, 0, 255); ">int</span>&nbsp;<span style="color: rgb(0, 0, 0); ">&nbsp;i</span>&nbsp;<span style="color: rgb(0, 0, 0); ">=</span>&nbsp;<span style="color: rgb(0, 0, 0); ">N</span>&nbsp;<span style="color: rgb(0, 0, 0); ">+</span>&nbsp;<span style="color: rgb(0, 0, 0); ">n,c</span>&nbsp;<span style="color: rgb(0, 0, 0); ">=</span>&nbsp;<span style="color: rgb(0, 0, 0); ">0</span>&nbsp;<span style="color: rgb(0, 0, 0); ">;&nbsp;</span>&nbsp;<span style="color: rgb(0, 128, 0); ">//</span>&nbsp;<span style="color: rgb(0, 128, 0); ">若统计小于等于则c=a[i];&nbsp;</span>&nbsp;<span style="color: rgb(0, 128, 0); "><br><img src="http://www.cnitblog.com/Images/OutliningIndicators/InBlock.gif" align="top">&nbsp;</span><span style="color: rgb(0, 0, 0); ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span>&nbsp;<span style="color: rgb(0, 0, 255); ">for</span>&nbsp;<span style="color: rgb(0, 0, 0); ">(;&nbsp;i</span>&nbsp;<span style="color: rgb(0, 0, 0); ">&gt;</span>&nbsp;<span style="color: rgb(0, 0, 0); ">1</span>&nbsp;<span style="color: rgb(0, 0, 0); ">;&nbsp;i</span>&nbsp;<span style="color: rgb(0, 0, 0); ">/=</span>&nbsp;<span style="color: rgb(0, 0, 0); ">2</span>&nbsp;<span style="color: rgb(0, 0, 0); ">)&nbsp;<br><img src="http://www.cnitblog.com/Images/OutliningIndicators/InBlock.gif" align="top">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span>&nbsp;<span style="color: rgb(0, 0, 255); ">if</span>&nbsp;<span style="color: rgb(0, 0, 0); ">(i</span>&nbsp;<span style="color: rgb(0, 0, 0); ">&amp;</span>&nbsp;<span style="color: rgb(0, 0, 0); ">1</span>&nbsp;<span style="color: rgb(0, 0, 0); ">)&nbsp;c</span>&nbsp;<span style="color: rgb(0, 0, 0); ">+=</span>&nbsp;<span style="color: rgb(0, 0, 0); ">a[i</span>&nbsp;<span style="color: rgb(0, 0, 0); ">/</span>&nbsp;<span style="color: rgb(0, 0, 0); ">2</span>&nbsp;<span style="color: rgb(0, 0, 0); ">];<br><img src="http://www.cnitblog.com/Images/OutliningIndicators/InBlock.gif" align="top">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span>&nbsp;<span style="color: rgb(0, 0, 255); ">return</span>&nbsp;<span style="color: rgb(0, 0, 0); ">&nbsp;c;<br><img src="http://www.cnitblog.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top">&nbsp;&nbsp;&nbsp;&nbsp;}</span>&nbsp;</span><span style="color: rgb(0, 0, 0); "><br><img id="Codehighlighter1_419_450_Open_Image" src="http://www.cnitblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span>&nbsp;<span style="color: rgb(0, 0, 255); ">int</span>&nbsp;<span style="color: rgb(0, 0, 0); ">&nbsp;cntGt(</span>&nbsp;<span style="color: rgb(0, 0, 255); ">int</span>&nbsp;<span style="color: rgb(0, 0, 0); ">&nbsp;n)</span>&nbsp;<span id="Codehighlighter1_419_450_Open_Text"><span style="color: rgb(0, 0, 0); ">{&nbsp;</span>&nbsp;<span style="color: rgb(0, 0, 255); ">return</span>&nbsp;<span style="color: rgb(0, 0, 0); ">&nbsp;size</span>&nbsp;<span style="color: rgb(0, 0, 0); ">-</span>&nbsp;<span style="color: rgb(0, 0, 0); ">a[N</span>&nbsp;<span style="color: rgb(0, 0, 0); ">+</span>&nbsp;<span style="color: rgb(0, 0, 0); ">n]</span>&nbsp;<span style="color: rgb(0, 0, 0); ">-</span>&nbsp;<span style="color: rgb(0, 0, 0); ">cntLs(n);&nbsp;}</span>&nbsp;</span><span style="color: rgb(0, 0, 0); ">&nbsp;<br><img src="http://www.cnitblog.com/Images/OutliningIndicators/ExpandedBlockEnd.gif" align="top">}</span>&nbsp;</span><span style="color: rgb(0, 0, 0); ">;&nbsp;</span></div><span style="font-family: verdana, 'courier new'; font-size: 14px; line-height: 21px; "><span style="font-family: verdana, Arial, helvetica, sans-seriff; line-height: 19px; font-size: 12px; color: rgb(75, 75, 75); "><br></span></span><span style="font-family: verdana, 'courier new'; font-size: 14px; line-height: 21px; "><span style="font-family: verdana, Arial, helvetica, sans-seriff; line-height: 19px; font-size: 12px; color: rgb(75, 75, 75); ">　　嗯~~~为了解</span></span><span style="font-family: verdana, 'courier new'; font-size: 14px; line-height: 21px; "><span style="font-family: verdana, Arial, helvetica, sans-seriff; line-height: 19px; font-size: 12px; color: rgb(75, 75, 75); "><a href="http://acm.zju.edu.cn/show_problem.php?pid=2425" style="color: rgb(0, 0, 0); ">http://acm.zju.edu.cn/show_problem.php?pid=2425</a></span></span><span style="font-family: verdana, 'courier new'; font-size: 14px; line-height: 21px; "><span style="font-family: verdana, Arial, helvetica, sans-seriff; line-height: 19px; font-size: 12px; color: rgb(75, 75, 75); ">这一题，还是把上述两个扩展给实现了啦，果然不难：</span></span><div style="padding-right: 5px; padding-left: 4px; font-size: 13px; padding-bottom: 4px; border-left-color: rgb(204, 204, 204); width: 566px; word-break: break-all; padding-top: 4px; background-color: rgb(238, 238, 238); font-family: verdana, Arial, helvetica, sans-seriff; line-height: 19px; color: rgb(75, 75, 75); "><img src="http://www.cnitblog.com/Images/OutliningIndicators/None.gif" align="top"><span style="color: rgb(0, 0, 0); ">（接上）<br><img id="Codehighlighter1_24_135_Open_Image" src="http://www.cnitblog.com/Images/OutliningIndicators/ExpandedBlockStart.gif" align="top">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(0, 0, 255); ">void</span><span style="color: rgb(0, 0, 0); ">&nbsp;del(</span><span style="color: rgb(0, 0, 255); ">int</span><span style="color: rgb(0, 0, 0); ">&nbsp;n)</span><span id="Codehighlighter1_24_135_Open_Text"><span style="color: rgb(0, 0, 0); ">{<br><img src="http://www.cnitblog.com/Images/OutliningIndicators/InBlock.gif" align="top">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(0, 0, 255); ">if</span><span style="color: rgb(0, 0, 0); ">(</span><span style="color: rgb(0, 0, 0); ">!</span><span style="color: rgb(0, 0, 0); ">a[n</span><span style="color: rgb(0, 0, 0); ">+=</span><span style="color: rgb(0, 0, 0); ">N])</span><span style="color: rgb(0, 0, 255); ">return</span><span style="color: rgb(0, 0, 0); ">;<br><img src="http://www.cnitblog.com/Images/OutliningIndicators/InBlock.gif" align="top">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(0, 0, 0); ">--</span><span style="color: rgb(0, 0, 0); ">size;<br><img src="http://www.cnitblog.com/Images/OutliningIndicators/InBlock.gif" align="top">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(0, 0, 255); ">for</span><span style="color: rgb(0, 0, 0); ">(</span><span style="color: rgb(0, 0, 0); ">--</span><span style="color: rgb(0, 0, 0); ">a[n];&nbsp;n</span><span style="color: rgb(0, 0, 0); ">&gt;</span><span style="color: rgb(0, 0, 0); ">1</span><span style="color: rgb(0, 0, 0); ">;&nbsp;n</span><span style="color: rgb(0, 0, 0); ">/=</span><span style="color: rgb(0, 0, 0); ">2</span><span style="color: rgb(0, 0, 0); ">)<br><img src="http://www.cnitblog.com/Images/OutliningIndicators/InBlock.gif" align="top">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(0, 0, 255); ">if</span><span style="color: rgb(0, 0, 0); ">(</span><span style="color: rgb(0, 0, 0); ">~</span><span style="color: rgb(0, 0, 0); ">n</span><span style="color: rgb(0, 0, 0); ">&amp;</span><span style="color: rgb(0, 0, 0); ">1</span><span style="color: rgb(0, 0, 0); ">)</span><span style="color: rgb(0, 0, 0); ">--</span><span style="color: rgb(0, 0, 0); ">a[n</span><span style="color: rgb(0, 0, 0); ">/</span><span style="color: rgb(0, 0, 0); ">2</span><span style="color: rgb(0, 0, 0); ">];<br><img src="http://www.cnitblog.com/Images/OutliningIndicators/ExpandedBlockEnd.gif" align="top">&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="color: rgb(0, 0, 0); "><br><img id="Codehighlighter1_141_197_Open_Image" src="http://www.cnitblog.com/Images/OutliningIndicators/ExpandedBlockStart.gif" align="top">&nbsp;&nbsp;&nbsp;&nbsp;</span><span id="Codehighlighter1_141_197_Open_Text"><span style="color: rgb(0, 128, 0); ">/*</span><span style="color: rgb(0, 128, 0); ">&nbsp;&nbsp;解决：求点集中第i小的数(由0数起)<br><img src="http://www.cnitblog.com/Images/OutliningIndicators/InBlock.gif" align="top">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;&nbsp;&nbsp;&nbsp;注意：如果i&gt;=size&nbsp;返回N-1&nbsp;<br><img src="http://www.cnitblog.com/Images/OutliningIndicators/ExpandedBlockEnd.gif" align="top">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(0, 128, 0); ">*/</span></span><span style="color: rgb(0, 0, 0); ">&nbsp;<br><img id="Codehighlighter1_225_366_Open_Image" src="http://www.cnitblog.com/Images/OutliningIndicators/ExpandedBlockStart.gif" align="top">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(0, 0, 255); ">int</span><span style="color: rgb(0, 0, 0); ">&nbsp;</span><span style="color: rgb(0, 0, 255); ">operator</span><span style="color: rgb(0, 0, 0); ">[](</span><span style="color: rgb(0, 0, 255); ">int</span><span style="color: rgb(0, 0, 0); ">&nbsp;n)</span><span id="Codehighlighter1_225_366_Open_Text"><span style="color: rgb(0, 0, 0); ">{<br><img src="http://www.cnitblog.com/Images/OutliningIndicators/InBlock.gif" align="top">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(0, 0, 255); ">int</span><span style="color: rgb(0, 0, 0); ">&nbsp;i</span><span style="color: rgb(0, 0, 0); ">=</span><span style="color: rgb(0, 0, 0); ">1</span><span style="color: rgb(0, 0, 0); ">;<br><img id="Codehighlighter1_262_336_Open_Image" src="http://www.cnitblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(0, 0, 255); ">while</span><span style="color: rgb(0, 0, 0); ">(i</span><span style="color: rgb(0, 0, 0); ">&lt;</span><span style="color: rgb(0, 0, 0); ">N)</span><span id="Codehighlighter1_262_336_Open_Text"><span style="color: rgb(0, 0, 0); ">{<br><img src="http://www.cnitblog.com/Images/OutliningIndicators/InBlock.gif" align="top">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(0, 0, 255); ">if</span><span style="color: rgb(0, 0, 0); ">(n</span><span style="color: rgb(0, 0, 0); ">&lt;</span><span style="color: rgb(0, 0, 0); ">a[i])&nbsp;i</span><span style="color: rgb(0, 0, 0); ">*=</span><span style="color: rgb(0, 0, 0); ">2</span><span style="color: rgb(0, 0, 0); ">;<br><img src="http://www.cnitblog.com/Images/OutliningIndicators/InBlock.gif" align="top">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(0, 0, 255); ">else</span><span style="color: rgb(0, 0, 0); ">&nbsp;n</span><span style="color: rgb(0, 0, 0); ">-=</span><span style="color: rgb(0, 0, 0); ">a[i],&nbsp;i</span><span style="color: rgb(0, 0, 0); ">=</span><span style="color: rgb(0, 0, 0); ">i</span><span style="color: rgb(0, 0, 0); ">*</span><span style="color: rgb(0, 0, 0); ">2</span><span style="color: rgb(0, 0, 0); ">+</span><span style="color: rgb(0, 0, 0); ">1</span><span style="color: rgb(0, 0, 0); ">;<br><img src="http://www.cnitblog.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="color: rgb(0, 0, 0); "><br><img src="http://www.cnitblog.com/Images/OutliningIndicators/InBlock.gif" align="top">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(0, 0, 255); ">return</span><span style="color: rgb(0, 0, 0); ">&nbsp;i</span><span style="color: rgb(0, 0, 0); ">-</span><span style="color: rgb(0, 0, 0); ">N;&nbsp;&nbsp;&nbsp;&nbsp;<br><img src="http://www.cnitblog.com/Images/OutliningIndicators/ExpandedBlockEnd.gif" align="top">&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="color: rgb(0, 0, 0); ">&nbsp;&nbsp;&nbsp;&nbsp;<br><img src="http://www.cnitblog.com/Images/OutliningIndicators/None.gif" align="top">};&nbsp;&nbsp;<br><img src="http://www.cnitblog.com/Images/OutliningIndicators/None.gif" align="top"></span><span style="color: rgb(0, 128, 0); ">//</span><span style="color: rgb(0, 128, 0); ">附一个测试程序</span><span style="color: rgb(0, 128, 0); "><br><img src="http://www.cnitblog.com/Images/OutliningIndicators/None.gif" align="top"></span><span style="color: rgb(0, 0, 0); ">#include</span><span style="color: rgb(0, 0, 0); ">&lt;</span><span style="color: rgb(0, 0, 0); ">iostream.h</span><span style="color: rgb(0, 0, 0); ">&gt;</span><span style="color: rgb(0, 0, 0); "><br><img src="http://www.cnitblog.com/Images/OutliningIndicators/None.gif" align="top">T</span><span style="color: rgb(0, 0, 0); ">&lt;</span><span style="color: rgb(0, 0, 0); ">8192</span><span style="color: rgb(0, 0, 0); ">&gt;</span><span style="color: rgb(0, 0, 0); ">&nbsp;t;&nbsp;&nbsp;<br><img id="Codehighlighter1_431_666_Open_Image" src="http://www.cnitblog.com/Images/OutliningIndicators/ExpandedBlockStart.gif" align="top"></span><span style="color: rgb(0, 0, 255); ">int</span><span style="color: rgb(0, 0, 0); ">&nbsp;main()</span><span id="Codehighlighter1_431_666_Open_Text"><span style="color: rgb(0, 0, 0); ">{<br><img src="http://www.cnitblog.com/Images/OutliningIndicators/InBlock.gif" align="top">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(0, 0, 255); ">char</span><span style="color: rgb(0, 0, 0); ">&nbsp;c;&nbsp;</span><span style="color: rgb(0, 0, 255); ">int</span><span style="color: rgb(0, 0, 0); ">&nbsp;n;<br><img id="Codehighlighter1_469_636_Open_Image" src="http://www.cnitblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(0, 0, 255); ">while</span><span style="color: rgb(0, 0, 0); ">(cin</span><span style="color: rgb(0, 0, 0); ">&gt;&gt;</span><span style="color: rgb(0, 0, 0); ">c)</span><span id="Codehighlighter1_469_636_Open_Text"><span style="color: rgb(0, 0, 0); ">{<br><img src="http://www.cnitblog.com/Images/OutliningIndicators/InBlock.gif" align="top">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(0, 0, 255); ">if</span><span style="color: rgb(0, 0, 0); ">(c</span><span style="color: rgb(0, 0, 0); ">==</span><span style="color: rgb(0, 0, 0); ">'</span><span style="color: rgb(0, 0, 0); ">c</span><span style="color: rgb(0, 0, 0); ">'</span><span style="color: rgb(0, 0, 0); ">)&nbsp;t.clear();<br><img id="Codehighlighter1_507_629_Open_Image" src="http://www.cnitblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(0, 0, 255); ">else</span><span id="Codehighlighter1_507_629_Open_Text"><span style="color: rgb(0, 0, 0); ">{<br><img src="http://www.cnitblog.com/Images/OutliningIndicators/InBlock.gif" align="top">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;cin</span><span style="color: rgb(0, 0, 0); ">&gt;&gt;</span><span style="color: rgb(0, 0, 0); ">n;<br><img src="http://www.cnitblog.com/Images/OutliningIndicators/InBlock.gif" align="top">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(0, 0, 255); ">if</span><span style="color: rgb(0, 0, 0); ">(c</span><span style="color: rgb(0, 0, 0); ">==</span><span style="color: rgb(0, 0, 0); ">'</span><span style="color: rgb(0, 0, 0); ">a</span><span style="color: rgb(0, 0, 0); ">'</span><span style="color: rgb(0, 0, 0); ">)&nbsp;t.add(n);<br><img src="http://www.cnitblog.com/Images/OutliningIndicators/InBlock.gif" align="top">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(0, 0, 255); ">if</span><span style="color: rgb(0, 0, 0); ">(c</span><span style="color: rgb(0, 0, 0); ">==</span><span style="color: rgb(0, 0, 0); ">'</span><span style="color: rgb(0, 0, 0); ">d</span><span style="color: rgb(0, 0, 0); ">'</span><span style="color: rgb(0, 0, 0); ">)&nbsp;t.del(n);<br><img src="http://www.cnitblog.com/Images/OutliningIndicators/InBlock.gif" align="top">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(0, 0, 255); ">if</span><span style="color: rgb(0, 0, 0); ">(c</span><span style="color: rgb(0, 0, 0); ">==</span><span style="color: rgb(0, 0, 0); ">'</span><span style="color: rgb(0, 0, 0); ">q</span><span style="color: rgb(0, 0, 0); ">'</span><span style="color: rgb(0, 0, 0); ">)&nbsp;cout</span><span style="color: rgb(0, 0, 0); ">&lt;&lt;</span><span style="color: rgb(0, 0, 0); ">t[n]</span><span style="color: rgb(0, 0, 0); ">&lt;&lt;</span><span style="color: rgb(0, 0, 0); ">endl;<br><img src="http://www.cnitblog.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="color: rgb(0, 0, 0); ">&nbsp;&nbsp;&nbsp;&nbsp;<br><img src="http://www.cnitblog.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top">&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="color: rgb(0, 0, 0); ">&nbsp;&nbsp;&nbsp;&nbsp;<br><img src="http://www.cnitblog.com/Images/OutliningIndicators/InBlock.gif" align="top">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br><img src="http://www.cnitblog.com/Images/OutliningIndicators/InBlock.gif" align="top">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(0, 0, 255); ">return</span><span style="color: rgb(0, 0, 0); ">&nbsp;</span><span style="color: rgb(0, 0, 0); ">0</span><span style="color: rgb(0, 0, 0); ">;<br><img src="http://www.cnitblog.com/Images/OutliningIndicators/ExpandedBlockEnd.gif" align="top">}</span></span><span style="color: rgb(0, 0, 0); ">&nbsp;&nbsp;</span></div><span style="font-family: verdana, 'courier new'; font-size: 14px; line-height: 21px; "><span style="font-family: verdana, Arial, helvetica, sans-seriff; line-height: 19px; font-size: 12px; color: rgb(75, 75, 75); "><div><span style="font-family: verdana, 'courier new'; font-size: 14px; line-height: 21px; "><span style="font-family: verdana, Arial, helvetica, sans-seriff; line-height: 19px; font-size: 12px; color: rgb(75, 75, 75); "><span  style="color: rgb(0, 0, 0); line-height: 24px; "><div>求点集里n的个数了!<div style="padding-right: 5px; padding-left: 4px; font-size: 13px; padding-bottom: 4px; border-left-color: rgb(204, 204, 204); width: 593px; word-break: break-all; padding-top: 4px; background-color: rgb(238, 238, 238); "><img id="Codehighlighter1_16_37_Open_Image" src="http://www.cnitblog.com/Images/OutliningIndicators/ExpandedBlockStart.gif" align="top"><span style="color: rgb(0, 0, 255); ">int</span><span style="color: rgb(0, 0, 0); ">&nbsp;cntEQ(</span><span style="color: rgb(0, 0, 255); ">int</span><span style="color: rgb(0, 0, 0); ">&nbsp;n)</span><span id="Codehighlighter1_16_37_Open_Text"><span style="color: rgb(0, 0, 0); ">{<br><img src="http://www.cnitblog.com/Images/OutliningIndicators/InBlock.gif" align="top">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(0, 0, 255); ">return</span><span style="color: rgb(0, 0, 0); ">&nbsp;a[N</span><span style="color: rgb(0, 0, 0); ">+</span><span style="color: rgb(0, 0, 0); ">n];<br><img src="http://www.cnitblog.com/Images/OutliningIndicators/ExpandedBlockEnd.gif" align="top">}</span></span></div></div></span></span></span></div><br></span></span><span style="font-family: verdana, 'courier new'; font-size: 14px; line-height: 21px; "><span style="font-family: verdana, Arial, helvetica, sans-seriff; line-height: 19px; font-size: 12px; color: rgb(75, 75, 75); ">P.S.：</span></span><span style="font-family: verdana, 'courier new'; font-size: 14px; line-height: 21px; "><span style="font-family: verdana, Arial, helvetica, sans-seriff; line-height: 19px; font-size: 12px; color: rgb(75, 75, 75); "><br></span></span><span style="font-family: verdana, 'courier new'; font-size: 14px; line-height: 21px; "><span style="font-family: verdana, Arial, helvetica, sans-seriff; line-height: 19px; font-size: 12px; color: rgb(75, 75, 75); ">　　在写完这篇文章一段时间后，我认识了另一种功能上比较类似的数据结构，叫做&#8220;树状数组&#8221;。它们有不少相似之处：</span></span><ul style="list-style-type: none; list-style-position: initial; list-style-image: initial; margin-top: 0px; margin-right: 0px; margin-bottom: 10px; margin-left: 5px; padding-left: 5px; font-size: 13px; text-align: left; font-family: verdana, Arial, helvetica, sans-seriff; line-height: 19px; color: rgb(75, 75, 75); "><li>针对点集的处理（添加、删除、查找）；</li><li>相似的时空复杂度（logN时间，2N空间）；</li><li>相似的编程复杂度（都比线段树简短得多）；</li></ul><p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; font-family: verdana, Arial, helvetica, sans-seriff; line-height: 19px; font-size: 12px; color: rgb(75, 75, 75); ">因此，所有可以用树状数组解决的问题都可以用这个&#8220;点树&#8221;来解决，另外它还有以下好处：</p><ul style="list-style-type: none; list-style-position: initial; list-style-image: initial; margin-top: 0px; margin-right: 0px; margin-bottom: 10px; margin-left: 5px; padding-left: 5px; font-size: 13px; text-align: left; font-family: verdana, Arial, helvetica, sans-seriff; line-height: 19px; color: rgb(75, 75, 75); "><li>更直观的转移（个人感受，不一定要同意）；</li><li>同时支持自下而上和自上而下两种方向的查找和更新，而后者树状数组不支持，所以树状数组不提供某些功能，比如说O(logN)求点集中第k小数。</li></ul><p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; font-family: verdana, 'courier new'; font-size: 14px; line-height: 21px; "><span style="font-family: verdana, Arial, helvetica, sans-seriff; line-height: 19px; font-size: 12px; color: rgb(48, 48, 48); ">posted on 2006-09-13 19:54&nbsp;<a href="http://www.cnitblog.com/cockerel/" style="color: rgb(0, 0, 0); ">踏雪赤兔</a></span>&nbsp;</p></div><img src ="http://www.cppblog.com/MiYu/aggbug/128568.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/MiYu/" target="_blank">MiYu</a> 2010-10-04 16:11 <a href="http://www.cppblog.com/MiYu/archive/2010/10/04/128568.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>HDU 2795 HDOJ 2795 Billboard ACM 2795 IN HDU</title><link>http://www.cppblog.com/MiYu/archive/2010/09/26/127809.html</link><dc:creator>MiYu</dc:creator><author>MiYu</author><pubDate>Sun, 26 Sep 2010 14:15:00 GMT</pubDate><guid>http://www.cppblog.com/MiYu/archive/2010/09/26/127809.html</guid><wfw:comment>http://www.cppblog.com/MiYu/comments/127809.html</wfw:comment><comments>http://www.cppblog.com/MiYu/archive/2010/09/26/127809.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/MiYu/comments/commentRss/127809.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/MiYu/services/trackbacks/127809.html</trackback:ping><description><![CDATA[
<p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; font-family: verdana, 'courier new'; font-size: 14px; line-height: 21px; "><br><p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; ">MiYu原创, 转帖请注明 : 转载自&nbsp;<a href="http://www.cnblogs.com/MiYu"><font  color="#000000">______________白白の屋</font></a>&nbsp;&nbsp;<img src="http://www.cnblogs.com/Emoticons/baimantou/223332482.gif" alt="">&nbsp;&nbsp;</p><p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; ">&nbsp;</p><p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; ">题目地址:</p><p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; "><span class="Apple-tab-span" style="white-space: pre; ">	</span>&nbsp;<a href="http://acm.hdu.edu.cn/showproblem.php?pid=2795">http://acm.hdu.edu.cn/showproblem.php?pid=2795</a></p><p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; ">题目描述:<br></p><div class="cnblogs_code" style="background-color: rgb(245, 245, 245); font-family: 'Courier New'; font-size: 13px; border-left-color: rgb(204, 204, 204); padding-top: 5px; padding-right: 5px; padding-bottom: 5px; padding-left: 5px; word-break: break-all; overflow-x: auto; overflow-y: auto; "><div><font  color="#800080"><span  style="font-family: 'Times New Roman'; color: rgb(0, 0, 0); line-height: normal; font-size: medium; "><h1 style="color: rgb(26, 92, 200); text-align: center; ">Billboard</h1><font><strong><span style="font-family: Arial; font-size: 12px; font-weight: bold; color: green; ">Time Limit: 20000/8000 MS (Java/Others)&nbsp;&nbsp;&nbsp;&nbsp;Memory Limit: 32768/32768 K (Java/Others)<br>Total Submission(s): 733&nbsp;&nbsp;&nbsp;&nbsp;Accepted Submission(s): 340<br></span></strong></font><br><br><div class="panel_title" align="left" style="height: 38px; background-image: url(http://acm.hdu.edu.cn/images/panel-title.png); background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; padding-top: 0px; padding-right: 14px; padding-bottom: 0px; padding-left: 14px; color: rgb(124, 169, 237); font-size: 18px; font-family: Arial; font-weight: bold; background-position: 0% 100%; background-repeat: no-repeat no-repeat; ">Problem Description</div><div class="panel_content" style="height: auto; background-image: url(http://acm.hdu.edu.cn/images/panel-content.png); background-attachment: initial; background-origin: initial; background-clip: initial; background-color: initial; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 20px; padding-bottom: 0px; padding-left: 20px; font-size: 14px; font-family: 'Times New Roman'; text-align: left; background-repeat: no-repeat repeat; ">At the entrance to the university, there is a huge rectangular billboard of size h*w (h is its height and w is its width). The board is the place where all possible announcements are posted: nearest programming competitions, changes in the dining room menu, and other important information.<br><br>On September 1, the billboard was empty. One by one, the announcements started being put on the billboard.<br><br>Each announcement is a stripe of paper of unit height. More specifically, the i-th announcement is a rectangle of size 1 * wi.<br><br>When someone puts a new announcement on the billboard, she would always choose the topmost possible position for the announcement. Among all possible topmost positions she would always choose the leftmost one.<br><br>If there is no valid location for a new announcement, it is not put on the billboard (that's why some programming contests have no participants from this university).<br><br>Given the sizes of the billboard and the announcements, your task is to find the numbers of rows in which the announcements are placed.</div><div class="panel_bottom" style="height: auto; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; background-image: url(http://acm.hdu.edu.cn/images/panel-bottom.png); background-attachment: initial; background-origin: initial; background-clip: initial; background-color: initial; background-position: 0% 0%; background-repeat: no-repeat no-repeat; ">&nbsp;</div><br><div class="panel_title" align="left" style="height: 38px; background-image: url(http://acm.hdu.edu.cn/images/panel-title.png); background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; padding-top: 0px; padding-right: 14px; padding-bottom: 0px; padding-left: 14px; color: rgb(124, 169, 237); font-size: 18px; font-family: Arial; font-weight: bold; background-position: 0% 100%; background-repeat: no-repeat no-repeat; ">Input</div><div class="panel_content" style="height: auto; background-image: url(http://acm.hdu.edu.cn/images/panel-content.png); background-attachment: initial; background-origin: initial; background-clip: initial; background-color: initial; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 20px; padding-bottom: 0px; padding-left: 20px; font-size: 14px; font-family: 'Times New Roman'; text-align: left; background-repeat: no-repeat repeat; ">There are multiple cases (no more than 40 cases).<br><br>The first line of the input file contains three integer numbers, h, w, and n (1 &lt;= h,w &lt;= 10^9; 1 &lt;= n &lt;= 200,000) - the dimensions of the billboard and the number of announcements.<br><br>Each of the next n lines contains an integer number wi (1 &lt;= wi &lt;= 10^9) - the width of i-th announcement.</div><div class="panel_bottom" style="height: auto; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; background-image: url(http://acm.hdu.edu.cn/images/panel-bottom.png); background-attachment: initial; background-origin: initial; background-clip: initial; background-color: initial; background-position: 0% 0%; background-repeat: no-repeat no-repeat; ">&nbsp;</div><br><div class="panel_title" align="left" style="height: 38px; background-image: url(http://acm.hdu.edu.cn/images/panel-title.png); background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; padding-top: 0px; padding-right: 14px; padding-bottom: 0px; padding-left: 14px; color: rgb(124, 169, 237); font-size: 18px; font-family: Arial; font-weight: bold; background-position: 0% 100%; background-repeat: no-repeat no-repeat; ">Output</div><div class="panel_content" style="height: auto; background-image: url(http://acm.hdu.edu.cn/images/panel-content.png); background-attachment: initial; background-origin: initial; background-clip: initial; background-color: initial; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 20px; padding-bottom: 0px; padding-left: 20px; font-size: 14px; font-family: 'Times New Roman'; text-align: left; background-repeat: no-repeat repeat; ">For each announcement (in the order they are given in the input file) output one number - the number of the row in which this announcement is placed. Rows are numbered from 1 to h, starting with the top row. If an announcement can't be put on the billboard, output "-1" for this announcement.</div><div class="panel_bottom" style="height: auto; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; background-image: url(http://acm.hdu.edu.cn/images/panel-bottom.png); background-attachment: initial; background-origin: initial; background-clip: initial; background-color: initial; background-position: 0% 0%; background-repeat: no-repeat no-repeat; ">&nbsp;</div><br><div class="panel_title" align="left" style="height: 38px; background-image: url(http://acm.hdu.edu.cn/images/panel-title.png); background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; padding-top: 0px; padding-right: 14px; padding-bottom: 0px; padding-left: 14px; color: rgb(124, 169, 237); font-size: 18px; font-family: Arial; font-weight: bold; background-position: 0% 100%; background-repeat: no-repeat no-repeat; ">Sample Input</div><div class="panel_content" style="height: auto; background-image: url(http://acm.hdu.edu.cn/images/panel-content.png); background-attachment: initial; background-origin: initial; background-clip: initial; background-color: initial; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 20px; padding-bottom: 0px; padding-left: 20px; font-size: 14px; font-family: 'Times New Roman'; text-align: left; background-repeat: no-repeat repeat; "><pre style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font-size: 14px; "><div style="font-family: 'Courier New', Courier, monospace; ">3 5 5
2
4
3
3
3</div></pre></div><div class="panel_bottom" style="height: auto; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; background-image: url(http://acm.hdu.edu.cn/images/panel-bottom.png); background-attachment: initial; background-origin: initial; background-clip: initial; background-color: initial; background-position: 0% 0%; background-repeat: no-repeat no-repeat; ">&nbsp;</div><br><div class="panel_title" align="left" style="height: 38px; background-image: url(http://acm.hdu.edu.cn/images/panel-title.png); background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; padding-top: 0px; padding-right: 14px; padding-bottom: 0px; padding-left: 14px; color: rgb(124, 169, 237); font-size: 18px; font-family: Arial; font-weight: bold; background-position: 0% 100%; background-repeat: no-repeat no-repeat; ">Sample Output</div><div class="panel_content" style="height: auto; background-image: url(http://acm.hdu.edu.cn/images/panel-content.png); background-attachment: initial; background-origin: initial; background-clip: initial; background-color: initial; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 20px; padding-bottom: 0px; padding-left: 20px; font-size: 14px; font-family: 'Times New Roman'; text-align: left; background-repeat: no-repeat repeat; "><pre style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font-size: 14px; "><div style="font-family: 'Courier New', Courier, monospace; ">1
2
1
3
-1</div></pre></div><div class="panel_bottom" style="height: auto; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; background-image: url(http://acm.hdu.edu.cn/images/panel-bottom.png); background-attachment: initial; background-origin: initial; background-clip: initial; background-color: initial; background-position: 0% 0%; background-repeat: no-repeat no-repeat; ">&nbsp;</div><div><br></div><p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; ">&nbsp;</p><p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; ">一开始没想明白怎么做 , &nbsp;仔细想了想, &nbsp; 再次 读题后 发现 , n &lt;= 200000; &nbsp;也就是说 &nbsp;最多 也就 200000 条广告 , 你就算每行贴一张 ,</p><p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; ">最多也就贴到 200000 行, &nbsp;所以 &nbsp;不要被 &nbsp;h &lt;= 10^9 &nbsp;次方吓到了 &nbsp;,认为 线段树开不了那么大的数组 &nbsp;. 只要开 200000 就可以了 .</p><p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; ">&nbsp;</p><p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; ">其他的 没什么 好说的 , 知道这个 就直接 暴 吧 ............将近 7000MS .=水过.................&nbsp;<img src="http://www.cnblogs.com/Emoticons/baimantou/134950908.gif" alt="">&nbsp;&nbsp;g++提交 还华丽的 送出了 一次 TLE....<span class="Apple-tab-span" style="font-family: 'Courier New'; white-space: pre; ">	</span></p><p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; ">C++ &nbsp;水过了 ............</p><p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; ">&nbsp;</p><p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; "><span style="font-family: 'Courier New'; color: red; ">// &nbsp; &nbsp;一直没明白 为什么我的 代码速度 那么 慢, &nbsp;查询后 更新 的时间是 2000MS 左右 &nbsp;, 我的 是 查询 就更新了,</span></p><p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; "><span style="font-family: 'Courier New'; color: red; ">竟然要 将近 7000MS ? 非常 郁闷 , &nbsp;不信邪的 继续 检查 代码, 在 瞪了 1哥小时后 , 忽然想到 : 把 cout 改成</span></p><p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; "><span style="font-family: 'Courier New'; color: red; ">printf 会怎样? &nbsp; 结果 : &nbsp;1640 MS &nbsp;AC ..............鬼知道他的 数据量有多大..... cout 和 printf</span></p><p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; "><span style="font-family: 'Courier New'; color: red; ">竟然 差了 5000 MS 的时间 ...........无语</span></p><p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; ">代码如下 :</p><p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; ">&nbsp;</p><p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; ">&nbsp;/*</p><p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; ">Coded By &nbsp;: MiYu</p><p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; ">Link &nbsp; &nbsp; &nbsp;: http://www.cnblogs.com/MiYu &nbsp;|| http://www.cppblog.com/MiYu</p><p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; ">Author By : MiYu</p><p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; ">Test &nbsp; &nbsp; &nbsp;: 1</p><p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; ">Program &nbsp; : 2795</p><p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; ">*/</p><p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; ">//#pragma warning( disable:4789 )</p><p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; ">#include &lt;iostream&gt;</p><p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; ">#include &lt;algorithm&gt;</p><p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; ">#include &lt;string&gt;</p><p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; ">#include &lt;set&gt;</p><p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; ">#include &lt;map&gt;</p><p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; ">#include &lt;utility&gt;</p><p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; ">#include &lt;queue&gt;</p><p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; ">#include &lt;stack&gt;</p><p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; ">#include &lt;list&gt;</p><p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; ">#include &lt;vector&gt;</p><p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; ">#include &lt;cstdio&gt;</p><p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; ">#include &lt;cstdlib&gt;</p><p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; ">#include &lt;cstring&gt;</p><p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; ">#include &lt;cmath&gt;</p><p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; ">using namespace std;</p><p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; "><br></p><p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; ">struct ADV {</p><p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; ">&nbsp;&nbsp; &nbsp; &nbsp; int left, right, val;</p><p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; ">&nbsp;&nbsp; &nbsp; &nbsp; int mid () { return ( left + right ) &gt;&gt; 1; } &nbsp; &nbsp;&nbsp;</p><p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; ">}adv[800000];</p><p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; ">int N, W, H, w;</p><p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; ">void creat ( int l, int r, int rt = 1 ){</p><p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; ">&nbsp;&nbsp; &nbsp; adv[rt].left = l;</p><p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; ">&nbsp;&nbsp; &nbsp; adv[rt].right = r;</p><p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; ">&nbsp;&nbsp; &nbsp; adv[rt].val = W;</p><p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; ">&nbsp;&nbsp; &nbsp; if ( l == r )</p><p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; ">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;return ;</p><p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; ">&nbsp;&nbsp; &nbsp; int mid = adv[rt].mid();</p><p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; ">&nbsp;&nbsp; &nbsp; creat ( l, mid, rt &lt;&lt; 1 );</p><p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; ">&nbsp;&nbsp; &nbsp; creat ( mid + 1, r, ( rt &lt;&lt; 1 ) + 1 );</p><p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; ">}</p><p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; ">void add ( int rt = 1, int wei = w ){</p><p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; ">&nbsp;&nbsp; &nbsp;if ( wei &lt;= adv[rt].val ){</p><p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; ">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; if ( adv[rt].left == adv[rt].right ){</p><p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; ">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;adv[rt].val -= wei;</p><p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; ">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;<span style="font-family: 'Courier New'; color: red; ">&nbsp;//cout &lt;&lt; adv[rt].left &lt;&lt; endl; &nbsp;//杯具的 地方</span></p><p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; "><span class="Apple-tab-span" style="font-family: 'Courier New'; white-space: pre; ">	printf ( "%d\n", adv[rt].left );</span>&nbsp;</p><p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; ">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;return ; &nbsp; &nbsp;&nbsp;</p><p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; ">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; } else if ( adv[rt&lt;&lt;1].val &gt;= wei ) {</p><p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; ">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;add ( rt &lt;&lt; 1 );</p><p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; ">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;adv[rt].val = max ( adv[rt&lt;&lt;1].val, adv[(rt&lt;&lt;1)+1].val ); &nbsp; &nbsp;&nbsp;</p><p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; ">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; } else {</p><p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; ">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;add ( ( rt &lt;&lt; 1 ) + 1 );</p><p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; ">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;adv[rt].val = max ( adv[rt&lt;&lt;1].val, adv[(rt&lt;&lt;1)+1].val ); &nbsp; &nbsp; &nbsp; &nbsp;</p><p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; ">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; } &nbsp;&nbsp;</p><p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; ">&nbsp;&nbsp; &nbsp;} else {</p><p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; ">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //<span style="font-family: 'Courier New'; color: red; ">cout &lt;&lt; -1 &lt;&lt; endl;&nbsp;</span>&nbsp;&nbsp;&nbsp;<span style="font-family: 'Courier New'; color: red; ">&nbsp; //杯具的地方</span></p><p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; "><span class="Apple-tab-span" style="font-family: 'Courier New'; white-space: pre; ">	</span>puts ( "-1" ); &nbsp;&nbsp;</p><p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; ">&nbsp;&nbsp; &nbsp;} &nbsp;&nbsp;</p><p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; ">}</p><p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; ">inline bool scan_ud(int &amp;num)</p><p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; ">{</p><p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; ">&nbsp;&nbsp; &nbsp;char in;</p><p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; ">&nbsp;&nbsp; &nbsp;in=getchar();</p><p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; ">&nbsp;&nbsp; &nbsp;if(in==EOF) return false;</p><p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; ">&nbsp;&nbsp; &nbsp;while(in&lt;'0'||in&gt;'9') in=getchar();</p><p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; ">&nbsp;&nbsp; &nbsp;num=in-'0';</p><p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; ">&nbsp;&nbsp; &nbsp;while(in=getchar(),in&gt;='0'&amp;&amp;in&lt;='9'){</p><p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; ">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;num*=10,num+=in-'0';</p><p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; ">&nbsp;&nbsp; &nbsp;}</p><p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; ">&nbsp;&nbsp; &nbsp;return true;</p><p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; ">}</p><p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; ">int main ()</p><p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; ">{</p><p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; ">&nbsp;&nbsp; &nbsp;while ( scan_ud (H)&amp;&amp;scan_ud (W)&amp;&amp;scan_ud (N) ) {</p><p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; ">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if ( H &gt; 200000 )</p><p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; ">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; H = 200010;</p><p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; ">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; creat ( 1, H );</p><p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; ">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; for ( int i = 1; i &lt;= N; ++ i ) {</p><p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; ">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;scan_ud (w);</p><p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; ">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;add ( ); &nbsp; &nbsp;&nbsp;</p><p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; ">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; } &nbsp; &nbsp; &nbsp;</p><p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; ">&nbsp;&nbsp; &nbsp;}</p><p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; ">&nbsp;&nbsp; &nbsp;return 0;</p><p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; ">}</p><p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; ">&nbsp;</p><p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; ">&nbsp;</p><p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; ">&nbsp;</p><p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; ">&nbsp;</p><p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; ">另 附上 傻崽 &nbsp;神牛 代码 :</p><p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; ">&nbsp;</p><p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; ">#include &lt;iostream&gt;</p><p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; ">#include &lt;algorithm&gt;</p><p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; ">#include &lt;string&gt;</p><p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; ">#include &lt;set&gt;</p><p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; ">#include &lt;map&gt;</p><p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; ">#include &lt;utility&gt;</p><p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; ">#include &lt;queue&gt;</p><p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; ">#include &lt;stack&gt;</p><p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; ">#include &lt;list&gt;</p><p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; ">#include &lt;vector&gt;</p><p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; ">#include &lt;cstdio&gt;</p><p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; ">#include &lt;cstdlib&gt;</p><p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; ">#include &lt;cstring&gt;</p><p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; ">#include &lt;cmath&gt;</p><p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; ">#define FF(i,a)<span class="Apple-tab-span" style="font-family: 'Courier New'; white-space: pre; "><font  face="'Times New Roman'">				</font></span>for( int i = 0 ; i &lt; a ; i ++ )</p><p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; ">#define FOR(i,a,b)<span class="Apple-tab-span" style="font-family: 'Courier New'; white-space: pre; "><font  face="'Times New Roman'">			</font></span>for( int i = a ; i &lt; b ; i ++ )</p><p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; ">#define LL(a)<span class="Apple-tab-span" style="font-family: 'Courier New'; white-space: pre; "><font  face="'Times New Roman'">				</font></span>a&lt;&lt;1<span class="Apple-tab-span" style="font-family: 'Courier New'; white-space: pre; "><font  face="'Times New Roman'">		</font></span></p><p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; ">#define RR(a)<span class="Apple-tab-span" style="font-family: 'Courier New'; white-space: pre; "><font  face="'Times New Roman'">				</font></span>a&lt;&lt;1|1<span class="Apple-tab-span" style="font-family: 'Courier New'; white-space: pre; "><font  face="'Times New Roman'">		</font></span></p><p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; ">template&lt;class T&gt; inline void checkmin(T &amp;a,T b)<span class="Apple-tab-span" style="font-family: 'Courier New'; white-space: pre; "><font  face="'Times New Roman'">	</font></span>{if(a &lt; 0 || a &gt; b)a = b;}</p><p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; ">template&lt;class T&gt; inline void checkmax(T &amp;a,T b)<span class="Apple-tab-span" style="font-family: 'Courier New'; white-space: pre; "><font  face="'Times New Roman'">	</font></span>{if(a &lt; b)<span class="Apple-tab-span" style="font-family: 'Courier New'; white-space: pre; "><font  face="'Times New Roman'">	</font></span>a = b;}</p><p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; ">using namespace std;</p><p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; ">struct Node {</p><p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; "><span class="Apple-tab-span" style="font-family: 'Courier New'; white-space: pre; "><font  face="'Times New Roman'">	</font></span>int val;</p><p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; "><span class="Apple-tab-span" style="font-family: 'Courier New'; white-space: pre; "><font  face="'Times New Roman'">	</font></span>int idx;</p><p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; "><span class="Apple-tab-span" style="font-family: 'Courier New'; white-space: pre; "><font  face="'Times New Roman'">	</font></span>friend bool operator &lt; (Node a , Node b) {</p><p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; "><span class="Apple-tab-span" style="font-family: 'Courier New'; white-space: pre; "><font  face="'Times New Roman'">		</font></span>if(a.val == b.val) {</p><p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; "><span class="Apple-tab-span" style="font-family: 'Courier New'; white-space: pre; "><font  face="'Times New Roman'">			</font></span>return a.idx &gt; b.idx;</p><p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; "><span class="Apple-tab-span" style="font-family: 'Courier New'; white-space: pre; "><font  face="'Times New Roman'">		</font></span>}</p><p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; "><span class="Apple-tab-span" style="font-family: 'Courier New'; white-space: pre; "><font  face="'Times New Roman'">		</font></span>return a.val &lt; b.val;</p><p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; "><span class="Apple-tab-span" style="font-family: 'Courier New'; white-space: pre; "><font  face="'Times New Roman'">	</font></span>}</p><p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; ">}error;</p><p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; ">&nbsp;</p><p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; ">struct Seg_Tree{</p><p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; "><span class="Apple-tab-span" style="font-family: 'Courier New'; white-space: pre; "><font  face="'Times New Roman'">	</font></span>int left,right;</p><p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; "><span class="Apple-tab-span" style="font-family: 'Courier New'; white-space: pre; "><font  face="'Times New Roman'">	</font></span>Node node;</p><p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; "><span class="Apple-tab-span" style="font-family: 'Courier New'; white-space: pre; "><font  face="'Times New Roman'">	</font></span>int mid() {</p><p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; "><span class="Apple-tab-span" style="font-family: 'Courier New'; white-space: pre; "><font  face="'Times New Roman'">		</font></span>return (left + right)&gt;&gt;1;</p><p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; "><span class="Apple-tab-span" style="font-family: 'Courier New'; white-space: pre; "><font  face="'Times New Roman'">	</font></span>}</p><p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; ">}tt[800000];</p><p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; ">&nbsp;</p><p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; ">int n , h , m;</p><p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; ">&nbsp;</p><p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; ">void build(int l,int r,int idx) {</p><p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; "><span class="Apple-tab-span" style="font-family: 'Courier New'; white-space: pre; "><font  face="'Times New Roman'">	</font></span>tt[idx].left = l;</p><p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; "><span class="Apple-tab-span" style="font-family: 'Courier New'; white-space: pre; "><font  face="'Times New Roman'">	</font></span>tt[idx].right = r;</p><p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; "><span class="Apple-tab-span" style="font-family: 'Courier New'; white-space: pre; "><font  face="'Times New Roman'">	</font></span>tt[idx].node.idx = l;</p><p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; "><span class="Apple-tab-span" style="font-family: 'Courier New'; white-space: pre; "><font  face="'Times New Roman'">	</font></span>tt[idx].node.val = h;</p><p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; "><span class="Apple-tab-span" style="font-family: 'Courier New'; white-space: pre; "><font  face="'Times New Roman'">	</font></span>if(l == r) return ;</p><p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; "><span class="Apple-tab-span" style="font-family: 'Courier New'; white-space: pre; "><font  face="'Times New Roman'">	</font></span>int mid = tt[idx].mid();</p><p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; "><span class="Apple-tab-span" style="font-family: 'Courier New'; white-space: pre; "><font  face="'Times New Roman'">	</font></span>build(l,mid,LL(idx));</p><p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; "><span class="Apple-tab-span" style="font-family: 'Courier New'; white-space: pre; "><font  face="'Times New Roman'">	</font></span>build(mid+1,r,RR(idx));</p><p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; ">}</p><p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; ">&nbsp;</p><p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; ">void update(int l,int r,int val,int idx) {</p><p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; "><span class="Apple-tab-span" style="font-family: 'Courier New'; white-space: pre; "><font  face="'Times New Roman'">	</font></span>if(l &lt;= tt[idx].left &amp;&amp; r &gt;= tt[idx].right) {</p><p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; "><span class="Apple-tab-span" style="font-family: 'Courier New'; white-space: pre; "><font  face="'Times New Roman'">		</font></span>tt[idx].node.val += val;</p><p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; "><span class="Apple-tab-span" style="font-family: 'Courier New'; white-space: pre; "><font  face="'Times New Roman'">		</font></span>return ;</p><p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; "><span class="Apple-tab-span" style="font-family: 'Courier New'; white-space: pre; "><font  face="'Times New Roman'">	</font></span>}</p><p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; "><span class="Apple-tab-span" style="font-family: 'Courier New'; white-space: pre; "><font  face="'Times New Roman'">	</font></span>int mid = tt[idx].mid();</p><p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; "><span class="Apple-tab-span" style="font-family: 'Courier New'; white-space: pre; "><font  face="'Times New Roman'">	</font></span>if(l &lt;= mid) update(l,r,val,LL(idx));</p><p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; "><span class="Apple-tab-span" style="font-family: 'Courier New'; white-space: pre; "><font  face="'Times New Roman'">	</font></span>if(mid &lt; r)<span class="Apple-tab-span" style="font-family: 'Courier New'; white-space: pre; "><font  face="'Times New Roman'">	</font></span>update(l,r,val,RR(idx));</p><p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; "><span class="Apple-tab-span" style="font-family: 'Courier New'; white-space: pre; "><font  face="'Times New Roman'">	</font></span>tt[idx].node = max(tt[LL(idx)].node,tt[RR(idx)].node);</p><p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; ">}</p><p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; ">&nbsp;</p><p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; ">Node query(int w,int idx) {</p><p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; "><span class="Apple-tab-span" style="font-family: 'Courier New'; white-space: pre; "><font  face="'Times New Roman'">	</font></span>if(tt[idx].node.val &lt; w) {</p><p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; "><span class="Apple-tab-span" style="font-family: 'Courier New'; white-space: pre; "><font  face="'Times New Roman'">		</font></span>return error;</p><p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; "><span class="Apple-tab-span" style="font-family: 'Courier New'; white-space: pre; "><font  face="'Times New Roman'">	</font></span>}</p><p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; "><span class="Apple-tab-span" style="font-family: 'Courier New'; white-space: pre; "><font  face="'Times New Roman'">	</font></span>if(tt[idx].left == tt[idx].right) {</p><p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; "><span class="Apple-tab-span" style="font-family: 'Courier New'; white-space: pre; "><font  face="'Times New Roman'">		</font></span>return tt[idx].node;</p><p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; "><span class="Apple-tab-span" style="font-family: 'Courier New'; white-space: pre; "><font  face="'Times New Roman'">	</font></span>}</p><p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; "><span class="Apple-tab-span" style="font-family: 'Courier New'; white-space: pre; "><font  face="'Times New Roman'">	</font></span>if(tt[LL(idx)].node.val &gt;= w) {</p><p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; "><span class="Apple-tab-span" style="font-family: 'Courier New'; white-space: pre; "><font  face="'Times New Roman'">		</font></span>return query(w,LL(idx));</p><p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; "><span class="Apple-tab-span" style="font-family: 'Courier New'; white-space: pre; "><font  face="'Times New Roman'">	</font></span>} else {</p><p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; "><span class="Apple-tab-span" style="font-family: 'Courier New'; white-space: pre; "><font  face="'Times New Roman'">		</font></span>return query(w,RR(idx));</p><p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; "><span class="Apple-tab-span" style="font-family: 'Courier New'; white-space: pre; "><font  face="'Times New Roman'">	</font></span>}</p><p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; ">}</p><p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; ">&nbsp;</p><p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; ">int main() {</p><p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; "><span class="Apple-tab-span" style="font-family: 'Courier New'; white-space: pre; "><font  face="'Times New Roman'">	</font></span>error.idx = -1;</p><p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; "><span class="Apple-tab-span" style="font-family: 'Courier New'; white-space: pre; "><font  face="'Times New Roman'">	</font></span>while(scanf("%d%d%d",&amp;n,&amp;h,&amp;m) == 3) {</p><p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; "><span class="Apple-tab-span" style="font-family: 'Courier New'; white-space: pre; "><font  face="'Times New Roman'">		</font></span>checkmin(n,m);</p><p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; "><span class="Apple-tab-span" style="font-family: 'Courier New'; white-space: pre; "><font  face="'Times New Roman'">		</font></span>build(1,n,1);</p><p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; "><span class="Apple-tab-span" style="font-family: 'Courier New'; white-space: pre; "><font  face="'Times New Roman'">		</font></span>while(m --) {</p><p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; "><span class="Apple-tab-span" style="font-family: 'Courier New'; white-space: pre; "><font  face="'Times New Roman'">			</font></span>int w;</p><p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; "><span class="Apple-tab-span" style="font-family: 'Courier New'; white-space: pre; "><font  face="'Times New Roman'">			</font></span>scanf("%d",&amp;w);</p><p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; "><span class="Apple-tab-span" style="font-family: 'Courier New'; white-space: pre; "><font  face="'Times New Roman'">			</font></span>Node ret = query(w,1);</p><p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; "><span class="Apple-tab-span" style="font-family: 'Courier New'; white-space: pre; "><font  face="'Times New Roman'">			</font></span>printf("%d\n",ret.idx);</p><p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; "><span class="Apple-tab-span" style="font-family: 'Courier New'; white-space: pre; "><font  face="'Times New Roman'">			</font></span>if(ret.idx != -1) {</p><p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; "><span class="Apple-tab-span" style="font-family: 'Courier New'; white-space: pre; "><font  face="'Times New Roman'">				</font></span>update(ret.idx,ret.idx,-w,1);</p><p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; "><span class="Apple-tab-span" style="font-family: 'Courier New'; white-space: pre; "><font  face="'Times New Roman'">			</font></span>}</p><p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; "><span class="Apple-tab-span" style="font-family: 'Courier New'; white-space: pre; "><font  face="'Times New Roman'">		</font></span>}</p><p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; "><span class="Apple-tab-span" style="font-family: 'Courier New'; white-space: pre; "><font  face="'Times New Roman'">	</font></span>}</p><p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; "><span class="Apple-tab-span" style="font-family: 'Courier New'; white-space: pre; "><font  face="'Times New Roman'">	</font></span>return 0;</p><p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; ">}&nbsp;</p></span></font></div></div><p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; ">&nbsp;</p>&nbsp;</p><img src ="http://www.cppblog.com/MiYu/aggbug/127809.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/MiYu/" target="_blank">MiYu</a> 2010-09-26 22:15 <a href="http://www.cppblog.com/MiYu/archive/2010/09/26/127809.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>HDOJ 1698 HDU 1698 Just a Hook ACM 1698 IN HDU</title><link>http://www.cppblog.com/MiYu/archive/2010/09/17/126829.html</link><dc:creator>MiYu</dc:creator><author>MiYu</author><pubDate>Fri, 17 Sep 2010 02:09:00 GMT</pubDate><guid>http://www.cppblog.com/MiYu/archive/2010/09/17/126829.html</guid><wfw:comment>http://www.cppblog.com/MiYu/comments/126829.html</wfw:comment><comments>http://www.cppblog.com/MiYu/archive/2010/09/17/126829.html#Feedback</comments><slash:comments>4</slash:comments><wfw:commentRss>http://www.cppblog.com/MiYu/comments/commentRss/126829.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/MiYu/services/trackbacks/126829.html</trackback:ping><description><![CDATA[&nbsp;&nbsp;&nbsp;&nbsp; 摘要: MiYu原创, 转帖请注明 : 转载自&nbsp;______________白白の屋&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;题目地址 :&nbsp;&nbsp; &nbsp; &nbsp;http://acm.hdu.edu.cn/showproblem.php?pid=1698题目描述 :&nbsp;Just a HookTime Limit: 40...&nbsp;&nbsp;<a href='http://www.cppblog.com/MiYu/archive/2010/09/17/126829.html'>阅读全文</a><img src ="http://www.cppblog.com/MiYu/aggbug/126829.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/MiYu/" target="_blank">MiYu</a> 2010-09-17 10:09 <a href="http://www.cppblog.com/MiYu/archive/2010/09/17/126829.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>HDOJ 1754 HDU 1754 I Hate It ACM 1754 IN HDU</title><link>http://www.cppblog.com/MiYu/archive/2010/09/15/126668.html</link><dc:creator>MiYu</dc:creator><author>MiYu</author><pubDate>Wed, 15 Sep 2010 08:08:00 GMT</pubDate><guid>http://www.cppblog.com/MiYu/archive/2010/09/15/126668.html</guid><wfw:comment>http://www.cppblog.com/MiYu/comments/126668.html</wfw:comment><comments>http://www.cppblog.com/MiYu/archive/2010/09/15/126668.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/MiYu/comments/commentRss/126668.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/MiYu/services/trackbacks/126668.html</trackback:ping><description><![CDATA[<p><span style="font-family: Verdana,Geneva,Arial,Helvetica,sans-serif; line-height: normal; font-size: 13px;">MiYu原创, 转帖请注明 : 转载自&nbsp;<font color="#1d58d1"><a href="http://www.cnblogs.com/MiYu" style="text-decoration: none; color: rgb(29, 88, 209);">______________白白の屋</a>&nbsp;&nbsp;<img src="http://www.cnblogs.com/Emoticons/baimantou/223332482.gif" alt="">&nbsp;&nbsp;</font></span></p>
<p>&nbsp;</p><p>题目地址:</p><p>　　<a href="http://acm.hdu.edu.cn/showproblem.php?pid=1754">http://acm.hdu.edu.cn/showproblem.php?pid=1754</a></p><p>题目描述:</p><p>　　</p>
<div class="cnblogs_code"><div><span style="color: rgb(128, 0, 128);"><span style="border-collapse: separate; color: rgb(0, 0, 0); font-family: 'Times New Roman'; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; font-size: medium;"><h1>I Hate It</h1><strong><span style="font-family: Arial; font-size: 12px; font-weight: bold; color: green;">Time Limit: 9000/3000 MS (Java/Others)&nbsp;&nbsp;&nbsp;&nbsp;Memory Limit: 32768/32768 K (Java/Others)<br>Total Submission(s): 6306&nbsp;&nbsp;&nbsp;&nbsp;Accepted Submission(s): 2267<br></span></strong><br><br><div id="" style="height: 38px; background-image: url(&quot;http://acm.hdu.edu.cn/images/panel-title.png&quot;); background-color: transparent; padding: 0px 14px; color: rgb(124, 169, 237); font-size: 18px; font-family: Arial; font-weight: bold; background-position: 0% 100%;" align="left">Problem Description</div><div id="" style="height: auto; background-image: url(&quot;http://acm.hdu.edu.cn/images/panel-content.png&quot;); margin: 0px; padding: 0px 20px; font-size: 14px; font-family: 'Times New Roman';">很多学校流行一种比较的习惯。老师们很喜欢询问，从某某到某某当中，分数最高的是多少。<br>这让很多学生很反感。<br><br>不管你喜不喜欢，现在需要你做的是，就是按照老师的要求，写一个程序，模拟老师的询问。当然，老师有时候需要更新某位同学的成绩。</div><div style="height: auto; margin: 0px; background-image: url(&quot;http://acm.hdu.edu.cn/images/panel-bottom.png&quot;); background-position: 0% 0%;">&nbsp;</div><br><div style="height: 38px; background-image: url(&quot;http://acm.hdu.edu.cn/images/panel-title.png&quot;); background-color: transparent; padding: 0px 14px; color: rgb(124, 169, 237); font-size: 18px; font-family: Arial; font-weight: bold; background-position: 0% 100%;" align="left">Input</div><div id="" style="height: auto; background-image: url(&quot;http://acm.hdu.edu.cn/images/panel-content.png&quot;); margin: 0px; padding: 0px 20px; font-size: 14px; font-family: 'Times New Roman';">本题目包含多组测试，请处理到文件结束。<br>在每个测试的第一行，有两个正整数 N 和 M ( 0&lt;N&lt;=200000,0&lt;M&lt;5000 )，分别代表学生的数目和操作的数目。<br>学生ID编号分别从1编到N。<br>第二行包含N个整数，代表这N个学生的初始成绩，其中第i个数代表ID为i的学生的成绩。<br>接下来有M行。每一行有一个字符 C (只取'Q'或'U') ，和两个正整数A，B。<br>当C为'Q'的时候，表示这是一条询问操作，它询问ID从A到B(包括A,B)的学生当中，成绩最高的是多少。<br>当C为'U'的时候，表示这是一条更新操作，要求把ID为A的学生的成绩更改为B。<br></div><div style="height: auto; margin: 0px; background-image: url(&quot;http://acm.hdu.edu.cn/images/panel-bottom.png&quot;); background-position: 0% 0%;">&nbsp;</div><br><div style="height: 38px; background-image: url(&quot;http://acm.hdu.edu.cn/images/panel-title.png&quot;); background-color: transparent; padding: 0px 14px; color: rgb(124, 169, 237); font-size: 18px; font-family: Arial; font-weight: bold; background-position: 0% 100%;" align="left">Output</div><div style="height: auto; background-image: url(&quot;http://acm.hdu.edu.cn/images/panel-content.png&quot;); margin: 0px; padding: 0px 20px; font-size: 14px; font-family: 'Times New Roman';">对于每一次询问操作，在一行里面输出最高成绩。</div><div style="height: auto; margin: 0px; background-image: url(&quot;http://acm.hdu.edu.cn/images/panel-bottom.png&quot;); background-position: 0% 0%;">&nbsp;</div><br><div style="height: 38px; background-image: url(&quot;http://acm.hdu.edu.cn/images/panel-title.png&quot;); background-color: transparent; padding: 0px 14px; color: rgb(124, 169, 237); font-size: 18px; font-family: Arial; font-weight: bold; background-position: 0% 100%;" align="left">Sample Input</div><div style="height: auto; background-image: url(&quot;http://acm.hdu.edu.cn/images/panel-content.png&quot;); margin: 0px; padding: 0px 20px; font-size: 14px; font-family: 'Times New Roman';"><pre style="margin: 0px; font-size: 14px;"><div style="font-family: 'Courier New',Courier,monospace;">5 6 1 2 3 4 5 Q 1 5 U 3 6 Q 3 4 Q 4 5 U 2 9 Q 1 5</div></pre></div><div style="height: auto; margin: 0px; background-image: url(&quot;http://acm.hdu.edu.cn/images/panel-bottom.png&quot;); background-position: 0% 0%;">&nbsp;</div><br><div style="height: 38px; background-image: url(&quot;http://acm.hdu.edu.cn/images/panel-title.png&quot;); background-color: transparent; padding: 0px 14px; color: rgb(124, 169, 237); font-size: 18px; font-family: Arial; font-weight: bold; background-position: 0% 100%;" align="left">Sample Output</div><div style="height: auto; background-image: url(&quot;http://acm.hdu.edu.cn/images/panel-content.png&quot;); margin: 0px; padding: 0px 20px; font-size: 14px; font-family: 'Times New Roman';"><pre style="margin: 0px; font-size: 14px;"><div style="font-family: 'Courier New',Courier,monospace;">5 6 5 9  <div style="font-family: 'Times New Roman'; font-size: 14px; background-color: rgb(244, 251, 255); border-left-color: rgb(183, 203, 255); padding-top: 6px; padding-right: 6px; padding-bottom: 6px; padding-left: 6px; "><div style="font-family: Arial; font-weight: bold; color: rgb(124, 169, 237); "><em>Hint</em></div>Huge input,the C function scanf() will work better than cin</div><em style="font-size: 1px;"> </em></div></pre></div><div style="height: auto; margin: 0px; background-image: url(&quot;http://acm.hdu.edu.cn/images/panel-bottom.png&quot;); background-position: 0% 0%;">&nbsp;</div></span><br>
</span></div><p>&nbsp;</p><p>感觉好久没有A题了 , 最近一直没有状态,&nbsp; 豆豆也转行了, 郁闷....... &nbsp;&nbsp; 因为打算 专精 数据结构方面,</p><p>所以这几天一直都在复习 数据结构, 再一次学习了 线段树, 以前只会用它来 更新点 求和 , 现在终于水了一</p><p>个 RMQ 的裸题了, HAPPY 一下.... <br>
</p><p>对于 RMQ 的题目, 看PPT 上面的 DP 我直接0rz了...........表示DP只会做水题.... 这方面还是交给<br>
</p><p>YCH 吧. &nbsp; 不过看了&nbsp;<span style="border-collapse: separate; color: rgb(0, 0, 0); font-family: 'Segoe UI',Calibri,'Myriad Pro',Myriad,'Trebuchet MS',Helvetica,Arial,sans-serif; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; font-size: medium;"><span style="color: rgb(187, 187, 187); font-size: 13px; line-height: 32px;"><a href="http://www.notonlysuccess.com/?author=1" title="shǎ崽 " style="margin: 0px; padding: 0px; font-family: 'Segoe UI',Calibri,'Myriad Pro',Myriad,'Trebuchet MS',Helvetica,Arial,sans-serif; color: rgb(153, 153, 153); outline-style: none; font-weight: bold;">shǎ崽</a></span></span> 大神 博客的 线段树专辑后, 发现 用线段树处理 这类问题 非常方便, 修改查询</p><p>都是 O (logN)的 ,&nbsp; 稍稍优化了下输入, 234MS AC ........ <br>
</p><p>&nbsp;</p><p>代码如下 :<br>
</p>
  <div class="cnblogs_code"><img src="http://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif" class="code_img_closed" id="code_img_closed_c9d6cbc8-2faa-4358-87c6-2f687a9ae84d" style="display: none;"><img src="http://images.cnblogs.com/OutliningIndicators/ExpandedBlockStart.gif" class="code_img_opened" id="code_img_opened_c9d6cbc8-2faa-4358-87c6-2f687a9ae84d"><span class="cnblogs_code_collapse">代码</span><div id="cnblogs_code_open_c9d6cbc8-2faa-4358-87c6-2f687a9ae84d"><div><span style="color: rgb(0, 128, 0);">/*</span><span style="color: rgb(0, 128, 0);"><br>Coded&nbsp;By&nbsp;&nbsp;:&nbsp;MiYu<br>Link&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:&nbsp;</span><span style="color: rgb(0, 128, 0); text-decoration: underline;">http://www.cnblogs.com/MiYu</span><span style="color: rgb(0, 128, 0);">&nbsp;&nbsp;||&nbsp;</span><span style="color: rgb(0, 128, 0); text-decoration: underline;">http://www.cppblog.com/MiYu</span><span style="color: rgb(0, 128, 0);"><br>Author&nbsp;By&nbsp;:&nbsp;MiYu<br>Test&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:&nbsp;1<br>Program&nbsp;&nbsp;&nbsp;:&nbsp;1754<br></span><span style="color: rgb(0, 128, 0);">*/</span><span style="color: rgb(0, 0, 0);"><br></span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);">#pragma&nbsp;warning(&nbsp;disable:4789&nbsp;)</span><span style="color: rgb(0, 128, 0);"></span><span style="color: rgb(0, 0, 0);"><br>#include&nbsp;</span><span style="color: rgb(0, 0, 0);">&lt;</span><span style="color: rgb(0, 0, 0);">iostream</span><span style="color: rgb(0, 0, 0);">&gt;</span><span style="color: rgb(0, 0, 0);"><br>#include&nbsp;</span><span style="color: rgb(0, 0, 0);">&lt;</span><span style="color: rgb(0, 0, 0);">algorithm</span><span style="color: rgb(0, 0, 0);">&gt;</span><span style="color: rgb(0, 0, 0);"><br>#include&nbsp;</span><span style="color: rgb(0, 0, 0);">&lt;</span><span style="color: rgb(0, 0, 255);">string</span><span style="color: rgb(0, 0, 0);">&gt;</span><span style="color: rgb(0, 0, 0);"><br>#include&nbsp;</span><span style="color: rgb(0, 0, 0);">&lt;</span><span style="color: rgb(0, 0, 255);">set</span><span style="color: rgb(0, 0, 0);">&gt;</span><span style="color: rgb(0, 0, 0);"><br>#include&nbsp;</span><span style="color: rgb(0, 0, 0);">&lt;</span><span style="color: rgb(0, 0, 0);">map</span><span style="color: rgb(0, 0, 0);">&gt;</span><span style="color: rgb(0, 0, 0);"><br>#include&nbsp;</span><span style="color: rgb(0, 0, 0);">&lt;</span><span style="color: rgb(0, 0, 0);">utility</span><span style="color: rgb(0, 0, 0);">&gt;</span><span style="color: rgb(0, 0, 0);"><br>#include&nbsp;</span><span style="color: rgb(0, 0, 0);">&lt;</span><span style="color: rgb(0, 0, 0);">queue</span><span style="color: rgb(0, 0, 0);">&gt;</span><span style="color: rgb(0, 0, 0);"><br>#include&nbsp;</span><span style="color: rgb(0, 0, 0);">&lt;</span><span style="color: rgb(0, 0, 0);">stack</span><span style="color: rgb(0, 0, 0);">&gt;</span><span style="color: rgb(0, 0, 0);"><br>#include&nbsp;</span><span style="color: rgb(0, 0, 0);">&lt;</span><span style="color: rgb(0, 0, 0);">list</span><span style="color: rgb(0, 0, 0);">&gt;</span><span style="color: rgb(0, 0, 0);"><br>#include&nbsp;</span><span style="color: rgb(0, 0, 0);">&lt;</span><span style="color: rgb(0, 0, 0);">vector</span><span style="color: rgb(0, 0, 0);">&gt;</span><span style="color: rgb(0, 0, 0);"><br>#include&nbsp;</span><span style="color: rgb(0, 0, 0);">&lt;</span><span style="color: rgb(0, 0, 0);">cstdio</span><span style="color: rgb(0, 0, 0);">&gt;</span><span style="color: rgb(0, 0, 0);"><br>#include&nbsp;</span><span style="color: rgb(0, 0, 0);">&lt;</span><span style="color: rgb(0, 0, 0);">cstdlib</span><span style="color: rgb(0, 0, 0);">&gt;</span><span style="color: rgb(0, 0, 0);"><br>#include&nbsp;</span><span style="color: rgb(0, 0, 0);">&lt;</span><span style="color: rgb(0, 0, 0);">cstring</span><span style="color: rgb(0, 0, 0);">&gt;</span><span style="color: rgb(0, 0, 0);"><br>#include&nbsp;</span><span style="color: rgb(0, 0, 0);">&lt;</span><span style="color: rgb(0, 0, 0);">cmath</span><span style="color: rgb(0, 0, 0);">&gt;</span><span style="color: rgb(0, 0, 0);"><br></span><span style="color: rgb(0, 0, 255);">using</span><span style="color: rgb(0, 0, 0);">&nbsp;</span><span style="color: rgb(0, 0, 255);">namespace</span><span style="color: rgb(0, 0, 0);">&nbsp;std;<br>inline&nbsp;</span><span style="color: rgb(0, 0, 255);">int</span><span style="color: rgb(0, 0, 0);">&nbsp;max&nbsp;(&nbsp;</span><span style="color: rgb(0, 0, 255);">int</span><span style="color: rgb(0, 0, 0);">&nbsp;a,&nbsp;</span><span style="color: rgb(0, 0, 255);">int</span><span style="color: rgb(0, 0, 0);">&nbsp;b&nbsp;){<br>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(0, 0, 255);">return</span><span style="color: rgb(0, 0, 0);">&nbsp;a&nbsp;</span><span style="color: rgb(0, 0, 0);">&gt;</span><span style="color: rgb(0, 0, 0);">&nbsp;b&nbsp;</span><span style="color: rgb(0, 0, 0);">?</span><span style="color: rgb(0, 0, 0);">&nbsp;a&nbsp;:&nbsp;b;<br>}<br>typedef&nbsp;</span><span style="color: rgb(0, 0, 255);">struct</span><span style="color: rgb(0, 0, 0);">&nbsp;seg_Tree&nbsp;{<br>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(0, 0, 255);">int</span><span style="color: rgb(0, 0, 0);">&nbsp;left,&nbsp;right;<br>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(0, 0, 255);">int</span><span style="color: rgb(0, 0, 0);">&nbsp;mid()&nbsp;{&nbsp;</span><span style="color: rgb(0, 0, 255);">return</span><span style="color: rgb(0, 0, 0);">&nbsp;(left</span><span style="color: rgb(0, 0, 0);">+</span><span style="color: rgb(0, 0, 0);">right)</span><span style="color: rgb(0, 0, 0);">&gt;&gt;</span><span style="color: rgb(128, 0, 128);">1</span><span style="color: rgb(0, 0, 0);">;&nbsp;}<br>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(0, 0, 255);">int</span><span style="color: rgb(0, 0, 0);">&nbsp;max;<br>}S;<br>S&nbsp;seg[</span><span style="color: rgb(128, 0, 128);">605000</span><span style="color: rgb(0, 0, 0);">];<br></span><span style="color: rgb(0, 0, 255);">int</span><span style="color: rgb(0, 0, 0);">&nbsp;key[</span><span style="color: rgb(128, 0, 128);">200010</span><span style="color: rgb(0, 0, 0);">];<br></span><span style="color: rgb(0, 0, 255);">int</span><span style="color: rgb(0, 0, 0);">&nbsp;creat&nbsp;(&nbsp;</span><span style="color: rgb(0, 0, 255);">int</span><span style="color: rgb(0, 0, 0);">&nbsp;left,&nbsp;</span><span style="color: rgb(0, 0, 255);">int</span><span style="color: rgb(0, 0, 0);">&nbsp;right,&nbsp;</span><span style="color: rgb(0, 0, 255);">int</span><span style="color: rgb(0, 0, 0);">&nbsp;root&nbsp;</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);">&nbsp;</span><span style="color: rgb(128, 0, 128);">1</span><span style="color: rgb(0, 0, 0);">&nbsp;){<br>&nbsp;&nbsp;&nbsp;&nbsp;seg[root].left&nbsp;</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);">&nbsp;left;&nbsp;&nbsp;&nbsp;&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;seg[root].right&nbsp;</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);">&nbsp;right;&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(0, 0, 255);">if</span><span style="color: rgb(0, 0, 0);">&nbsp;(&nbsp;left&nbsp;</span><span style="color: rgb(0, 0, 0);">==</span><span style="color: rgb(0, 0, 0);">&nbsp;right&nbsp;)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(0, 0, 255);">return</span><span style="color: rgb(0, 0, 0);">&nbsp;seg[root].max&nbsp;</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);">&nbsp;key[left];<br>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(0, 0, 255);">int</span><span style="color: rgb(0, 0, 0);">&nbsp;mid&nbsp;</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);">&nbsp;seg[root].mid();<br>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(0, 0, 255);">return</span><span style="color: rgb(0, 0, 0);">&nbsp;seg[root].max&nbsp;</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);">&nbsp;max&nbsp;(&nbsp;creat&nbsp;(&nbsp;left,&nbsp;mid,&nbsp;root&nbsp;</span><span style="color: rgb(0, 0, 0);">&lt;&lt;</span><span style="color: rgb(0, 0, 0);">&nbsp;</span><span style="color: rgb(128, 0, 128);">1</span><span style="color: rgb(0, 0, 0);">&nbsp;),creat&nbsp;(&nbsp;mid&nbsp;</span><span style="color: rgb(0, 0, 0);">+</span><span style="color: rgb(0, 0, 0);">&nbsp;</span><span style="color: rgb(128, 0, 128);">1</span><span style="color: rgb(0, 0, 0);">,&nbsp;right,&nbsp;(&nbsp;root&nbsp;</span><span style="color: rgb(0, 0, 0);">&lt;&lt;</span><span style="color: rgb(0, 0, 0);">&nbsp;</span><span style="color: rgb(128, 0, 128);">1</span><span style="color: rgb(0, 0, 0);">&nbsp;)&nbsp;</span><span style="color: rgb(0, 0, 0);">+</span><span style="color: rgb(0, 0, 0);">&nbsp;</span><span style="color: rgb(128, 0, 128);">1</span><span style="color: rgb(0, 0, 0);">&nbsp;)&nbsp;);<br>}<br><br></span><span style="color: rgb(0, 0, 255);">void</span><span style="color: rgb(0, 0, 0);">&nbsp;modify&nbsp;(&nbsp;</span><span style="color: rgb(0, 0, 255);">int</span><span style="color: rgb(0, 0, 0);">&nbsp;val,&nbsp;</span><span style="color: rgb(0, 0, 255);">int</span><span style="color: rgb(0, 0, 0);">&nbsp;pos,&nbsp;</span><span style="color: rgb(0, 0, 255);">int</span><span style="color: rgb(0, 0, 0);">&nbsp;r&nbsp;</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);">&nbsp;</span><span style="color: rgb(128, 0, 128);">1</span><span style="color: rgb(0, 0, 0);">&nbsp;){<br>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(0, 0, 255);">if</span><span style="color: rgb(0, 0, 0);">&nbsp;(&nbsp;seg[r].left&nbsp;</span><span style="color: rgb(0, 0, 0);">==</span><span style="color: rgb(0, 0, 0);">&nbsp;seg[r].right&nbsp;){<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;seg[r].max&nbsp;</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);">&nbsp;val;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(0, 0, 255);">return</span><span style="color: rgb(0, 0, 0);">;<br>&nbsp;&nbsp;&nbsp;&nbsp;}<br>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(0, 0, 255);">int</span><span style="color: rgb(0, 0, 0);">&nbsp;mid&nbsp;</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);">&nbsp;seg[r].mid();<br>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(0, 0, 255);">if</span><span style="color: rgb(0, 0, 0);">&nbsp;(&nbsp;pos&nbsp;</span><span style="color: rgb(0, 0, 0);">&lt;=</span><span style="color: rgb(0, 0, 0);">&nbsp;mid&nbsp;){<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;modify&nbsp;(&nbsp;val,&nbsp;pos,&nbsp;r&nbsp;</span><span style="color: rgb(0, 0, 0);">&lt;&lt;</span><span style="color: rgb(0, 0, 0);">&nbsp;</span><span style="color: rgb(128, 0, 128);">1</span><span style="color: rgb(0, 0, 0);">&nbsp;);<br>&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;</span><span style="color: rgb(0, 0, 255);">else</span><span style="color: rgb(0, 0, 0);">&nbsp;{<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;modify&nbsp;(&nbsp;val,&nbsp;pos,&nbsp;(&nbsp;r&nbsp;</span><span style="color: rgb(0, 0, 0);">&lt;&lt;</span><span style="color: rgb(0, 0, 0);">&nbsp;</span><span style="color: rgb(128, 0, 128);">1</span><span style="color: rgb(0, 0, 0);">&nbsp;)&nbsp;</span><span style="color: rgb(0, 0, 0);">+</span><span style="color: rgb(0, 0, 0);">&nbsp;</span><span style="color: rgb(128, 0, 128);">1</span><span style="color: rgb(0, 0, 0);">&nbsp;);<br>&nbsp;&nbsp;&nbsp;&nbsp;}<br>&nbsp;&nbsp;&nbsp;&nbsp;seg[r].max&nbsp;</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);">&nbsp;max&nbsp;(&nbsp;seg[r</span><span style="color: rgb(0, 0, 0);">&lt;&lt;</span><span style="color: rgb(128, 0, 128);">1</span><span style="color: rgb(0, 0, 0);">].max,&nbsp;seg[&nbsp;(r</span><span style="color: rgb(0, 0, 0);">&lt;&lt;</span><span style="color: rgb(128, 0, 128);">1</span><span style="color: rgb(0, 0, 0);">)&nbsp;</span><span style="color: rgb(0, 0, 0);">+</span><span style="color: rgb(0, 0, 0);">&nbsp;</span><span style="color: rgb(128, 0, 128);">1</span><span style="color: rgb(0, 0, 0);">&nbsp;].max&nbsp;);<br>}<br><br></span><span style="color: rgb(0, 0, 255);">int</span><span style="color: rgb(0, 0, 0);">&nbsp;quy&nbsp;(&nbsp;</span><span style="color: rgb(0, 0, 255);">int</span><span style="color: rgb(0, 0, 0);">&nbsp;left,&nbsp;</span><span style="color: rgb(0, 0, 255);">int</span><span style="color: rgb(0, 0, 0);">&nbsp;right,&nbsp;</span><span style="color: rgb(0, 0, 255);">int</span><span style="color: rgb(0, 0, 0);">&nbsp;r&nbsp;</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);">&nbsp;</span><span style="color: rgb(128, 0, 128);">1</span><span style="color: rgb(0, 0, 0);">&nbsp;){<br>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(0, 0, 255);">if</span><span style="color: rgb(0, 0, 0);">&nbsp;(&nbsp;seg[r].left&nbsp;</span><span style="color: rgb(0, 0, 0);">==</span><span style="color: rgb(0, 0, 0);">&nbsp;left&nbsp;</span><span style="color: rgb(0, 0, 0);">&amp;&amp;</span><span style="color: rgb(0, 0, 0);">&nbsp;seg[r].right&nbsp;</span><span style="color: rgb(0, 0, 0);">==</span><span style="color: rgb(0, 0, 0);">&nbsp;right&nbsp;){<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(0, 0, 255);">return</span><span style="color: rgb(0, 0, 0);">&nbsp;seg[r].max;<br>&nbsp;&nbsp;&nbsp;&nbsp;}<br>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(0, 0, 255);">int</span><span style="color: rgb(0, 0, 0);">&nbsp;mid&nbsp;</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);">&nbsp;seg[r].mid();<br>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(0, 0, 255);">if</span><span style="color: rgb(0, 0, 0);">&nbsp;(&nbsp;right&nbsp;</span><span style="color: rgb(0, 0, 0);">&lt;=</span><span style="color: rgb(0, 0, 0);">&nbsp;mid&nbsp;&nbsp;){<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(0, 0, 255);">return</span><span style="color: rgb(0, 0, 0);">&nbsp;quy&nbsp;(&nbsp;left,&nbsp;right,&nbsp;r&nbsp;</span><span style="color: rgb(0, 0, 0);">&lt;&lt;</span><span style="color: rgb(0, 0, 0);">&nbsp;</span><span style="color: rgb(128, 0, 128);">1</span><span style="color: rgb(0, 0, 0);">&nbsp;);<br>&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;</span><span style="color: rgb(0, 0, 255);">else</span><span style="color: rgb(0, 0, 0);">&nbsp;</span><span style="color: rgb(0, 0, 255);">if</span><span style="color: rgb(0, 0, 0);">&nbsp;(&nbsp;left&nbsp;</span><span style="color: rgb(0, 0, 0);">&gt;</span><span style="color: rgb(0, 0, 0);">&nbsp;mid&nbsp;)&nbsp;{<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(0, 0, 255);">return</span><span style="color: rgb(0, 0, 0);">&nbsp;quy&nbsp;(&nbsp;left,&nbsp;right,&nbsp;(r&nbsp;</span><span style="color: rgb(0, 0, 0);">&lt;&lt;</span><span style="color: rgb(0, 0, 0);">&nbsp;</span><span style="color: rgb(128, 0, 128);">1</span><span style="color: rgb(0, 0, 0);">)&nbsp;</span><span style="color: rgb(0, 0, 0);">+</span><span style="color: rgb(0, 0, 0);">&nbsp;</span><span style="color: rgb(128, 0, 128);">1</span><span style="color: rgb(0, 0, 0);">&nbsp;);<br>&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;</span><span style="color: rgb(0, 0, 255);">else</span><span style="color: rgb(0, 0, 0);">&nbsp;{<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(0, 0, 255);">return</span><span style="color: rgb(0, 0, 0);">&nbsp;max&nbsp;(&nbsp;quy&nbsp;(&nbsp;left,&nbsp;mid,&nbsp;r&nbsp;</span><span style="color: rgb(0, 0, 0);">&lt;&lt;</span><span style="color: rgb(0, 0, 0);">&nbsp;</span><span style="color: rgb(128, 0, 128);">1</span><span style="color: rgb(0, 0, 0);">&nbsp;),&nbsp;quy&nbsp;(&nbsp;mid&nbsp;</span><span style="color: rgb(0, 0, 0);">+</span><span style="color: rgb(0, 0, 0);">&nbsp;</span><span style="color: rgb(128, 0, 128);">1</span><span style="color: rgb(0, 0, 0);">,&nbsp;right,&nbsp;(r&nbsp;</span><span style="color: rgb(0, 0, 0);">&lt;&lt;</span><span style="color: rgb(0, 0, 0);">&nbsp;</span><span style="color: rgb(128, 0, 128);">1</span><span style="color: rgb(0, 0, 0);">)&nbsp;</span><span style="color: rgb(0, 0, 0);">+</span><span style="color: rgb(0, 0, 0);">&nbsp;</span><span style="color: rgb(128, 0, 128);">1</span><span style="color: rgb(0, 0, 0);">&nbsp;)&nbsp;);<br>&nbsp;&nbsp;&nbsp;&nbsp;}<br>}<br>inline&nbsp;</span><span style="color: rgb(0, 0, 255);">bool</span><span style="color: rgb(0, 0, 0);">&nbsp;scan_d(</span><span style="color: rgb(0, 0, 255);">int</span><span style="color: rgb(0, 0, 0);">&nbsp;</span><span style="color: rgb(0, 0, 0);">&amp;</span><span style="color: rgb(0, 0, 0);">num) <br>{<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(0, 0, 255);">char</span><span style="color: rgb(0, 0, 0);">&nbsp;</span><span style="color: rgb(0, 0, 255);">in</span><span style="color: rgb(0, 0, 0);">;</span><span style="color: rgb(0, 0, 255);">bool</span><span style="color: rgb(0, 0, 0);">&nbsp;IsN</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 255);">false</span><span style="color: rgb(0, 0, 0);">;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(0, 0, 255);">in</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);">getchar();<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(0, 0, 255);">if</span><span style="color: rgb(0, 0, 0);">(</span><span style="color: rgb(0, 0, 255);">in</span><span style="color: rgb(0, 0, 0);">==</span><span style="color: rgb(0, 0, 0);">EOF)&nbsp;</span><span style="color: rgb(0, 0, 255);">return</span><span style="color: rgb(0, 0, 0);">&nbsp;</span><span style="color: rgb(0, 0, 255);">false</span><span style="color: rgb(0, 0, 0);">;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(0, 0, 255);">while</span><span style="color: rgb(0, 0, 0);">(</span><span style="color: rgb(0, 0, 255);">in</span><span style="color: rgb(0, 0, 0);">!=</span><span style="color: rgb(128, 0, 0);">'</span><span style="color: rgb(128, 0, 0);">-</span><span style="color: rgb(128, 0, 0);">'</span><span style="color: rgb(0, 0, 0);">&amp;&amp;</span><span style="color: rgb(0, 0, 0);">(</span><span style="color: rgb(0, 0, 255);">in</span><span style="color: rgb(0, 0, 0);">&lt;</span><span style="color: rgb(128, 0, 0);">'</span><span style="color: rgb(128, 0, 0);">0</span><span style="color: rgb(128, 0, 0);">'</span><span style="color: rgb(0, 0, 0);">||</span><span style="color: rgb(0, 0, 255);">in</span><span style="color: rgb(0, 0, 0);">&gt;</span><span style="color: rgb(128, 0, 0);">'</span><span style="color: rgb(128, 0, 0);">9</span><span style="color: rgb(128, 0, 0);">'</span><span style="color: rgb(0, 0, 0);">))&nbsp;</span><span style="color: rgb(0, 0, 255);">in</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);">getchar();<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(0, 0, 255);">if</span><span style="color: rgb(0, 0, 0);">(</span><span style="color: rgb(0, 0, 255);">in</span><span style="color: rgb(0, 0, 0);">==</span><span style="color: rgb(128, 0, 0);">'</span><span style="color: rgb(128, 0, 0);">-</span><span style="color: rgb(128, 0, 0);">'</span><span style="color: rgb(0, 0, 0);">){&nbsp;IsN</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 255);">true</span><span style="color: rgb(0, 0, 0);">;num</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(128, 0, 128);">0</span><span style="color: rgb(0, 0, 0);">;}<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(0, 0, 255);">else</span><span style="color: rgb(0, 0, 0);">&nbsp;num</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 255);">in</span><span style="color: rgb(0, 0, 0);">-</span><span style="color: rgb(128, 0, 0);">'</span><span style="color: rgb(128, 0, 0);">0</span><span style="color: rgb(128, 0, 0);">'</span><span style="color: rgb(0, 0, 0);">;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(0, 0, 255);">while</span><span style="color: rgb(0, 0, 0);">(</span><span style="color: rgb(0, 0, 255);">in</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);">getchar(),</span><span style="color: rgb(0, 0, 255);">in</span><span style="color: rgb(0, 0, 0);">&gt;=</span><span style="color: rgb(128, 0, 0);">'</span><span style="color: rgb(128, 0, 0);">0</span><span style="color: rgb(128, 0, 0);">'</span><span style="color: rgb(0, 0, 0);">&amp;&amp;</span><span style="color: rgb(0, 0, 255);">in</span><span style="color: rgb(0, 0, 0);">&lt;=</span><span style="color: rgb(128, 0, 0);">'</span><span style="color: rgb(128, 0, 0);">9</span><span style="color: rgb(128, 0, 0);">'</span><span style="color: rgb(0, 0, 0);">){<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;num</span><span style="color: rgb(0, 0, 0);">*=</span><span style="color: rgb(128, 0, 128);">10</span><span style="color: rgb(0, 0, 0);">,num</span><span style="color: rgb(0, 0, 0);">+=</span><span style="color: rgb(0, 0, 255);">in</span><span style="color: rgb(0, 0, 0);">-</span><span style="color: rgb(128, 0, 0);">'</span><span style="color: rgb(128, 0, 0);">0</span><span style="color: rgb(128, 0, 0);">'</span><span style="color: rgb(0, 0, 0);">;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(0, 0, 255);">if</span><span style="color: rgb(0, 0, 0);">(IsN)&nbsp;num</span><span style="color: rgb(0, 0, 0);">=-</span><span style="color: rgb(0, 0, 0);">num;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(0, 0, 255);">return</span><span style="color: rgb(0, 0, 0);">&nbsp;</span><span style="color: rgb(0, 0, 255);">true</span><span style="color: rgb(0, 0, 0);">;<br>}<br></span><span style="color: rgb(0, 0, 255);">int</span><span style="color: rgb(0, 0, 0);">&nbsp;main&nbsp;()<br>{<br>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(0, 0, 255);">int</span><span style="color: rgb(0, 0, 0);">&nbsp;N,&nbsp;M,&nbsp;x,&nbsp;y;<br>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(0, 0, 255);">while</span><span style="color: rgb(0, 0, 0);">&nbsp;(&nbsp;scan_d(N)&nbsp;</span><span style="color: rgb(0, 0, 0);">&amp;&amp;</span><span style="color: rgb(0, 0, 0);">&nbsp;scan_d(M)&nbsp;){<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(0, 0, 255);">for</span><span style="color: rgb(0, 0, 0);">&nbsp;(&nbsp;</span><span style="color: rgb(0, 0, 255);">int</span><span style="color: rgb(0, 0, 0);">&nbsp;i&nbsp;</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);">&nbsp;</span><span style="color: rgb(128, 0, 128);">1</span><span style="color: rgb(0, 0, 0);">;&nbsp;i&nbsp;</span><span style="color: rgb(0, 0, 0);">&lt;=</span><span style="color: rgb(0, 0, 0);">&nbsp;N;&nbsp;</span><span style="color: rgb(0, 0, 0);">++</span><span style="color: rgb(0, 0, 0);">&nbsp;i&nbsp;){<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;scan_d(&nbsp;key[i]&nbsp;);&nbsp;&nbsp;&nbsp;&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;creat&nbsp;(&nbsp;</span><span style="color: rgb(128, 0, 128);">1</span><span style="color: rgb(0, 0, 0);">,&nbsp;N&nbsp;);&nbsp;&nbsp; </span><span style="color: rgb(0, 128, 0);"><br></span><span style="color: rgb(0, 0, 0);">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(0, 0, 255);">while</span><span style="color: rgb(0, 0, 0);">&nbsp;(&nbsp;M&nbsp;</span><span style="color: rgb(0, 0, 0);">--</span><span style="color: rgb(0, 0, 0);">&nbsp;){<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(0, 0, 255);">char</span><span style="color: rgb(0, 0, 0);">&nbsp;ask[</span><span style="color: rgb(128, 0, 128);">5</span><span style="color: rgb(0, 0, 0);">];<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;scanf&nbsp;(&nbsp;</span><span style="color: rgb(128, 0, 0);">"</span><span style="color: rgb(128, 0, 0);">%s</span><span style="color: rgb(128, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">,&nbsp;ask&nbsp;);</span><span style="color: rgb(0, 128, 0);"></span><span style="color: rgb(0, 128, 0);"><br></span><span style="color: rgb(0, 0, 0);">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;scan_d(x);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;scan_d(y);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(0, 0, 255);">switch</span><span style="color: rgb(0, 0, 0);">&nbsp;(&nbsp;ask[</span><span style="color: rgb(128, 0, 128);">0</span><span style="color: rgb(0, 0, 0);">]&nbsp;){<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(0, 0, 255);">case</span><span style="color: rgb(0, 0, 0);">&nbsp;</span><span style="color: rgb(128, 0, 0);">'</span><span style="color: rgb(128, 0, 0);">Q</span><span style="color: rgb(128, 0, 0);">'</span><span style="color: rgb(0, 0, 0);">:&nbsp;&nbsp;&nbsp;&nbsp;printf&nbsp;(&nbsp;</span><span style="color: rgb(128, 0, 0);">"</span><span style="color: rgb(128, 0, 0);">%d\n</span><span style="color: rgb(128, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">,&nbsp;quy&nbsp;(&nbsp;x,y&nbsp;)&nbsp;);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(0, 0, 255);">break</span><span style="color: rgb(0, 0, 0);">;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(0, 0, 255);">case</span><span style="color: rgb(0, 0, 0);">&nbsp;</span><span style="color: rgb(128, 0, 0);">'</span><span style="color: rgb(128, 0, 0);">U</span><span style="color: rgb(128, 0, 0);">'</span><span style="color: rgb(0, 0, 0);">:&nbsp;&nbsp;&nbsp;&nbsp;modify&nbsp;(&nbsp;y,&nbsp;x&nbsp;);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br>&nbsp;&nbsp;&nbsp;&nbsp;}<br>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(0, 0, 255);">return</span><span style="color: rgb(0, 0, 0);">&nbsp;</span><span style="color: rgb(128, 0, 128);">0</span><span style="color: rgb(0, 0, 0);">;<br>}<br><br></span><span style="color: rgb(0, 128, 0);">/*</span><span style="color: rgb(0, 128, 0);"><br>5&nbsp;6<br>1&nbsp;2&nbsp;3&nbsp;4&nbsp;5<br>Q&nbsp;1&nbsp;5<br>U&nbsp;3&nbsp;6<br>Q&nbsp;3&nbsp;4<br>Q&nbsp;4&nbsp;5<br>U&nbsp;2&nbsp;9<br>Q&nbsp;1&nbsp;5<br></span><span style="color: rgb(0, 128, 0);">*/</span></div></div></div>
  <p><br>
  </p>
<p>&nbsp;</p><p>&nbsp;</p></div>
<p><br>
</p>
<p> </p>
<img src ="http://www.cppblog.com/MiYu/aggbug/126668.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/MiYu/" target="_blank">MiYu</a> 2010-09-15 16:08 <a href="http://www.cppblog.com/MiYu/archive/2010/09/15/126668.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>HDOJ 1166 HDU 1166 敌兵布阵 (线段树解法)ACM 1166 IN HDU</title><link>http://www.cppblog.com/MiYu/archive/2010/09/04/125867.html</link><dc:creator>MiYu</dc:creator><author>MiYu</author><pubDate>Sat, 04 Sep 2010 04:53:00 GMT</pubDate><guid>http://www.cppblog.com/MiYu/archive/2010/09/04/125867.html</guid><wfw:comment>http://www.cppblog.com/MiYu/comments/125867.html</wfw:comment><comments>http://www.cppblog.com/MiYu/archive/2010/09/04/125867.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/MiYu/comments/commentRss/125867.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/MiYu/services/trackbacks/125867.html</trackback:ping><description><![CDATA[

<p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; font-family: verdana, 'courier new'; font-size: 14px; line-height: 21px; ">MiYu原创, 转帖请注明 : 转载自&nbsp;<a href="http://www.cnblogs.com/MiYu"><font color="#000000">______________白白の屋</font></a>&nbsp;&nbsp;<img src="http://www.cnblogs.com/Emoticons/baimantou/223332482.gif" alt="">&nbsp;&nbsp;</p><p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; font-family: verdana, 'courier new'; font-size: 14px; line-height: 21px; ">&nbsp;</p><p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; font-family: verdana, 'courier new'; font-size: 14px; line-height: 21px; ">先前做了这一题, 不过是用 树状数组做的, 对于这一类型的题目也来说非常方便快捷. 具体地址 :&nbsp;<a href="http://www.cnblogs.com/MiYu/archive/2010/08/25/1808441.html">http://www.cnblogs.com/MiYu/archive/2010/08/25/1808441.html</a></p><p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; font-family: verdana, 'courier new'; font-size: 14px; line-height: 21px; ">&nbsp;</p><p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; font-family: verdana, 'courier new'; font-size: 14px; line-height: 21px; ">这几天学了 线段树 , 不是很明白它的用途 和 使用方法, &nbsp;因为 听说 树状数组是 线段树的 一种特殊情况 ( 部分资料是这么说的 ) . &nbsp;于是就又做了一次这个题目.</p><p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; font-family: verdana, 'courier new'; font-size: 14px; line-height: 21px; ">不过使用的是线段树的 方法 :</p><p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; font-family: verdana, 'courier new'; font-size: 14px; line-height: 21px; ">代码如下 :</p><div class="cnblogs_code" style="background-color: rgb(245, 245, 245); font-family: 'Courier New'; font-size: 13px; border-left-color: rgb(204, 204, 204); padding-top: 5px; padding-right: 5px; padding-bottom: 5px; padding-left: 5px; word-break: break-all; overflow-x: auto; overflow-y: auto; line-height: 21px; "><img src="http://images.cnblogs.com/OutliningIndicators/ExpandedBlockStart.gif" class="code_img_opened" id="code_img_opened_fd9a7ebe-31b4-4010-86f1-450ac5860cfa" style="vertical-align: middle; padding-right: 5px; "><span class="cnblogs_code_collapse" style="border-right-color: rgb(128, 128, 128); border-right-width: 1px; border-right-style: solid; border-top-color: rgb(128, 128, 128); border-top-width: 1px; border-top-style: solid; border-left-color: rgb(128, 128, 128); border-left-width: 1px; border-left-style: solid; border-bottom-color: rgb(128, 128, 128); border-bottom-width: 1px; border-bottom-style: solid; background-color: rgb(255, 255, 255); padding-top: 2px; padding-right: 2px; padding-bottom: 2px; padding-left: 2px; font-family: 'Courier New'; ">代码</span><div id="cnblogs_code_open_fd9a7ebe-31b4-4010-86f1-450ac5860cfa"><div><span style="font-family: 'Courier New'; color: rgb(0, 128, 0); ">/*</span><span style="font-family: 'Courier New'; color: rgb(0, 128, 0); "><br>MiYu原创,&nbsp;转帖请注明&nbsp;:&nbsp;转载自&nbsp;______________白白の屋<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="font-family: 'Courier New'; color: rgb(0, 128, 0); text-decoration: underline; ">http://www.cnblog.com/MiYu</span><span style="font-family: 'Courier New'; color: rgb(0, 128, 0); "><br>Author&nbsp;By&nbsp;:&nbsp;MiYu<br>Test&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:&nbsp;3<br>Program&nbsp;&nbsp;&nbsp;:&nbsp;1166<br></span><span style="font-family: 'Courier New'; color: rgb(0, 128, 0); ">*/</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 0); "><br><br>#include&nbsp;</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 0); ">&lt;</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 0); ">iostream</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 0); ">&gt;</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 0); "><br>#include&nbsp;</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 0); ">&lt;</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 0); ">algorithm</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 0); ">&gt;</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 0); "><br></span><span style="font-family: 'Courier New'; color: rgb(0, 0, 255); ">using</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 0); ">&nbsp;</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 255); ">namespace</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 0); ">&nbsp;std;<br>typedef&nbsp;</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 255); ">struct</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 0); ">&nbsp;Line{<span class="Apple-tab-span" style="font-family: 'Courier New'; white-space: pre; ">		</span>//线段树结构体<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;friend&nbsp;</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 255); ">struct</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 0); ">&nbsp;optLine;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Line&nbsp;()&nbsp;{&nbsp;sum&nbsp;</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 0); ">=</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 0); ">&nbsp;</span><span style="font-family: 'Courier New'; color: rgb(128, 0, 128); ">0</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 0); ">;&nbsp;left&nbsp;</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 0); ">=</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 0); ">&nbsp;right&nbsp;</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 0); ">=</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 0); ">&nbsp;NULL;&nbsp;};<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 255); ">int</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 0); ">&nbsp;l,r,sum;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 255); ">struct</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 0); ">&nbsp;Line&nbsp;</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 0); ">*</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 0); ">left,&nbsp;</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 0); ">*</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 0); ">right;<br>}L;<br>typedef&nbsp;</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 255); ">struct</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 0); ">&nbsp;optLine&nbsp;{<span class="Apple-tab-span" style="font-family: 'Courier New'; white-space: pre; ">	</span>//线段树操作结构<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 255); ">void</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 0); ">&nbsp;Creat&nbsp;(&nbsp;</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 255); ">struct</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 0); ">&nbsp;Line&nbsp;</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 0); ">*</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 0); ">node,&nbsp;</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 255); ">int</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 0); ">&nbsp;beg,&nbsp;</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 255); ">int</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 0); ">&nbsp;end&nbsp;);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 255); ">void</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 0); ">&nbsp;modify&nbsp;(&nbsp;</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 255); ">struct</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 0); ">&nbsp;Line&nbsp;</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 0); ">*</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 0); ">node,&nbsp;</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 255); ">int</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 0); ">&nbsp;pos,</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 255); ">int</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 0); ">&nbsp;val&nbsp;);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 255); ">int</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 0); ">&nbsp;quy&nbsp;(&nbsp;</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 255); ">struct</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 0); ">&nbsp;Line&nbsp;</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 0); ">*</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 0); ">node,&nbsp;</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 255); ">int</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 0); ">&nbsp;beg,&nbsp;</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 255); ">int</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 0); ">&nbsp;end&nbsp;);&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br>}OPT;<br></span><span style="font-family: 'Courier New'; color: rgb(0, 0, 255); ">void</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 0); ">&nbsp;optLine::Creat&nbsp;(&nbsp;</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 255); ">struct</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 0); ">&nbsp;Line&nbsp;</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 0); ">*</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 0); ">node,&nbsp;</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 255); ">int</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 0); ">&nbsp;beg,&nbsp;</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 255); ">int</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 0); ">&nbsp;end&nbsp;){<span class="Apple-tab-span" style="font-family: 'Courier New'; white-space: pre; ">	</span>//建树<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;node</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 0); ">-&gt;</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 0); ">l&nbsp;</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 0); ">=</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 0); ">&nbsp;beg;&nbsp;&nbsp;node</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 0); ">-&gt;</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 0); ">r&nbsp;</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 0); ">=</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 0); ">&nbsp;end;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 255); ">if</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 0); ">&nbsp;(&nbsp;beg&nbsp;</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 0); ">==</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 0); ">&nbsp;end&nbsp;)&nbsp;</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 255); ">return</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 0); ">;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 255); ">int</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 0); ">&nbsp;mid&nbsp;</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 0); ">=</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 0); ">&nbsp;(&nbsp;node</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 0); ">-&gt;</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 0); ">l&nbsp;</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 0); ">+</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 0); ">&nbsp;node</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 0); ">-&gt;</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 0); ">r&nbsp;)&nbsp;</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 0); ">&gt;&gt;</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 0); ">&nbsp;</span><span style="font-family: 'Courier New'; color: rgb(128, 0, 128); ">1</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 0); ">;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;L&nbsp;</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 0); ">*</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 0); ">p&nbsp;</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 0); ">=</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 0); ">&nbsp;</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 255); ">new</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 0); ">&nbsp;L;&nbsp;&nbsp;L&nbsp;</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 0); ">*</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 0); ">q&nbsp;</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 0); ">=</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 0); ">&nbsp;</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 255); ">new</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 0); ">&nbsp;L;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;node</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 0); ">-&gt;</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 0); ">left&nbsp;</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 0); ">=</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 0); ">&nbsp;p;&nbsp;node</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 0); ">-&gt;</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 0); ">right&nbsp;</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 0); ">=</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 0); ">&nbsp;q;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Creat&nbsp;(&nbsp;p,&nbsp;beg,&nbsp;mid&nbsp;);&nbsp;&nbsp;&nbsp;Creat&nbsp;(&nbsp;q,&nbsp;mid&nbsp;</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 0); ">+</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 0); ">&nbsp;</span><span style="font-family: 'Courier New'; color: rgb(128, 0, 128); ">1</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 0); ">,&nbsp;end&nbsp;);&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br>}<br></span><span style="font-family: 'Courier New'; color: rgb(0, 0, 255); ">void</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 0); ">&nbsp;optLine::modify&nbsp;(&nbsp;</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 255); ">struct</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 0); ">&nbsp;Line&nbsp;</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 0); ">*</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 0); ">node,&nbsp;</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 255); ">int</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 0); ">&nbsp;pos,&nbsp;</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 255); ">int</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 0); ">&nbsp;val&nbsp;){<span class="Apple-tab-span" style="font-family: 'Courier New'; white-space: pre; ">	</span>//修改<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 255); ">if</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 0); ">&nbsp;(&nbsp;pos&nbsp;</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 0); ">&gt;=</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 0); ">&nbsp;node</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 0); ">-&gt;</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 0); ">l&nbsp;</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 0); ">&amp;&amp;</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 0); ">&nbsp;pos&nbsp;</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 0); ">&lt;=</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 0); ">&nbsp;node</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 0); ">-&gt;</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 0); ">r&nbsp;)&nbsp;node</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 0); ">-&gt;</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 0); ">sum&nbsp;</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 0); ">+=</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 0); ">&nbsp;val;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 255); ">if</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 0); ">&nbsp;(&nbsp;node</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 0); ">-&gt;</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 0); ">l&nbsp;</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 0); ">==</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 0); ">&nbsp;node</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 0); ">-&gt;</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 0); ">r&nbsp;)&nbsp;</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 255); ">return</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 0); ">;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 255); ">int</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 0); ">&nbsp;mid&nbsp;</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 0); ">=</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 0); ">&nbsp;(&nbsp;node</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 0); ">-&gt;</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 0); ">l&nbsp;</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 0); ">+</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 0); ">&nbsp;node</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 0); ">-&gt;</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 0); ">r&nbsp;)&nbsp;</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 0); ">&gt;&gt;</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 0); ">&nbsp;</span><span style="font-family: 'Courier New'; color: rgb(128, 0, 128); ">1</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 0); ">;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 255); ">if</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 0); ">&nbsp;(&nbsp;mid&nbsp;</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 0); ">&gt;=</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 0); ">&nbsp;pos&nbsp;)&nbsp;modify&nbsp;(&nbsp;node</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 0); ">-&gt;</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 0); ">left,&nbsp;pos,&nbsp;val&nbsp;);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 255); ">else</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 0); ">&nbsp;</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 255); ">if</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 0); ">&nbsp;(&nbsp;mid&nbsp;</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 0); ">&lt;</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 0); ">&nbsp;pos&nbsp;)&nbsp;modify&nbsp;(&nbsp;node</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 0); ">-&gt;</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 0); ">right,&nbsp;pos,val&nbsp;);<br>}<br></span><span style="font-family: 'Courier New'; color: rgb(0, 0, 255); ">int</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 0); ">&nbsp;optLine::quy&nbsp;(&nbsp;</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 255); ">struct</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 0); ">&nbsp;Line&nbsp;</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 0); ">*</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 0); ">node,&nbsp;</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 255); ">int</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 0); ">&nbsp;beg,&nbsp;</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 255); ">int</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 0); ">&nbsp;end&nbsp;){<span class="Apple-tab-span" style="font-family: 'Courier New'; white-space: pre; ">	</span>//查询<br>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 255); ">int</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 0); ">&nbsp;sum&nbsp;</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 0); ">=</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 0); ">&nbsp;</span><span style="font-family: 'Courier New'; color: rgb(128, 0, 128); ">0</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 0); ">;&nbsp;&nbsp;</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 255); ">int</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 0); ">&nbsp;mid&nbsp;</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 0); ">=</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 0); ">&nbsp;(&nbsp;node</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 0); ">-&gt;</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 0); ">l&nbsp;</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 0); ">+</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 0); ">&nbsp;node</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 0); ">-&gt;</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 0); ">r&nbsp;)&nbsp;</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 0); ">&gt;&gt;</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 0); ">&nbsp;</span><span style="font-family: 'Courier New'; color: rgb(128, 0, 128); ">1</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 0); ">;<br>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 255); ">if</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 0); ">&nbsp;(&nbsp;node</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 0); ">-&gt;</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 0); ">l&nbsp;</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 0); ">==</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 0); ">&nbsp;beg&nbsp;</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 0); ">&amp;&amp;</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 0); ">&nbsp;node</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 0); ">-&gt;</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 0); ">r&nbsp;</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 0); ">==</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 0); ">&nbsp;end&nbsp;)&nbsp;</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 255); ">return</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 0); ">&nbsp;node</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 0); ">-&gt;</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 0); ">sum;<br>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 255); ">if</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 0); ">&nbsp;(&nbsp;mid&nbsp;</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 0); ">&gt;=</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 0); ">&nbsp;end&nbsp;)&nbsp;</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 255); ">return</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 0); ">&nbsp;sum&nbsp;</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 0); ">+=</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 0); ">&nbsp;quy&nbsp;(&nbsp;node</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 0); ">-&gt;</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 0); ">left,&nbsp;beg,end&nbsp;);<br>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 255); ">else</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 0); ">&nbsp;</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 255); ">if</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 0); ">&nbsp;(&nbsp;beg&nbsp;</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 0); ">&gt;</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 0); ">&nbsp;mid&nbsp;)&nbsp;</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 255); ">return</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 0); ">&nbsp;sum&nbsp;</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 0); ">+=</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 0); ">&nbsp;quy&nbsp;(&nbsp;node</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 0); ">-&gt;</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 0); ">right,&nbsp;beg,&nbsp;end&nbsp;);&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 255); ">else</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 0); ">&nbsp;{<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 255); ">return</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 0); ">&nbsp;sum&nbsp;</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 0); ">+=</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 0); ">&nbsp;quy&nbsp;(&nbsp;node</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 0); ">-&gt;</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 0); ">left,&nbsp;beg,&nbsp;mid&nbsp;)&nbsp;</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 0); ">+</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 0); ">&nbsp;quy&nbsp;(&nbsp;node</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 0); ">-&gt;</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 0); ">right,&nbsp;mid</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 0); ">+</span><span style="font-family: 'Courier New'; color: rgb(128, 0, 128); ">1</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 0); ">,end&nbsp;);&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;&nbsp;&nbsp;<br>}<br>inline&nbsp;</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 255); ">bool</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 0); ">&nbsp;scan_ud(</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 255); ">int</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 0); ">&nbsp;</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 0); ">&amp;</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 0); ">num)&nbsp;<br>{<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 255); ">char</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 0); ">&nbsp;</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 255); ">in</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 0); ">;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 255); ">in</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 0); ">=</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 0); ">getchar();<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 255); ">if</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 0); ">(</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 255); ">in</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 0); ">==</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 0); ">EOF)&nbsp;</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 255); ">return</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 0); ">&nbsp;</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 255); ">false</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 0); ">;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 255); ">while</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 0); ">(</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 255); ">in</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 0); ">&lt;</span><span style="font-family: 'Courier New'; color: rgb(128, 0, 0); ">'</span><span style="font-family: 'Courier New'; color: rgb(128, 0, 0); ">0</span><span style="font-family: 'Courier New'; color: rgb(128, 0, 0); ">'</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 0); ">||</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 255); ">in</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 0); ">&gt;</span><span style="font-family: 'Courier New'; color: rgb(128, 0, 0); ">'</span><span style="font-family: 'Courier New'; color: rgb(128, 0, 0); ">9</span><span style="font-family: 'Courier New'; color: rgb(128, 0, 0); ">'</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 0); ">)&nbsp;</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 255); ">in</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 0); ">=</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 0); ">getchar();<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;num</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 0); ">=</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 255); ">in</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 0); ">-</span><span style="font-family: 'Courier New'; color: rgb(128, 0, 0); ">'</span><span style="font-family: 'Courier New'; color: rgb(128, 0, 0); ">0</span><span style="font-family: 'Courier New'; color: rgb(128, 0, 0); ">'</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 0); ">;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 255); ">while</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 0); ">(</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 255); ">in</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 0); ">=</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 0); ">getchar(),</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 255); ">in</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 0); ">&gt;=</span><span style="font-family: 'Courier New'; color: rgb(128, 0, 0); ">'</span><span style="font-family: 'Courier New'; color: rgb(128, 0, 0); ">0</span><span style="font-family: 'Courier New'; color: rgb(128, 0, 0); ">'</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 0); ">&amp;&amp;</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 255); ">in</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 0); ">&lt;=</span><span style="font-family: 'Courier New'; color: rgb(128, 0, 0); ">'</span><span style="font-family: 'Courier New'; color: rgb(128, 0, 0); ">9</span><span style="font-family: 'Courier New'; color: rgb(128, 0, 0); ">'</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 0); ">){<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;num</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 0); ">*=</span><span style="font-family: 'Courier New'; color: rgb(128, 0, 128); ">10</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 0); ">,num</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 0); ">+=</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 255); ">in</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 0); ">-</span><span style="font-family: 'Courier New'; color: rgb(128, 0, 0); ">'</span><span style="font-family: 'Courier New'; color: rgb(128, 0, 0); ">0</span><span style="font-family: 'Courier New'; color: rgb(128, 0, 0); ">'</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 0); ">;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 255); ">return</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 0); ">&nbsp;</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 255); ">true</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 0); ">;<br>}<br></span><span style="font-family: 'Courier New'; color: rgb(0, 0, 255); ">int</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 0); ">&nbsp;main&nbsp;(&nbsp;</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 255); ">int</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 0); ">&nbsp;T,&nbsp;</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 255); ">int</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 0); ">&nbsp;N&nbsp;)<br>{<br>&nbsp;&nbsp;&nbsp;&nbsp;scan_ud&nbsp;(&nbsp;T&nbsp;);<br>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 255); ">for</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 0); ">&nbsp;(&nbsp;</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 255); ">int</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 0); ">&nbsp;ca&nbsp;</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 0); ">=</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 0); ">&nbsp;</span><span style="font-family: 'Courier New'; color: rgb(128, 0, 128); ">1</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 0); ">;&nbsp;ca&nbsp;</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 0); ">&lt;=</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 0); ">&nbsp;T&nbsp;;&nbsp;</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 0); ">++</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 0); ">&nbsp;ca&nbsp;){<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;printf&nbsp;(&nbsp;</span><span style="font-family: 'Courier New'; color: rgb(128, 0, 0); ">"</span><span style="font-family: 'Courier New'; color: rgb(128, 0, 0); ">Case&nbsp;%d:\n</span><span style="font-family: 'Courier New'; color: rgb(128, 0, 0); ">"</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 0); ">,ca&nbsp;);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;scan_ud&nbsp;(&nbsp;N&nbsp;);&nbsp;&nbsp;&nbsp;&nbsp;OPT&nbsp;opt;&nbsp;&nbsp;L&nbsp;</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 0); ">*</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 0); ">root&nbsp;</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 0); ">=</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 0); ">&nbsp;</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 255); ">new</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 0); ">&nbsp;L;&nbsp;&nbsp;&nbsp;</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 255); ">int</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 0); ">&nbsp;val,x,y;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;opt.Creat&nbsp;(&nbsp;root,&nbsp;</span><span style="font-family: 'Courier New'; color: rgb(128, 0, 128); ">1</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 0); ">,&nbsp;N&nbsp;);&nbsp;&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 255); ">for</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 0); ">&nbsp;(&nbsp;</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 255); ">int</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 0); ">&nbsp;i&nbsp;</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 0); ">=</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 0); ">&nbsp;</span><span style="font-family: 'Courier New'; color: rgb(128, 0, 128); ">1</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 0); ">;&nbsp;i&nbsp;</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 0); ">&lt;=</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 0); ">&nbsp;N;&nbsp;</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 0); ">++</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 0); ">&nbsp;i&nbsp;){<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;scan_ud&nbsp;(&nbsp;val&nbsp;);&nbsp;&nbsp;opt.modify&nbsp;(&nbsp;root,&nbsp;i,&nbsp;val&nbsp;);&nbsp;&nbsp;&nbsp;&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 255); ">char</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 0); ">&nbsp;ask[</span><span style="font-family: 'Courier New'; color: rgb(128, 0, 128); ">10</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 0); ">];&nbsp;&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 255); ">while</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 0); ">&nbsp;(&nbsp;scanf&nbsp;(&nbsp;</span><span style="font-family: 'Courier New'; color: rgb(128, 0, 0); ">"</span><span style="font-family: 'Courier New'; color: rgb(128, 0, 0); ">%s</span><span style="font-family: 'Courier New'; color: rgb(128, 0, 0); ">"</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 0); ">,&nbsp;ask&nbsp;),&nbsp;ask[</span><span style="font-family: 'Courier New'; color: rgb(128, 0, 128); ">0</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 0); ">]&nbsp;</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 0); ">!=</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 0); ">&nbsp;</span><span style="font-family: 'Courier New'; color: rgb(128, 0, 0); ">'</span><span style="font-family: 'Courier New'; color: rgb(128, 0, 0); ">E</span><span style="font-family: 'Courier New'; color: rgb(128, 0, 0); ">'</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 0); ">&nbsp;){<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;scanf&nbsp;(&nbsp;</span><span style="font-family: 'Courier New'; color: rgb(128, 0, 0); ">"</span><span style="font-family: 'Courier New'; color: rgb(128, 0, 0); ">%d%d</span><span style="font-family: 'Courier New'; color: rgb(128, 0, 0); ">"</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 0); ">,</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 0); ">&amp;</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 0); ">x,</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 0); ">&amp;</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 0); ">y&nbsp;);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 255); ">switch</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 0); ">&nbsp;(&nbsp;ask[</span><span style="font-family: 'Courier New'; color: rgb(128, 0, 128); ">0</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 0); ">]&nbsp;){<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 255); ">case</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 0); ">&nbsp;</span><span style="font-family: 'Courier New'; color: rgb(128, 0, 0); ">'</span><span style="font-family: 'Courier New'; color: rgb(128, 0, 0); ">Q</span><span style="font-family: 'Courier New'; color: rgb(128, 0, 0); ">'</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 0); ">:&nbsp;&nbsp;printf&nbsp;(&nbsp;</span><span style="font-family: 'Courier New'; color: rgb(128, 0, 0); ">"</span><span style="font-family: 'Courier New'; color: rgb(128, 0, 0); ">%d\n</span><span style="font-family: 'Courier New'; color: rgb(128, 0, 0); ">"</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 0); ">,opt.quy&nbsp;(&nbsp;root,&nbsp;x,y&nbsp;)&nbsp;);&nbsp;</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 255); ">break</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 0); ">;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 255); ">case</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 0); ">&nbsp;</span><span style="font-family: 'Courier New'; color: rgb(128, 0, 0); ">'</span><span style="font-family: 'Courier New'; color: rgb(128, 0, 0); ">A</span><span style="font-family: 'Courier New'; color: rgb(128, 0, 0); ">'</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 0); ">:&nbsp;&nbsp;opt.modify&nbsp;(&nbsp;root,&nbsp;x,&nbsp;y&nbsp;);&nbsp;</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 255); ">break</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 0); ">;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 255); ">case</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 0); ">&nbsp;</span><span style="font-family: 'Courier New'; color: rgb(128, 0, 0); ">'</span><span style="font-family: 'Courier New'; color: rgb(128, 0, 0); ">S</span><span style="font-family: 'Courier New'; color: rgb(128, 0, 0); ">'</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 0); ">:&nbsp;&nbsp;opt.modify&nbsp;(&nbsp;root,&nbsp;x,&nbsp;</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 0); ">-</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 0); ">y&nbsp;);&nbsp;</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 255); ">break</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 0); ">;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br>&nbsp;&nbsp;&nbsp;&nbsp;}<br>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 255); ">return</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 0); ">&nbsp;</span><span style="font-family: 'Courier New'; color: rgb(128, 0, 128); ">0</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 0); ">;<br>}<br></span></div></div></div><p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; font-family: verdana, 'courier new'; font-size: 14px; line-height: 21px; ">&nbsp;</p><p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; font-family: verdana, 'courier new'; font-size: 14px; line-height: 21px; ">&nbsp;</p><img src ="http://www.cppblog.com/MiYu/aggbug/125867.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/MiYu/" target="_blank">MiYu</a> 2010-09-04 12:53 <a href="http://www.cppblog.com/MiYu/archive/2010/09/04/125867.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>