﻿<?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/14734.html</link><description>                             ______________白白の屋</description><language>zh-cn</language><lastBuildDate>Sun, 14 Nov 2010 20:34:51 GMT</lastBuildDate><pubDate>Sun, 14 Nov 2010 20:34:51 GMT</pubDate><ttl>60</ttl><item><title>HDU 3584 HDOJ 3584 Cube  ACM 3584 IN HDU</title><link>http://www.cppblog.com/MiYu/archive/2010/11/14/133577.html</link><dc:creator>MiYu</dc:creator><author>MiYu</author><pubDate>Sun, 14 Nov 2010 02:35:00 GMT</pubDate><guid>http://www.cppblog.com/MiYu/archive/2010/11/14/133577.html</guid><wfw:comment>http://www.cppblog.com/MiYu/comments/133577.html</wfw:comment><comments>http://www.cppblog.com/MiYu/archive/2010/11/14/133577.html#Feedback</comments><slash:comments>1</slash:comments><wfw:commentRss>http://www.cppblog.com/MiYu/comments/commentRss/133577.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/MiYu/services/trackbacks/133577.html</trackback:ping><description><![CDATA[
<span style="font-family: verdana, 'courier new'; font-size: 14px; line-height: 21px; "><p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; ">MiYu原创, 转帖请注明 : 转载自&nbsp;<a href="http://baiyun.me/"><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><span style="font-family: 'Times New Roman'; line-height: normal; font-size: medium; "><h1 style="color: rgb(26, 92, 200); text-align: center; ">Cube</h1><font><strong><span style="font-family: Arial; font-size: 12px; font-weight: bold; color: green; ">Time Limit: 2000/1000 MS (Java/Others)&nbsp;&nbsp;&nbsp;&nbsp;Memory Limit: 131072/65536 K (Java/Others)<br>Total Submission(s): 495&nbsp;&nbsp;&nbsp;&nbsp;Accepted Submission(s): 226<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; ">Given an N*N*N cube A, whose elements are either 0 or 1. A[i, j, k] means the number in the i-th row , j-th column and k-th layer. Initially we have A[i, j, k] = 0 (1 &lt;= i, j, k &lt;= N).&nbsp;<br>We define two operations, 1: &#8220;Not&#8221; operation that we change the A[i, j, k]=!A[i, j, k]. that means we change A[i, j, k] from 0-&gt;1,or 1-&gt;0. (x1&lt;=i&lt;=x2,y1&lt;=j&lt;=y2,z1&lt;=k&lt;=z2).<br>0: &#8220;Query&#8221; operation we want to get the value of A[i, j, k].<br></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; ">Multi-cases.<br>First line contains N and M, M lines follow indicating the operation below.<br>Each operation contains an X, the type of operation. 1: &#8220;Not&#8221; operation and 0: &#8220;Query&#8221; operation.<br>If X is 1, following x1, y1, z1, x2, y2, z2.<br>If X is 0, following x, y, z.<br></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 query output A[x, y, z] in one line. (1&lt;=n&lt;=100 sum of m &lt;=10000)</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; ">2 5
1 1 1 1  1 1 1
0 1 1 1
1 1 1 1  2 2 2
0 1 1 1
0 2 2 2</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
0
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></span><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; &nbsp;更新区间, 查询一个点, 三维线段树 直接无视.........数据不是很强, 所以 直接暴力就可以过, 过完发现自己的时间 在700MS 左右, 看了下rank,</p><p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; ">小A 榜首..... 时间竟然才62MS<img src="http://www.cnblogs.com/Emoticons/baimantou/134950312.gif">....果然还是要用三维树状数组来加速啊 . 不过一直没理解 用 树状数组 解决这题的思路, 今早上终于明白了<img src="http://www.cnblogs.com/Emoticons/baimantou/22571567.gif">.</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; &nbsp; &nbsp; &nbsp; &nbsp;<img src="http://www.cnblogs.com/images/cnblogs_com/miyu/HDU_3485.JPG" width="422" height="193" alt="">&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; ">树状数组代码 :</p><p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; ">&nbsp;<span style="font-family: 'Courier New'; line-height: normal; font-size: 12px; color: rgb(0, 128, 0); white-space: pre; ">/*</span></p><span style="font-family: 'Times New Roman'; line-height: normal; font-size: 12px; "><div style="padding-top: 10px; padding-right: 10px; padding-bottom: 10px; padding-left: 10px; "><pre style="font-family: 'Courier New'; text-align: left; "><font color="green">Mail to   : miyubai@gamil.com
My Blog   : www.baiyun.me
Link      : http://www.cnblogs.com/MiYu  || http://www.cppblog.com/MiYu
Author By : MiYu
Test      : 1
Complier  : g++ mingw32-3.4.2
Program   : HDU_3584
Doc Name  : Cube
*/</font><font color="green">
//#pragma warning( disable:4789 )
</font><font color="blue">#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;
</font><strong><font color="#0000FF">using namespace</font></strong> std<strong><font color="#FF00FF">;</font></strong><strong><font color="#0000FF">
inline</font></strong><strong><font color="blue"> bool</font></strong> scan_d<strong><font color="#FF00FF">(</font></strong><strong><font color="blue">int</font></strong><strong><font color="#FF00FF"> &amp;</font></strong>num<strong><font color="#FF00FF">)</font></strong><font color="green">  //整数输入
</font><strong><font color="#FF00FF">{</font></strong><strong><font color="blue">
        char</font></strong> in<strong><font color="#FF00FF">;</font></strong><strong><font color="blue">bool</font></strong> IsN<strong><font color="#FF00FF">=</font></strong><font color="#CC3300">false</font><strong><font color="#FF00FF">;</font></strong>
        in<strong><font color="#FF00FF">=</font></strong>getchar<strong><font color="#FF00FF">();</font></strong><strong><font color="#0000FF">
        if</font></strong><strong><font color="#FF00FF">(</font></strong>in<strong><font color="#FF00FF">==</font></strong>EOF<strong><font color="#FF00FF">)</font></strong><strong><font color="#0000FF"> return</font></strong><font color="#CC3300"> false</font><strong><font color="#FF00FF">;</font></strong><strong><font color="#0000FF">
        while</font></strong><strong><font color="#FF00FF">(</font></strong>in<strong><font color="#FF00FF">!=</font></strong><font color="green">'-'</font><strong><font color="#FF00FF">&amp;&amp;(</font></strong>in<strong><font color="#FF00FF">&lt;</font></strong><font color="green">'0'</font><strong><font color="#FF00FF">||</font></strong>in<strong><font color="#FF00FF">&gt;</font></strong><font color="green">'9'</font><strong><font color="#FF00FF">))</font></strong> in<strong><font color="#FF00FF">=</font></strong>getchar<strong><font color="#FF00FF">();</font></strong><strong><font color="#0000FF">
        if</font></strong><strong><font color="#FF00FF">(</font></strong>in<strong><font color="#FF00FF">==</font></strong><font color="green">'-'</font><strong><font color="#FF00FF">){</font></strong> IsN<strong><font color="#FF00FF">=</font></strong><font color="#CC3300">true</font><strong><font color="#FF00FF">;</font></strong>num<strong><font color="#FF00FF">=</font></strong><font color="#CC3300">0</font><strong><font color="#FF00FF">;}</font></strong><strong><font color="#0000FF">
        else</font></strong> num<strong><font color="#FF00FF">=</font></strong>in<strong><font color="#FF00FF">-</font></strong><font color="green">'0'</font><strong><font color="#FF00FF">;</font></strong><strong><font color="#0000FF">
        while</font></strong><strong><font color="#FF00FF">(</font></strong>in<strong><font color="#FF00FF">=</font></strong>getchar<strong><font color="#FF00FF">(),</font></strong>in<strong><font color="#FF00FF">&gt;=</font></strong><font color="green">'0'</font><strong><font color="#FF00FF">&amp;&amp;</font></strong>in<strong><font color="#FF00FF">&lt;=</font></strong><font color="green">'9'</font><strong><font color="#FF00FF">){</font></strong>
                num<strong><font color="#FF00FF">*=</font></strong><font color="#CC3300">10</font><strong><font color="#FF00FF">,</font></strong>num<strong><font color="#FF00FF">+=</font></strong>in<strong><font color="#FF00FF">-</font></strong><font color="green">'0'</font><strong><font color="#FF00FF">;
        }</font></strong><strong><font color="#0000FF">
        if</font></strong><strong><font color="#FF00FF">(</font></strong>IsN<strong><font color="#FF00FF">)</font></strong> num<strong><font color="#FF00FF">=-</font></strong>num<strong><font color="#FF00FF">;</font></strong><strong><font color="#0000FF">
        return</font></strong><font color="#CC3300"> true</font><strong><font color="#FF00FF">;
}</font></strong><strong><font color="#0000FF">
const</font></strong><strong><font color="blue"> int</font></strong> MAXN<strong><font color="#FF00FF"> =</font></strong><font color="#CC3300"> 105</font><strong><font color="#FF00FF">;</font></strong><strong><font color="blue">
int</font></strong> mat<strong><font color="#FF00FF">[</font></strong>MAXN<strong><font color="#FF00FF">][</font></strong>MAXN<strong><font color="#FF00FF">][</font></strong>MAXN<strong><font color="#FF00FF">];</font></strong><strong><font color="blue">
int</font></strong> low<strong><font color="#FF00FF">[</font></strong>MAXN<strong><font color="#FF00FF">];</font></strong><strong><font color="blue">
int</font></strong> i<strong><font color="#FF00FF">,</font></strong> j<strong><font color="#FF00FF">,</font></strong> k<strong><font color="#FF00FF">;</font></strong><strong><font color="blue">
void</font></strong> setLow<strong><font color="#FF00FF"> () {</font></strong><strong><font color="#0000FF">
     for</font></strong><strong><font color="#FF00FF"> (</font></strong> i<strong><font color="#FF00FF"> =</font></strong><font color="#CC3300"> 1</font><strong><font color="#FF00FF">;</font></strong> i<strong><font color="#FF00FF"> &lt;=</font></strong> MAXN<strong><font color="#FF00FF">; ++</font></strong> i<strong><font color="#FF00FF"> )</font></strong> low<strong><font color="#FF00FF">[</font></strong>i<strong><font color="#FF00FF">] =</font></strong> i<strong><font color="#FF00FF"> &amp; (-</font></strong> i<strong><font color="#FF00FF">);
}</font></strong><strong><font color="blue">
void</font></strong> modify<strong><font color="#FF00FF"> (</font></strong><strong><font color="blue"> int</font></strong> x<strong><font color="#FF00FF">,</font></strong><strong><font color="blue"> int</font></strong> y<strong><font color="#FF00FF">,</font></strong><strong><font color="blue"> int</font></strong> z<strong><font color="#FF00FF"> ) {</font></strong><strong><font color="#0000FF">
     for</font></strong><strong><font color="#FF00FF"> (</font></strong> i<strong><font color="#FF00FF"> =</font></strong> x<strong><font color="#FF00FF">;</font></strong> i<strong><font color="#FF00FF"> &lt;=</font></strong> MAXN<strong><font color="#FF00FF">;</font></strong> i<strong><font color="#FF00FF"> +=</font></strong> low<strong><font color="#FF00FF">[</font></strong>i<strong><font color="#FF00FF">] ) {</font></strong><strong><font color="#0000FF">
         for</font></strong><strong><font color="#FF00FF"> (</font></strong> j<strong><font color="#FF00FF"> =</font></strong> y<strong><font color="#FF00FF">;</font></strong> j<strong><font color="#FF00FF"> &lt;=</font></strong> MAXN<strong><font color="#FF00FF">;</font></strong> j<strong><font color="#FF00FF"> +=</font></strong> low<strong><font color="#FF00FF">[</font></strong>j<strong><font color="#FF00FF">] ) {</font></strong><strong><font color="#0000FF">
             for</font></strong><strong><font color="#FF00FF"> (</font></strong> k<strong><font color="#FF00FF"> =</font></strong> z<strong><font color="#FF00FF">;</font></strong> k<strong><font color="#FF00FF"> &lt;=</font></strong> MAXN<strong><font color="#FF00FF">;</font></strong> k<strong><font color="#FF00FF"> +=</font></strong> low<strong><font color="#FF00FF">[</font></strong>k<strong><font color="#FF00FF">] )</font></strong>
                 mat<strong><font color="#FF00FF">[</font></strong>i<strong><font color="#FF00FF">][</font></strong>j<strong><font color="#FF00FF">][</font></strong>k<strong><font color="#FF00FF">] ^=</font></strong><font color="#CC3300"> 1</font><strong><font color="#FF00FF">;   
         }    
     }    
}</font></strong><strong><font color="blue">
int</font></strong> query<strong><font color="#FF00FF"> (</font></strong><strong><font color="blue"> int</font></strong> x<strong><font color="#FF00FF">,</font></strong><strong><font color="blue"> int</font></strong> y<strong><font color="#FF00FF">,</font></strong><strong><font color="blue"> int</font></strong> z<strong><font color="#FF00FF"> ) {</font></strong><strong><font color="blue">
     int</font></strong> sum<strong><font color="#FF00FF"> =</font></strong><font color="#CC3300"> 0</font><strong><font color="#FF00FF">;</font></strong><strong><font color="#0000FF">
     for</font></strong><strong><font color="#FF00FF"> (</font></strong> i<strong><font color="#FF00FF"> =</font></strong> x<strong><font color="#FF00FF">;</font></strong> i<strong><font color="#FF00FF"> &gt;</font></strong><font color="#CC3300"> 0</font><strong><font color="#FF00FF">;</font></strong> i<strong><font color="#FF00FF"> ^=</font></strong> low<strong><font color="#FF00FF">[</font></strong>i<strong><font color="#FF00FF">] ) {</font></strong><strong><font color="#0000FF">
         for</font></strong><strong><font color="#FF00FF"> (</font></strong> j<strong><font color="#FF00FF"> =</font></strong> y<strong><font color="#FF00FF">;</font></strong> j<strong><font color="#FF00FF"> &gt;</font></strong><font color="#CC3300"> 0</font><strong><font color="#FF00FF">;</font></strong> j<strong><font color="#FF00FF"> ^=</font></strong> low<strong><font color="#FF00FF">[</font></strong>j<strong><font color="#FF00FF">] ) {</font></strong><strong><font color="#0000FF">
             for</font></strong><strong><font color="#FF00FF"> (</font></strong> k<strong><font color="#FF00FF"> =</font></strong> z<strong><font color="#FF00FF">;</font></strong> k<strong><font color="#FF00FF"> &gt;</font></strong><font color="#CC3300"> 0</font><strong><font color="#FF00FF">;</font></strong> k<strong><font color="#FF00FF"> ^=</font></strong> low<strong><font color="#FF00FF">[</font></strong>k<strong><font color="#FF00FF">] )</font></strong>
                 sum<strong><font color="#FF00FF"> +=</font></strong> mat<strong><font color="#FF00FF">[</font></strong>i<strong><font color="#FF00FF">][</font></strong>j<strong><font color="#FF00FF">][</font></strong>k<strong><font color="#FF00FF">];    
         }    
     }</font></strong><strong><font color="#0000FF">    
     return</font></strong> sum<strong><font color="#FF00FF"> &amp;</font></strong><font color="#CC3300"> 1</font><strong><font color="#FF00FF">;
}</font></strong><strong><font color="blue">
int</font></strong><strong><font color="#0000FF"> main</font></strong><strong><font color="#FF00FF"> ()
{</font></strong>
    setLow<strong><font color="#FF00FF"> ();</font></strong><strong><font color="blue">
    int</font></strong> N<strong><font color="#FF00FF">,</font></strong> M<strong><font color="#FF00FF">;</font></strong><strong><font color="#0000FF">
    while</font></strong><strong><font color="#FF00FF"> (</font></strong> scan_d<strong><font color="#FF00FF"> (</font></strong> N<strong><font color="#FF00FF"> ) &amp;&amp;</font></strong> scan_d<strong><font color="#FF00FF"> (</font></strong> M<strong><font color="#FF00FF"> ) ) {</font></strong>
          memset<strong><font color="#FF00FF"> (</font></strong> mat<strong><font color="#FF00FF">,</font></strong><font color="#CC3300"> 0</font><strong><font color="#FF00FF">,</font></strong><strong><font color="#0000FF"> sizeof</font></strong><strong><font color="#FF00FF"> (</font></strong> mat<strong><font color="#FF00FF"> ) );</font></strong><strong><font color="#0000FF">
          while</font></strong><strong><font color="#FF00FF"> (</font></strong> M<strong><font color="#FF00FF"> -- ) {</font></strong><strong><font color="blue">
                int</font></strong> x1<strong><font color="#FF00FF">,</font></strong>y1<strong><font color="#FF00FF">,</font></strong>z1<strong><font color="#FF00FF">,</font></strong>x2<strong><font color="#FF00FF">,</font></strong>y2<strong><font color="#FF00FF">,</font></strong>z2<strong><font color="#FF00FF">;</font></strong><strong><font color="blue">
                int</font></strong> s<strong><font color="#FF00FF">;</font></strong>  scan_d<strong><font color="#FF00FF"> (</font></strong> s<strong><font color="#FF00FF"> );</font></strong><strong><font color="#0000FF"> 
                switch</font></strong><strong><font color="#FF00FF"> (</font></strong> s<strong><font color="#FF00FF"> ) {</font></strong><strong><font color="#0000FF">
                       case</font></strong><font color="#CC3300"> 1</font><strong><font color="#FF00FF">:</font></strong>
                            scan_d<strong><font color="#FF00FF"> (</font></strong> x1<strong><font color="#FF00FF"> );</font></strong> scan_d<strong><font color="#FF00FF"> (</font></strong> y1<strong><font color="#FF00FF"> );</font></strong> scan_d<strong><font color="#FF00FF"> (</font></strong> z1<strong><font color="#FF00FF"> );</font></strong> 
                            scan_d<strong><font color="#FF00FF"> (</font></strong> x2<strong><font color="#FF00FF"> );</font></strong> scan_d<strong><font color="#FF00FF"> (</font></strong> y2<strong><font color="#FF00FF"> );</font></strong> scan_d<strong><font color="#FF00FF"> (</font></strong> z2<strong><font color="#FF00FF"> );</font></strong>
                            modify<strong><font color="#FF00FF"> (</font></strong> x1<strong><font color="#FF00FF">,</font></strong>y1<strong><font color="#FF00FF">,</font></strong>z1<strong><font color="#FF00FF"> );</font></strong>    modify<strong><font color="#FF00FF"> (</font></strong> x1<strong><font color="#FF00FF">,</font></strong>y1<strong><font color="#FF00FF">,</font></strong>z2<strong><font color="#FF00FF">+</font></strong><font color="#CC3300">1</font><strong><font color="#FF00FF"> );</font></strong>
                            modify<strong><font color="#FF00FF"> (</font></strong> x2<strong><font color="#FF00FF">+</font></strong><font color="#CC3300">1</font><strong><font color="#FF00FF">,</font></strong>y1<strong><font color="#FF00FF">,</font></strong>z1<strong><font color="#FF00FF"> );</font></strong>    modify<strong><font color="#FF00FF"> (</font></strong> x2<strong><font color="#FF00FF">+</font></strong><font color="#CC3300">1</font><strong><font color="#FF00FF">,</font></strong>y1<strong><font color="#FF00FF">,</font></strong>z2<strong><font color="#FF00FF">+</font></strong><font color="#CC3300">1</font><strong><font color="#FF00FF"> );</font></strong>
                            modify<strong><font color="#FF00FF"> (</font></strong> x1<strong><font color="#FF00FF">,</font></strong>y2<strong><font color="#FF00FF">+</font></strong><font color="#CC3300">1</font><strong><font color="#FF00FF">,</font></strong>z1<strong><font color="#FF00FF"> );</font></strong>    modify<strong><font color="#FF00FF"> (</font></strong> x2<strong><font color="#FF00FF">+</font></strong><font color="#CC3300">1</font><strong><font color="#FF00FF">,</font></strong>y2<strong><font color="#FF00FF">+</font></strong><font color="#CC3300">1</font><strong><font color="#FF00FF">,</font></strong>z1<strong><font color="#FF00FF"> );</font></strong>
                            modify<strong><font color="#FF00FF"> (</font></strong> x2<strong><font color="#FF00FF">+</font></strong><font color="#CC3300">1</font><strong><font color="#FF00FF">,</font></strong>y2<strong><font color="#FF00FF">+</font></strong><font color="#CC3300">1</font><strong><font color="#FF00FF">,</font></strong>z2<strong><font color="#FF00FF">+</font></strong><font color="#CC3300">1</font><strong><font color="#FF00FF"> );</font></strong>    modify<strong><font color="#FF00FF"> (</font></strong> x1<strong><font color="#FF00FF">,</font></strong>y2<strong><font color="#FF00FF">+</font></strong><font color="#CC3300">1</font><strong><font color="#FF00FF">,</font></strong>z2<strong><font color="#FF00FF">+</font></strong><font color="#CC3300">1</font><strong><font color="#FF00FF"> );</font></strong><strong><font color="#0000FF"> 
                            break</font></strong><strong><font color="#FF00FF">;</font></strong><strong><font color="#0000FF">
                       case</font></strong><font color="#CC3300"> 0</font><strong><font color="#FF00FF">:</font></strong>
                            scan_d<strong><font color="#FF00FF"> (</font></strong> x1<strong><font color="#FF00FF"> );</font></strong> scan_d<strong><font color="#FF00FF"> (</font></strong> y1<strong><font color="#FF00FF"> );</font></strong> scan_d<strong><font color="#FF00FF"> (</font></strong> z1<strong><font color="#FF00FF"> );</font></strong>
                            printf<strong><font color="#FF00FF"> (</font></strong><font color="green"> "%d\n"</font><strong><font color="#FF00FF">,</font></strong> query<strong><font color="#FF00FF"> (</font></strong> x1<strong><font color="#FF00FF">,</font></strong>y1<strong><font color="#FF00FF">,</font></strong>z1<strong><font color="#FF00FF"> ) );      
                }
          }           
    }</font></strong><strong><font color="#0000FF">
    return</font></strong><font color="#CC3300"> 0</font><strong><font color="#FF00FF">;
}</font></strong>
</pre><div><strong><font color="#FF00FF"><br></font></strong></div><p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; ">暴力代码 :<br></p><div style="padding-top: 10px; padding-right: 10px; padding-bottom: 10px; padding-left: 10px; "><pre style="font-family: 'Courier New'; text-align: left; "><font color="green">/*
Mail to   : miyubai@gamil.com
My Blog   : www.baiyun.me
Link      : http://www.cnblogs.com/MiYu  || http://www.cppblog.com/MiYu
Author By : MiYu
Test      : 1
Complier  : g++ mingw32-3.4.2
Program   :
Doc Name  :
*/</font><font color="green">
//#pragma warning( disable:4789 )
</font><font color="blue">#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;
</font><strong><font color="#0000FF">using namespace</font></strong> std<strong><font color="#FF00FF">;</font></strong><strong><font color="#0000FF">
struct</font></strong> node<strong><font color="#FF00FF"> {</font></strong><strong><font color="blue">  
    int</font></strong> x1<strong><font color="#FF00FF">,</font></strong> x2<strong><font color="#FF00FF">,</font></strong> y1<strong><font color="#FF00FF">,</font></strong> y2<strong><font color="#FF00FF">,</font></strong> z1<strong><font color="#FF00FF">,</font></strong> z2<strong><font color="#FF00FF">; 
}</font></strong>cube<strong><font color="#FF00FF">[</font></strong><font color="#CC3300">10010</font><strong><font color="#FF00FF">];</font></strong><strong><font color="blue">   
  
int</font></strong><strong><font color="#0000FF"> main</font></strong><strong><font color="#FF00FF">()  
{</font></strong><strong><font color="blue">  
    int</font></strong> N<strong><font color="#FF00FF">,</font></strong> M<strong><font color="#FF00FF">;</font></strong><strong><font color="blue">  
    int</font></strong> x<strong><font color="#FF00FF">,</font></strong> y<strong><font color="#FF00FF">,</font></strong> z<strong><font color="#FF00FF">;</font></strong><strong><font color="#0000FF">
    while</font></strong><strong><font color="#FF00FF"> (</font></strong> scanf<strong><font color="#FF00FF"> (</font></strong><font color="green"> "%d%d"</font><strong><font color="#FF00FF">,&amp;</font></strong>N<strong><font color="#FF00FF">,&amp;</font></strong>M<strong><font color="#FF00FF"> ) !=</font></strong> EOF<strong><font color="#FF00FF"> )  {</font></strong><strong><font color="blue">  
        int</font></strong> cnt<strong><font color="#FF00FF"> =</font></strong><font color="#CC3300"> 0</font><strong><font color="#FF00FF">;</font></strong><strong><font color="#0000FF">  
        while</font></strong><strong><font color="#FF00FF"> (</font></strong> M<strong><font color="#FF00FF"> -- )  
        {</font></strong><strong><font color="blue">  
            int</font></strong> ask<strong><font color="#FF00FF">;</font></strong>  
            scanf<strong><font color="#FF00FF"> (</font></strong><font color="green"> "%d"</font><strong><font color="#FF00FF">, &amp;</font></strong>ask<strong><font color="#FF00FF"> );</font></strong><strong><font color="#0000FF">  
            switch</font></strong><strong><font color="#FF00FF"> (</font></strong> ask<strong><font color="#FF00FF"> ) {</font></strong><strong><font color="#0000FF">
                case</font></strong><font color="#CC3300"> 1</font><strong><font color="#FF00FF">:</font></strong>   
                    scanf<strong><font color="#FF00FF"> (</font></strong><font color="green"> "%d%d%d%d%d%d"</font><strong><font color="#FF00FF">, &amp;</font></strong>cube<strong><font color="#FF00FF">[</font></strong>cnt<strong><font color="#FF00FF">].</font></strong>x1<strong><font color="#FF00FF">,&amp;</font></strong>cube<strong><font color="#FF00FF">[</font></strong>cnt<strong><font color="#FF00FF">].</font></strong>y1<strong><font color="#FF00FF">,
                                            &amp;</font></strong>cube<strong><font color="#FF00FF">[</font></strong>cnt<strong><font color="#FF00FF">].</font></strong>z1<strong><font color="#FF00FF">,&amp;</font></strong>cube<strong><font color="#FF00FF">[</font></strong>cnt<strong><font color="#FF00FF">].</font></strong>x2<strong><font color="#FF00FF">,
                                            &amp;</font></strong>cube<strong><font color="#FF00FF">[</font></strong>cnt<strong><font color="#FF00FF">].</font></strong>y2<strong><font color="#FF00FF">,&amp;</font></strong>cube<strong><font color="#FF00FF">[</font></strong>cnt<strong><font color="#FF00FF">].</font></strong>z2<strong><font color="#FF00FF"> );  
                    ++</font></strong> cnt<strong><font color="#FF00FF">;</font></strong><strong><font color="#0000FF">  
                    break</font></strong><strong><font color="#FF00FF">;</font></strong><strong><font color="#0000FF">
                case</font></strong><font color="#CC3300"> 0</font><strong><font color="#FF00FF">:</font></strong>
                    scanf<strong><font color="#FF00FF"> (</font></strong><font color="green"> "%d%d%d"</font><strong><font color="#FF00FF">, &amp;</font></strong>x<strong><font color="#FF00FF">, &amp;</font></strong>y<strong><font color="#FF00FF">, &amp;</font></strong>z<strong><font color="#FF00FF">);</font></strong><strong><font color="blue">  
                    int</font></strong> count<strong><font color="#FF00FF"> =</font></strong><font color="#CC3300"> 0</font><strong><font color="#FF00FF">;</font></strong><strong><font color="#0000FF">  
                    for</font></strong><strong><font color="#FF00FF"> (</font></strong><strong><font color="blue"> int</font></strong> i<strong><font color="#FF00FF"> =</font></strong><font color="#CC3300"> 0</font><strong><font color="#FF00FF">;</font></strong> i<strong><font color="#FF00FF"> !=</font></strong> cnt<strong><font color="#FF00FF">; ++</font></strong> i<strong><font color="#FF00FF"> )</font></strong><strong><font color="#0000FF">  
                        if</font></strong><strong><font color="#FF00FF"> (</font></strong> cube<strong><font color="#FF00FF">[</font></strong>i<strong><font color="#FF00FF">].</font></strong>x1<strong><font color="#FF00FF"> &lt;=</font></strong> x<strong><font color="#FF00FF"> &amp;&amp;</font></strong> x<strong><font color="#FF00FF"> &lt;=</font></strong> cube<strong><font color="#FF00FF">[</font></strong>i<strong><font color="#FF00FF">].</font></strong>x2<strong><font color="#FF00FF"> &amp;&amp;</font></strong> 
                             cube<strong><font color="#FF00FF">[</font></strong>i<strong><font color="#FF00FF">].</font></strong>y1<strong><font color="#FF00FF"> &lt;=</font></strong> y<strong><font color="#FF00FF"> &amp;&amp;</font></strong> y<strong><font color="#FF00FF"> &lt;=</font></strong> cube<strong><font color="#FF00FF">[</font></strong>i<strong><font color="#FF00FF">].</font></strong>y2<strong><font color="#FF00FF"> &amp;&amp;</font></strong> 
                             cube<strong><font color="#FF00FF">[</font></strong>i<strong><font color="#FF00FF">].</font></strong>z1<strong><font color="#FF00FF"> &lt;=</font></strong> z<strong><font color="#FF00FF"> &amp;&amp;</font></strong> z<strong><font color="#FF00FF"> &lt;=</font></strong> cube<strong><font color="#FF00FF">[</font></strong>i<strong><font color="#FF00FF">].</font></strong>z2<strong><font color="#FF00FF"> )</font></strong>  
                                    count<strong><font color="#FF00FF"> ^=</font></strong><font color="#CC3300"> 1</font><strong><font color="#FF00FF">;;</font></strong>  
                    puts<strong><font color="#FF00FF"> (</font></strong> count<strong><font color="#FF00FF"> ?</font></strong><font color="green"> "1"</font><strong><font color="#FF00FF"> :</font></strong><font color="green"> "0"</font><strong><font color="#FF00FF"> ); 
            }  
        }  
    }</font></strong><strong><font color="#0000FF">  
    return</font></strong><font color="#CC3300"> 0</font><strong><font color="#FF00FF">;  
}</font></strong>  
</pre></div><p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; ">&nbsp;</p></div></span></span><img src ="http://www.cppblog.com/MiYu/aggbug/133577.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-14 10:35 <a href="http://www.cppblog.com/MiYu/archive/2010/11/14/133577.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>树状数组 （Binary Indexed Trees ）论文解析</title><link>http://www.cppblog.com/MiYu/archive/2010/10/29/131711.html</link><dc:creator>MiYu</dc:creator><author>MiYu</author><pubDate>Fri, 29 Oct 2010 01:47:00 GMT</pubDate><guid>http://www.cppblog.com/MiYu/archive/2010/10/29/131711.html</guid><wfw:comment>http://www.cppblog.com/MiYu/comments/131711.html</wfw:comment><comments>http://www.cppblog.com/MiYu/archive/2010/10/29/131711.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/MiYu/comments/commentRss/131711.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/MiYu/services/trackbacks/131711.html</trackback:ping><description><![CDATA[&nbsp;&nbsp;&nbsp;&nbsp; 摘要: By&nbsp;boba5551TopCoder MemberIntroductionWe often need some sort of data structure to make our algorithms faster. In this article we willdiscuss the&nbsp;Binary Indexed Trees&nbsp;structure. Accordi...&nbsp;&nbsp;<a href='http://www.cppblog.com/MiYu/archive/2010/10/29/131711.html'>阅读全文</a><img src ="http://www.cppblog.com/MiYu/aggbug/131711.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-29 09:47 <a href="http://www.cppblog.com/MiYu/archive/2010/10/29/131711.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>HDU 2689 HDOJ 2689 Sort it ACM 2689 IN HDU </title><link>http://www.cppblog.com/MiYu/archive/2010/10/27/131506.html</link><dc:creator>MiYu</dc:creator><author>MiYu</author><pubDate>Wed, 27 Oct 2010 07:23:00 GMT</pubDate><guid>http://www.cppblog.com/MiYu/archive/2010/10/27/131506.html</guid><wfw:comment>http://www.cppblog.com/MiYu/comments/131506.html</wfw:comment><comments>http://www.cppblog.com/MiYu/archive/2010/10/27/131506.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/MiYu/comments/commentRss/131506.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/MiYu/services/trackbacks/131506.html</trackback:ping><description><![CDATA[<span  style="font-family: verdana, 'courier new'; font-size: 14px; line-height: 21px; "><p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; ">MiYu原创, 转帖请注明 : 转载自&nbsp;<a href="http://baiyun.me/"><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; ">题目地址 :</p><p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href="http://acm.hdu.edu.cn/showproblem.php?pid=2689">&nbsp;http://acm.hdu.edu.cn/showproblem.php?pid=2689&nbsp;</a></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;当然也可以求逆序数来解决问题, 下面是2份 代码:</p><p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; ">&nbsp;</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; "><img src="http://images.cnblogs.com/OutliningIndicators/ExpandedBlockStart.gif" class="code_img_opened" id="code_img_opened_088c1207-98d6-4d06-b962-93bbb10457cb" 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_088c1207-98d6-4d06-b962-93bbb10457cb"><div><span style="font-family: 'Courier New'; color: rgb(0, 128, 0); ">//</span><span style="font-family: 'Courier New'; color: rgb(0, 128, 0); ">直接冒泡排序求交换的次数</span><span style="font-family: 'Courier New'; color: rgb(0, 128, 0); "><br>/*</span><span style="font-family: 'Courier New'; color: rgb(0, 128, 0); "><br>Mail&nbsp;to&nbsp;&nbsp;&nbsp;:&nbsp;miyubai@gamil.com<br>My&nbsp;Blog&nbsp;&nbsp;&nbsp;:&nbsp;www.baiyun.me<br>Link&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:&nbsp;</span><span style="font-family: 'Courier New'; color: rgb(0, 128, 0); text-decoration: underline; ">http://www.cnblogs.com/MiYu</span><span style="font-family: 'Courier New'; color: rgb(0, 128, 0); ">&nbsp;&nbsp;||&nbsp;</span><span style="font-family: 'Courier New'; color: rgb(0, 128, 0); text-decoration: underline; ">http://www.cppblog.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;1<br>Complier&nbsp;&nbsp;:&nbsp;g++&nbsp;mingw32-3.4.2<br>Program&nbsp;&nbsp;&nbsp;:&nbsp;HDU_2689<br>Doc&nbsp;Name&nbsp;&nbsp;:&nbsp;Sort&nbsp;it<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></span><span style="font-family: 'Courier New'; color: rgb(0, 128, 0); ">//</span><span style="font-family: 'Courier New'; color: rgb(0, 128, 0); ">#pragma&nbsp;warning(&nbsp;disable:4789&nbsp;)</span><span style="font-family: 'Courier New'; color: rgb(0, 128, 0); "><br></span><span style="font-family: 'Courier New'; color: rgb(0, 0, 0); ">#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); ">fstream</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); ">sstream</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>#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, 255); ">string</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, 255); ">set</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); ">map</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); ">utility</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); ">queue</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); ">stack</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); ">list</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); ">vector</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); ">cstdio</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); ">cstdlib</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); ">cstring</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); ">cmath</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); ">ctime</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></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;num[</span><span style="font-family: 'Courier New'; color: rgb(128, 0, 128); ">1010</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 0); ">];<br>inline&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;swap&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;</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); ">a,&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;</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); ">b&nbsp;)&nbsp;{<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;a&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;b&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;a&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;b;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&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;bouble&nbsp;()&nbsp;{<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); ">;<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;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); ">0</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;)&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;j&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;j&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;</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;j&nbsp;)&nbsp;{<br>&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); ">if</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 0); ">&nbsp;(&nbsp;num[j</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); ">]&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;num[j]&nbsp;)&nbsp;{<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;swap&nbsp;(&nbsp;num[j</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); ">],&nbsp;num[j]&nbsp;);<br>&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, 0); ">++</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 0); ">&nbsp;sum;<br>&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;}&nbsp;&nbsp;&nbsp;&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;}&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;sum;<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;print&nbsp;()&nbsp;{<br>&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); ">0</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;cout&nbsp;</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 0); ">&lt;&lt;</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 0); ">&nbsp;num[i]&nbsp;</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 0); ">&lt;&lt;</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); ">&nbsp;</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;cout&nbsp;</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 0); ">&lt;&lt;</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 0); ">&nbsp;endl;&nbsp;&nbsp;&nbsp;&nbsp;&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;main&nbsp;()<br>{<br>&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); ">%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); ">,&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); ">N&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;</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;)&nbsp;{<br>&nbsp;&nbsp;&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); ">0</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;)&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</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;num&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;);&nbsp;&nbsp;&nbsp;&nbsp;<br>&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;&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); ">,bouble&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); ">//</span><span style="font-family: 'Courier New'; color: rgb(0, 128, 0); ">&nbsp;print&nbsp;();</span><span style="font-family: 'Courier New'; color: rgb(0, 128, 0); "><br></span><span style="font-family: 'Courier New'; color: rgb(0, 0, 0); ">&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><br></span><span style="font-family: 'Courier New'; color: rgb(0, 128, 0); ">//</span><span style="font-family: 'Courier New'; color: rgb(0, 128, 0); ">树状数组求逆序数法</span><span style="font-family: 'Courier New'; color: rgb(0, 128, 0); "><br>/*</span><span style="font-family: 'Courier New'; color: rgb(0, 128, 0); "><br>Mail&nbsp;to&nbsp;&nbsp;&nbsp;:&nbsp;miyubai@gamil.com<br>My&nbsp;Blog&nbsp;&nbsp;&nbsp;:&nbsp;www.baiyun.me<br>Link&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:&nbsp;</span><span style="font-family: 'Courier New'; color: rgb(0, 128, 0); text-decoration: underline; ">http://www.cnblogs.com/MiYu</span><span style="font-family: 'Courier New'; color: rgb(0, 128, 0); ">&nbsp;&nbsp;||&nbsp;</span><span style="font-family: 'Courier New'; color: rgb(0, 128, 0); text-decoration: underline; ">http://www.cppblog.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;1<br>Complier&nbsp;&nbsp;:&nbsp;g++&nbsp;mingw32-3.4.2<br>Program&nbsp;&nbsp;&nbsp;:&nbsp;HDU_2689<br>Doc&nbsp;Name&nbsp;&nbsp;:&nbsp;Sort&nbsp;it<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></span><span style="font-family: 'Courier New'; color: rgb(0, 128, 0); ">//</span><span style="font-family: 'Courier New'; color: rgb(0, 128, 0); ">#pragma&nbsp;warning(&nbsp;disable:4789&nbsp;)</span><span style="font-family: 'Courier New'; color: rgb(0, 128, 0); "><br></span><span style="font-family: 'Courier New'; color: rgb(0, 0, 0); ">#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); ">fstream</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); ">sstream</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>#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, 255); ">string</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, 255); ">set</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); ">map</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); ">utility</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); ">queue</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); ">stack</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); ">list</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); ">vector</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); ">cstdio</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); ">cstdlib</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); ">cstring</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); ">cmath</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); ">ctime</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></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,val,num[</span><span style="font-family: 'Courier New'; color: rgb(128, 0, 128); ">1010</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 0); ">],low[</span><span style="font-family: 'Courier New'; color: rgb(128, 0, 128); ">1010</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); ">void</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 0); ">&nbsp;init&nbsp;()&nbsp;{<br>&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); ">0</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;</span><span style="font-family: 'Courier New'; color: rgb(128, 0, 128); ">1010</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;i&nbsp;)&nbsp;{<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;low[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;i&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); ">&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); ">i&nbsp;);&nbsp;&nbsp;&nbsp;&nbsp;<br>&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;modify&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;x&nbsp;)&nbsp;{<br>&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;x&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;)&nbsp;{<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&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;num[x];&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&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); ">&nbsp;low[x];<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;&nbsp;&nbsp;&nbsp;&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;query&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;x&nbsp;)&nbsp;{<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); ">;<br>&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;x&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;</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;{<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&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;num[x];<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&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); ">&nbsp;low[x];&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;}&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;sum;<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;()<br>{<br>&nbsp;&nbsp;&nbsp;&nbsp;init&nbsp;();<br>&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); ">%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); ">,&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); ">N&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;</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;)&nbsp;{<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;memset&nbsp;(&nbsp;num,&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;</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 255); ">sizeof</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 0); ">&nbsp;(&nbsp;num&nbsp;)&nbsp;);&nbsp;&nbsp;<br>&nbsp;&nbsp;&nbsp;&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;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); ">;<br>&nbsp;&nbsp;&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); ">0</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;)&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</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, 0); ">&amp;</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 0); ">val&nbsp;);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;modify&nbsp;(&nbsp;val&nbsp;);&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&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;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;query&nbsp;(&nbsp;val&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;);&nbsp;&nbsp;&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;&nbsp;<br>&nbsp;&nbsp;&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); ">%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); ">,&nbsp;sum&nbsp;);<br>&nbsp;&nbsp;&nbsp;&nbsp;}<br>&nbsp;&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>}</span></div></div></div><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></span>
<img src ="http://www.cppblog.com/MiYu/aggbug/131506.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-27 15:23 <a href="http://www.cppblog.com/MiYu/archive/2010/10/27/131506.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><item><title>HDOJ 2688 HDU 2688 Rotate ACM 2688 IN HDU</title><link>http://www.cppblog.com/MiYu/archive/2010/08/30/125283.html</link><dc:creator>MiYu</dc:creator><author>MiYu</author><pubDate>Mon, 30 Aug 2010 08:18:00 GMT</pubDate><guid>http://www.cppblog.com/MiYu/archive/2010/08/30/125283.html</guid><wfw:comment>http://www.cppblog.com/MiYu/comments/125283.html</wfw:comment><comments>http://www.cppblog.com/MiYu/archive/2010/08/30/125283.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/MiYu/comments/commentRss/125283.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/MiYu/services/trackbacks/125283.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;&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://acm.hdu.edu.cn/showproblem.php?pid=2688">http://acm.hdu.edu.cn/showproblem.php?pid=2688</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; "><span class="Apple-tab-span" style="white-space: pre; "></span></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 id="cnblogs_code_open_893d025d-eb91-47ce-b372-a104db456f21"><div><span style="font-family: 'Courier New'; color: rgb(0, 0, 0); "><font  size="4"><span  style="font-family: 'Times New Roman'; font-size: medium; line-height: normal; "><h1 style="color: rgb(26, 92, 200); text-align: center; ">Rotate</h1><font><strong><span style="font-family: Arial; font-size: 12px; font-weight: bold; color: green; ">Time Limit: 2000/1000 MS (Java/Others)&nbsp;&nbsp;&nbsp;&nbsp;Memory Limit: 32768/32768 K (Java/Others)<br>Total Submission(s): 250&nbsp;&nbsp;&nbsp;&nbsp;Accepted Submission(s): 68<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; ">Recently yifenfei face such a problem that give you millions of positive integers,tell how many pairs i and j that satisfy F[i] smaller than F[j] strictly when i is smaller than j strictly. i and j is the serial number in the interger sequence. Of course, the problem is not over, the initial interger sequence will change all the time. Changing format is like this [S E] (abs(E-S)&lt;=1000) that mean between the S and E of the sequece will Rotate one times.<br>For example initial sequence is 1 2 3 4 5.<br>If changing format is [1 3], than the sequence will be 1 3 4 2 5 because the first sequence is base from 0.<br></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; ">The input contains multiple test cases.<br>Each case first given a integer n standing the length of integer sequence (2&lt;=n&lt;=3000000)&nbsp;<br>Second a line with n integers standing F[i](0&lt;F[i]&lt;=10000)<br>Third a line with one integer m (m &lt; 10000)<br>Than m lines quiry, first give the type of quiry. A character C, if C is &#8216;R&#8217; than give the changing format, if C equal to &#8216;Q&#8217;, just put the numbers of satisfy pairs.<br></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; ">Output just according to said.</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; ">5
1 2 3 4 5
3
Q
R 1 3
Q</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; ">10
8</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; "><span class="Apple-tab-span" style="font-family: 'Courier New'; white-space: pre; ">	</span>如果是暴力 , 没一次更新都要重新计算的话, &nbsp;时间上的开销会非常大.</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>对数据进行分析,可以看到, 当旋转的时候, 除了 第一个数, 其他的数的对数的个数值都与这个数有关, &nbsp; 因此, 只要开始</p><p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; ">先把总的对数 sum 算出来, 再 根据旋转时 每个数跟第一个数的大小 比较 ,对sum 进行更新就可以了.</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><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; "><img src="http://images.cnblogs.com/OutliningIndicators/ExpandedBlockStart.gif" class="code_img_opened" id="code_img_opened_1c302009-a3a9-495f-a7c0-be4b8a811956" 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_1c302009-a3a9-495f-a7c0-be4b8a811956"><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;1<br>Program&nbsp;&nbsp;&nbsp;:&nbsp;2688<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></span><span style="font-family: 'Courier New'; color: rgb(0, 0, 255); ">const</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); ">int</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 0); ">&nbsp;MAX&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); ">10000</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); ">int</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 0); ">&nbsp;nCount&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;N,&nbsp;M,&nbsp;x&nbsp;,&nbsp;y;<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;com[MAX&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;num[</span><span style="font-family: 'Courier New'; color: rgb(128, 0, 128); ">300</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;MAX&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;<br></span><span style="font-family: 'Courier New'; color: rgb(0, 0, 255); ">long</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); ">long</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;<br></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); ">5</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 0); ">];<br>inline&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;low&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;x&nbsp;)&nbsp;{<br>&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;x&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); ">&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); ">x&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;modify&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;x,&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;){&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="font-family: 'Courier New'; color: rgb(0, 128, 0); ">//</span><span style="font-family: 'Courier New'; color: rgb(0, 128, 0); ">&nbsp;修改&nbsp;</span><span style="font-family: 'Courier New'; color: rgb(0, 128, 0); "><br></span><span style="font-family: 'Courier New'; color: rgb(0, 0, 0); ">&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;x&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;MAX&nbsp;){<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;com[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); ">&nbsp;val;&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); ">&nbsp;low&nbsp;(&nbsp;x&nbsp;);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;&nbsp;&nbsp;&nbsp;&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;quy&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;x&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, 128, 0); ">//</span><span style="font-family: 'Courier New'; color: rgb(0, 128, 0); ">&nbsp;查询&nbsp;</span><span style="font-family: 'Courier New'; color: rgb(0, 128, 0); "><br></span><span style="font-family: 'Courier New'; color: rgb(0, 0, 0); ">&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); ">;<br>&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;x&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;</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;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;com[x];&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); ">&nbsp;low&nbsp;(&nbsp;x&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;sum&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_d(</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;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="font-family: 'Courier New'; color: rgb(0, 128, 0); ">//</span><span style="font-family: 'Courier New'; color: rgb(0, 128, 0); ">&nbsp;输入&nbsp;</span><span style="font-family: 'Courier New'; color: rgb(0, 128, 0); "><br></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); ">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); ">;</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;IsN</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 0); ">=</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); ">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); ">!=</span><span style="font-family: 'Courier New'; color: rgb(128, 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); ">'</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); ">(</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;</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(128, 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); ">'</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 0); ">){&nbsp;IsN</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 0); ">=</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); ">;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); ">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); ">else</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 0); ">&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); ">if</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 0); ">(IsN)&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, 0); ">num;<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;()<br>{<br>&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;scan_d&nbsp;(&nbsp;N&nbsp;)&nbsp;){<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;memset&nbsp;(&nbsp;com,&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;</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 255); ">sizeof</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 0); ">&nbsp;(&nbsp;com&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); ">;<br>&nbsp;&nbsp;&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); ">0</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;&nbsp;&nbsp;scan_d&nbsp;(&nbsp;num[i]&nbsp;);&nbsp;modify&nbsp;(&nbsp;num[i],&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;);&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&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;quy&nbsp;(&nbsp;num[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;);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;scan_d&nbsp;(&nbsp;M&nbsp;);<br>&nbsp;&nbsp;&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;M&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;){<br>&nbsp;&nbsp;&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); ">%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); ">,ask&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;temp;&nbsp;<br>&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); ">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;&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;cout&nbsp;</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 0); ">&lt;&lt;</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); ">&lt;&lt;</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 0); ">&nbsp;endl;&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;&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); ">R</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;scan_d&nbsp;(&nbsp;x&nbsp;),&nbsp;scan_d&nbsp;(&nbsp;y&nbsp;);&nbsp;temp&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;num[x];<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;&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;x&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;y&nbsp;)&nbsp;{&nbsp;num[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); ">&nbsp;num[x</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); ">];&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;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;num[x]&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;temp&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;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;:&nbsp;num[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); ">&nbsp;temp&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;sum</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;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); ">;&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;&nbsp;&nbsp;&nbsp;&nbsp;&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;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;num[y]&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;temp;&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;&nbsp;&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;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br>&nbsp;&nbsp;&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; "></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></span></font></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; "></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/125283.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-08-30 16:18 <a href="http://www.cppblog.com/MiYu/archive/2010/08/30/125283.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>HDOJ 3450 HDU 3450 Counting Sequences ACM 3450 IN HDU</title><link>http://www.cppblog.com/MiYu/archive/2010/08/30/125251.html</link><dc:creator>MiYu</dc:creator><author>MiYu</author><pubDate>Mon, 30 Aug 2010 01:59:00 GMT</pubDate><guid>http://www.cppblog.com/MiYu/archive/2010/08/30/125251.html</guid><wfw:comment>http://www.cppblog.com/MiYu/comments/125251.html</wfw:comment><comments>http://www.cppblog.com/MiYu/archive/2010/08/30/125251.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/MiYu/comments/commentRss/125251.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/MiYu/services/trackbacks/125251.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; ">题目地址:</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://acm.hdu.edu.cn/showproblem.php?pid=3450"><span class="Apple-tab-span" style="white-space: pre; ">http://acm.hdu.edu.cn/showproblem.php?pid=3450</span>&nbsp;</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 id="cnblogs_code_open_fb296ff0-eb92-437c-960c-72458cd53a64"><div><span style="font-family: 'Courier New'; color: rgb(0, 0, 0); "><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; ">Counting Sequences</h1><font><strong><span style="font-family: Arial; font-size: 12px; font-weight: bold; color: green; ">Time Limit: 2000/1000 MS (Java/Others)&nbsp;&nbsp;&nbsp;&nbsp;Memory Limit: 32768/65536 K (Java/Others)<br>Total Submission(s): 312&nbsp;&nbsp;&nbsp;&nbsp;Accepted Submission(s): 105<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; ">For a set of sequences of integers｛a1，a2，a3，...an｝, we define a sequence｛ai1,ai2,ai3...aik｝in which 1&lt;=i1&lt;i2&lt;i3&lt;...&lt;ik&lt;=n, as the sub-sequence of ｛a1，a2，a3，...an｝. It is quite obvious that a sequence with the length n has 2^n sub-sequences. And for a sub-sequence｛ai1,ai2,ai3...aik｝，if it matches the following qualities: k &gt;= 2, and the neighboring 2 elements have the difference not larger than d, it will be defined as a Perfect Sub-sequence. Now given an integer sequence, calculate the number of its perfect sub-sequence.<br></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; ">Multiple test cases The first line will contain 2 integers n, d（2&lt;=n&lt;=100000，1&lt;=d=&lt;=10000000） The second line n integers, representing the suquence</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; ">The number of Perfect Sub-sequences mod 9901<br></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; ">4 2
1 3 7 5</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; ">4</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; ">题目分析 :<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; "><span class="Apple-tab-span" style="font-family: 'Courier New'; white-space: pre; ">	</span>(&nbsp;线段树 || 树状数组 ) + DP&nbsp;&nbsp;</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>可以使用线段树 或 树状数组来做, &nbsp;可惜本人现在还不会线段树, 下面是 树状数组 解题的分析 :</p><p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; ">因为题目要求的 是 k &gt;= 2 , &nbsp;而且&nbsp;<span style="font-family: 'Courier New'; color: red; ">相邻元素 之差的绝对值 不大于 d</span>, &nbsp;这里纠结了很久 , 一直没明白 "<span  style="font-family: 'Courier New'; font-size: 14px; ">and the</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'; font-size: 14px; ">neighboring 2 elements have the difference not larger than d" 这句话的意思, 英语水平太差了. &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'; font-size: 14px; ">Amb 的解释下才明白, &nbsp;0rz........... &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'; font-size: 14px; ">为了使问题简单化, 我们不凡讨论 k &gt;= 1 的情况:</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>&nbsp;因为 输入数据的范围比较大, &nbsp;<span  style="font-family: 'Courier New'; font-size: 14px; ">2&lt;=n&lt;=100000，1&lt;=d=&lt;=10000000 , 所以先要将 数据排序后 用&nbsp;</span><span  style="font-family: 'Courier New'; font-size: 14px; color: red; ">hash[max]</span><span  style="font-family: 'Courier New'; font-size: 14px; ">&nbsp;做离散化处理.</span></p><p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; ">当然, 原数组需要另开一个数组保存起来. 处理完成后, &nbsp;我们可以这样理解 : &nbsp;&nbsp;用树状数组&nbsp;<span style="font-family: 'Courier New'; color: red; ">com[pos]<span  style="font-family: 'Times New Roman'; color: rgb(0, 0, 0); ">, ( pos 为 num 在 hash 数组中的位</span></span></p><p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; ">置 ) . 记录 能与 num 构成 完美串的个数. &nbsp; &nbsp;&nbsp;初始状态的 完美子串 为0, 每次加入一个数, 那么这个数 num 与 比他小且差不超过d的第一</p><p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; ">个数&nbsp;而且与 比他大且差不超过d的第一个数 &nbsp;构成完美串 . 更新树状数组. 最后求出所有的子串和 sum, &nbsp;因为算法是以 k &gt;= 1 来做的,而</p><p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; ">题目要求 k &gt;= 2, 也就是说, 对 N 个数, 就多计算了 N 次, 因此 (sum - N ) % 9901 即为所求. ( 别忘了MOD....... )</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><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"><div>/*</div><div>MiYu原创, 转帖请注明 : 转载自 ______________白白の屋</div><div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;http://www.cnblog.com/MiYu</div><div>Author By : MiYu</div><div>Test &nbsp; &nbsp; &nbsp;: 1</div><div>Program &nbsp; : 3450</div><div>*/</div><div><br></div><div>#include &lt;iostream&gt;</div><div>#include &lt;algorithm&gt;</div><div>using namespace std;</div><div>const int MAX = 100010;</div><div>const int MOD = 9901;</div><div>int nCount = 0;</div><div>int com[MAX];</div><div>int hash[MAX];</div><div>int num1[MAX];</div><div>int num2[MAX];</div><div>int N,D;</div><div>inline int low ( int x ) {</div><div>&nbsp;&nbsp; &nbsp; &nbsp; return x &amp; ( -x );</div><div>}</div><div>void modify ( int x, int val ){ &nbsp; &nbsp; // 修改&nbsp;</div><div>&nbsp;&nbsp; &nbsp; while ( x &lt;= nCount ){</div><div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;com[x] += val; x += low ( x );</div><div>&nbsp;&nbsp; &nbsp; } &nbsp; &nbsp;&nbsp;</div><div>}</div><div>int quy ( int x ){ &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// 查询&nbsp;</div><div>&nbsp;&nbsp; &nbsp;int sum = 0;</div><div>&nbsp;&nbsp; &nbsp;while ( x &gt; 0 ){</div><div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; sum += com[x]; x -= low ( x );</div><div>&nbsp;&nbsp; &nbsp;}</div><div>&nbsp;&nbsp; &nbsp;return sum ;</div><div>}</div><div>int find1 ( int val ){ &nbsp; &nbsp; &nbsp; &nbsp; // 二分 找 &lt;= val 的第一个数&nbsp;</div><div>&nbsp;&nbsp; &nbsp;int beg = 1, end = nCount; int mid = ( beg + end ) &gt;&gt; 1; int res = mid;</div><div>&nbsp;&nbsp; &nbsp;while ( beg &lt;= end ){</div><div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if ( hash[mid] &lt;= val ){</div><div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;beg = mid + 1; res = mid;</div><div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }else{</div><div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;end = mid - 1;&nbsp;</div><div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }</div><div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; mid = ( beg + end ) &gt;&gt; 1;</div><div>&nbsp;&nbsp; &nbsp;}</div><div>&nbsp;&nbsp; &nbsp;return res;</div><div>}</div><div>int find2 ( int val ){ &nbsp; &nbsp; &nbsp; &nbsp; // 二分 找 &lt;= val 的第一个数&nbsp;</div><div>&nbsp;&nbsp; &nbsp;int beg = 1, end = nCount; int mid = ( beg + end ) &gt;&gt; 1; int res = mid;</div><div>&nbsp;&nbsp; &nbsp;while ( beg &lt;= end ){</div><div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if ( hash[mid] &lt; val ){</div><div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;beg = mid + 1;</div><div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }else{</div><div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;end = mid - 1; res = mid;</div><div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }</div><div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; mid = ( beg + end ) &gt;&gt; 1;</div><div>&nbsp;&nbsp; &nbsp;}</div><div>&nbsp;&nbsp; &nbsp;return res;</div><div>}</div><div>inline bool scan_d(int &amp;num) &nbsp; &nbsp; &nbsp;// 输入&nbsp;</div><div>{</div><div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;char in;bool IsN=false;</div><div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;in=getchar();</div><div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;if(in==EOF) return false;</div><div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;while(in!='-'&amp;&amp;(in&lt;'0'||in&gt;'9')) in=getchar();</div><div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;if(in=='-'){ IsN=true;num=0;}</div><div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;else num=in-'0';</div><div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;while(in=getchar(),in&gt;='0'&amp;&amp;in&lt;='9'){</div><div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;num*=10,num+=in-'0';</div><div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;}</div><div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;if(IsN) num=-num;</div><div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;return true;</div><div>}</div><div>int main ()</div><div>{</div><div>&nbsp;&nbsp; &nbsp;while ( scan_d ( N ) &amp;&amp; scan_d ( D ) ){</div><div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; for ( int i = 0; i &lt; N; ++ i ){</div><div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;scan_d ( num1[i] ); &nbsp;num2[i] = num1[i]; &nbsp;</div><div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }</div><div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; sort ( num1, num1 + N );</div><div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; hash[1] = num1[0]; &nbsp;nCount = 1;</div><div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; for ( int i = 1; i &lt; N; ++ i ){ &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // 数据 离散化&nbsp;</div><div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if ( num1[i] != num1[i-1] ) hash[++nCount] = num1[i];</div><div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }</div><div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; memset ( com, 0, sizeof ( com ) );</div><div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; for ( int i = 0; i &lt; N; ++ i ){</div><div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;int pos = find1 ( num2[i] ); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // 找当前元素的 hash 下标 &nbsp;&nbsp;</div><div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;int pre = find1 ( num2[i] + D ); &nbsp; &nbsp; &nbsp; &nbsp; // 找 &lt;= &nbsp;num2[i] + D 的第一个数&nbsp;</div><div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;int tail = find2 ( num2[i] - D ); &nbsp; &nbsp; &nbsp; &nbsp;// 找 &gt;= num2[i] - D &nbsp;的第一个数&nbsp;</div><div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;int val = quy ( pre ) - quy ( tail - 1 ) + 1; &nbsp;// 区间 [ num2[i] - D, num2[i] + D ] 的元素个数 + 新增的一个元素&nbsp;</div><div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;modify ( pos, val % MOD );</div><div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }</div><div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; cout &lt;&lt; ( quy ( nCount ) - N &nbsp;) % MOD &lt;&lt; endl; &nbsp;//以 一个元素 的 [ elem - D, elem + D ] 计算, 题目要求 k &gt;= 2, 减掉 N 个&nbsp;</div><div>&nbsp;&nbsp; &nbsp;}</div><div>&nbsp;&nbsp; &nbsp;return 0;</div><div>}</div><div><br></div></font></div></div><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></span></font></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>
<img src ="http://www.cppblog.com/MiYu/aggbug/125251.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-08-30 09:59 <a href="http://www.cppblog.com/MiYu/archive/2010/08/30/125251.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>HDOJ 2642 HDU 2642 Stars ACM 2642 IN HDU</title><link>http://www.cppblog.com/MiYu/archive/2010/08/29/125126.html</link><dc:creator>MiYu</dc:creator><author>MiYu</author><pubDate>Sun, 29 Aug 2010 01:30:00 GMT</pubDate><guid>http://www.cppblog.com/MiYu/archive/2010/08/29/125126.html</guid><wfw:comment>http://www.cppblog.com/MiYu/comments/125126.html</wfw:comment><comments>http://www.cppblog.com/MiYu/archive/2010/08/29/125126.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/MiYu/comments/commentRss/125126.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/MiYu/services/trackbacks/125126.html</trackback:ping><description><![CDATA[<span  style="font-family: verdana, 'courier new'; font-size: 14px; line-height: 21px; "><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; ">&nbsp;&nbsp; &nbsp;&nbsp;<a href="http://acm.hdu.edu.cn/showproblem.php?pid=2642">http://acm.hdu.edu.cn/showproblem.php?pid=2642</a>&nbsp;</p><p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; ">题目描述:</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; ">Stars</h1><font><strong><span style="font-family: Arial; font-size: 12px; font-weight: bold; color: green; ">Time Limit: 5000/2000 MS (Java/Others)&nbsp;&nbsp;&nbsp;&nbsp;Memory Limit: 32768/65536 K (Java/Others)<br>Total Submission(s): 166&nbsp;&nbsp;&nbsp;&nbsp;Accepted Submission(s): 66<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; ">Yifenfei is a romantic guy and he likes to count the stars in the sky.<br>To make the problem easier,we considerate the sky is a two-dimension plane.Sometimes the star will be bright and sometimes the star will be dim.At first,there is no bright star in the sky,then some information will be given as "B x y" where 'B' represent bright and x represent the X coordinate and y represent the Y coordinate means the star at (x,y) is bright,And the 'D' in "D x y" mean the star at(x,y) is dim.When get a query as "Q X1 X2 Y1 Y2",you should tell Yifenfei how many bright stars there are in the region correspond X1,X2,Y1,Y2.<br><br>There is only one case.</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; ">The first line contain a M(M &lt;= 100000), then M line followed.<br>each line start with a operational character.<br>if the character is B or D,then two integer X,Y (0 &lt;=X,Y&lt;= 1000)followed.<br>if the character is Q then four integer X1,X2,Y1,Y2(0 &lt;=X1,X2,Y1,Y2&lt;= 1000) followed.<br></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 query,output the number of bright stars in one line.<br></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; ">5
B 581 145
B 581 145
Q 0 600 0 200
D 581 145
Q 0 600 0 200</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
0</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; ">题目分析 :</p><p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; ">&nbsp;与 HDU 1892 基本相同的一道题, &nbsp;只是矩阵数组的值被限定在 [0,1] , &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; ">&nbsp;</p><p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; ">代码如下 :</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><span style="font-family: 'Courier New'; color: rgb(128, 0, 128); "><div>/*</div><div>MiYu原创, 转帖请注明 : 转载自 ______________白白の屋</div><div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;http://www.cnblog.com/MiYu</div><div>Author By : MiYu</div><div>Test &nbsp; &nbsp; &nbsp;: 1</div><div>Program &nbsp; : 2642</div><div>*/</div><div><br></div><div>#include &lt;iostream&gt;</div><div>#include &lt;algorithm&gt;</div><div>using namespace std;</div><div>#define lowbit(x) (x&amp;(-x))</div><div>int T;</div><div>const int MAX = 1001;</div><div>int mat[1002][1002];</div><div>int com[1002][1002];</div><div>void modify ( int x,int y, int n )</div><div>{</div><div>&nbsp;&nbsp; &nbsp; while ( x &lt;= MAX ){</div><div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; int t = y;</div><div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; while ( t &lt;= MAX ){</div><div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;com[x][t] += n;</div><div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;t += lowbit(t);&nbsp;</div><div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }&nbsp;</div><div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; x += lowbit(x);</div><div>&nbsp;&nbsp; &nbsp; }&nbsp;</div><div>}</div><div>int quy ( int x, int y )</div><div>{</div><div>&nbsp;&nbsp; &nbsp; int sum = 0;</div><div>&nbsp;&nbsp; &nbsp; while ( x &gt; 0 ){</div><div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; int t = y;</div><div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; while ( t &gt; 0 ){</div><div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;sum += com[x][t];</div><div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;t ^= lowbit(t);&nbsp;</div><div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }&nbsp;</div><div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; x ^= lowbit(x);</div><div>&nbsp;&nbsp; &nbsp; }&nbsp;</div><div>&nbsp;&nbsp; &nbsp; return sum;&nbsp;</div><div>}</div><div>inline bool scan_d(int &amp;num)&nbsp;</div><div>{</div><div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;char in;bool IsN=false;</div><div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;in=getchar();</div><div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;if(in==EOF) return false;</div><div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;while(in!='-'&amp;&amp;(in&lt;'0'||in&gt;'9')) in=getchar();</div><div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;if(in=='-'){ IsN=true;num=0;}</div><div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;else num=in-'0';</div><div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;while(in=getchar(),in&gt;='0'&amp;&amp;in&lt;='9'){</div><div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;num*=10,num+=in-'0';</div><div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;}</div><div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;if(IsN) num=-num;</div><div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;return true;</div><div>}</div><div>int main ()</div><div>{</div><div>&nbsp;&nbsp; &nbsp; &nbsp;while ( scan_d(T) ) {</div><div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;int ca = 1;</div><div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; char s[5]; &nbsp;int a,b,x,y,m,res,maxx,maxy,minx,miny;</div><div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; memset ( com, 0, sizeof ( com ) );</div><div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; while ( T -- ) {</div><div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; scanf ( "%s",s );</div><div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; switch ( s[0] ){</div><div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;case 'Q' : scan_d(a);scan_d(x);scan_d(b);scan_d(y); minx = min ( a,x );miny=min(b,y);maxx=max(a,x)+1;maxy=max(b,y)+1;</div><div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; res = 0; &nbsp;res += quy( maxx,maxy ); res -= quy (maxx,miny); res -= quy(minx,maxy); res += quy(minx,miny);</div><div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; printf ( "%d\n",res ); break; &nbsp;&nbsp;</div><div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;case 'B' : scan_d(x);scan_d(y); x++;y++; if ( !mat[x][y] ) { modify ( x,y,1 ); mat[x][y] = 1; } break;</div><div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;case 'D' : scan_d(x);scan_d(y); x++;y++; if ( mat[x][y] ) { modify ( x,y,-1 ); mat[x][y] = 0; } break; &nbsp;</div><div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }&nbsp;</div><div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }</div><div>&nbsp;&nbsp; &nbsp;}</div><div>&nbsp;&nbsp; &nbsp;return 0;</div><div>}</div><div><br></div></span></div></div><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></span></font></div></div><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></span>
<img src ="http://www.cppblog.com/MiYu/aggbug/125126.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-08-29 09:30 <a href="http://www.cppblog.com/MiYu/archive/2010/08/29/125126.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>HDOJ 2227 HDU 2227 Find the nondecreasing subsequences ACM 2227 IN HDU</title><link>http://www.cppblog.com/MiYu/archive/2010/08/27/124917.html</link><dc:creator>MiYu</dc:creator><author>MiYu</author><pubDate>Fri, 27 Aug 2010 02:07:00 GMT</pubDate><guid>http://www.cppblog.com/MiYu/archive/2010/08/27/124917.html</guid><wfw:comment>http://www.cppblog.com/MiYu/comments/124917.html</wfw:comment><comments>http://www.cppblog.com/MiYu/archive/2010/08/27/124917.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/MiYu/comments/commentRss/124917.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/MiYu/services/trackbacks/124917.html</trackback:ping><description><![CDATA[<span  style="font-family: verdana, 'courier new'; font-size: 14px; line-height: 21px; "><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; ">&nbsp;&nbsp; &nbsp;&nbsp;<a href="http://acm.hdu.edu.cn/showproblem.php?pid=2227">http://acm.hdu.edu.cn/showproblem.php?pid=2227&nbsp;</a></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; "></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><span style="font-family: 'Courier New'; color: rgb(128, 0, 128); "><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; ">Find the nondecreasing subsequences</h1><font><strong><span style="font-family: Arial; font-size: 12px; font-weight: bold; color: green; ">Time Limit: 10000/5000 MS (Java/Others)&nbsp;&nbsp;&nbsp;&nbsp;Memory Limit: 32768/32768 K (Java/Others)<br>Total Submission(s): 211&nbsp;&nbsp;&nbsp;&nbsp;Accepted Submission(s): 80<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; ">How many nondecreasing subsequences can you find in the sequence S = {s1, s2, s3, ...., sn} ? For example, we assume that S = {1, 2, 3}, and you can find seven nondecreasing subsequences, {1}, {2}, {3}, {1, 2}, {1, 3}, {2, 3}, {1, 2, 3}.</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; ">The input consists of multiple test cases. Each case begins with a line containing a positive integer n that is the length of the sequence S, the next line contains n integers {s1, s2, s3, ...., sn}, 1 &lt;= n &lt;= 100000, 0 &lt;= si &lt;= 2^31.</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 test case, output one line containing the number of nondecreasing subsequences you can find from the sequence S, the answer should % 1000000007.</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
1 2 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; ">7</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;题目分析:&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;整整一天的时间, 终于是把这个题A了 &nbsp;,HDU 第一, &nbsp;纪念下.....................</p><table width="100%" border="0" align="center" cellspacing="2"><tbody><tr class="table_text" align="center" style="font-family: Tahoma; font-size: 12px; "><td>1</td><td><a href="http://acm.hdu.edu.cn/userstatus.php?user=lyzardiar" style="color: rgb(26, 92, 200); text-decoration: none; ">HUT-MiYu</a></td><td>375MS</td><td>1824K</td><td>2358B</td><td>G++</td><td><p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; ">2<font  face="Tahoma">010-08-27 09:44:32&nbsp;</font></p></td></tr></tbody></table><p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; ">&nbsp;但也没有什么值得高兴的, &nbsp;题目的思路是 小A 的, &nbsp;0rz....................... &nbsp;现在还是没有理解树状数组是怎么解这一题的, &nbsp;它的思路是怎样的,</p><p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; ">一点也没明白, &nbsp; 刚开始做的时候, 还以为 输入数据已经是按非递减排序了, 所以直接用 公式 2^n - 1, WA ...<img src="http://www.cnblogs.com/Emoticons/baimantou/134950908.gif"></p><p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; ">..... &nbsp;问过小A 才发现, 输入数据是 随机的. &nbsp;这时就要像找上升子串一样, 找到它 所有的上升子串. &nbsp;这里用到了 树状数组, 继续理解-ing......</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; ">&nbsp;</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"><div>/*</div><div>MiYu原创, 转帖请注明 : 转载自 ______________白白の屋</div><div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;http://www.cnblog.com/MiYu</div><div>Author By : MiYu</div><div>Test &nbsp; &nbsp; &nbsp;: 1</div><div>Program &nbsp; : 2227&nbsp;</div><div>*/</div><div><br></div><div>#include &lt;iostream&gt;</div><div>#include &lt;algorithm&gt;</div><div>using namespace std;</div><div>#define lowbit(x) (x&amp;(-x))</div><div>int num[100005];</div><div>int numcopy[100005];</div><div>int hash[100005];</div><div>int com[100005];</div><div>int nCount = 1;</div><div>void add ( int x,int k )</div><div>{</div><div>&nbsp;&nbsp; &nbsp; while ( x &lt;= nCount )</div><div>&nbsp;&nbsp; &nbsp; {</div><div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; com[x] += k;</div><div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if ( com[x] &gt;= 1000000007 ) com[x] %= 1000000007;</div><div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; x += lowbit(x);&nbsp;</div><div>&nbsp;&nbsp; &nbsp; }&nbsp;</div><div>}</div><div>int sum ( int x )</div><div>{</div><div>&nbsp;&nbsp; &nbsp;int s = 0;</div><div>&nbsp;&nbsp; &nbsp;while ( x &gt; 0 )</div><div>&nbsp;&nbsp; &nbsp;{</div><div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; s += com[x];</div><div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if ( s &gt;= 1000000007 ) s %= 1000000007;</div><div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; x -= lowbit(x);</div><div>&nbsp;&nbsp; &nbsp;}&nbsp;</div><div>&nbsp;&nbsp; &nbsp;return s %= 1000000007;</div><div>}</div><div>int cmp (const void *a, const void *b)</div><div>{</div><div>&nbsp;&nbsp; &nbsp;return *((int*)a) - *((int*)b);&nbsp;</div><div>}</div><div>int sfind ( int x )</div><div>{</div><div>&nbsp;&nbsp; &nbsp;int *p = (int *)bsearch ( &amp;x,hash+1,nCount+1,sizeof ( int ),cmp );&nbsp;</div><div>&nbsp;&nbsp; &nbsp;return p - hash;</div><div>}</div><div>int find(int num){</div><div>&nbsp;&nbsp; &nbsp;int top=1,bottom=nCount,mid=(top+bottom)/2,ans=mid;</div><div>&nbsp;&nbsp; &nbsp;while(num!=hash[ans]){</div><div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;if(hash[mid]&lt;=num){</div><div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;top=(ans=mid)+1;</div><div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;}else{</div><div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;bottom=mid-1;</div><div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;}</div><div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;mid=(top+bottom)/2;</div><div>&nbsp;&nbsp; &nbsp;}</div><div>&nbsp;&nbsp; &nbsp;return ans;</div><div>}</div><div><br></div><div>inline bool scan_d(int &amp;num) &nbsp;//整数输入</div><div>{</div><div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;char in;bool IsN=false;</div><div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;in=getchar();</div><div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;if(in==EOF) return false;</div><div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;while(in!='-'&amp;&amp;(in&lt;'0'||in&gt;'9')) in=getchar();</div><div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;if(in=='-'){ IsN=true;num=0;}</div><div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;else num=in-'0';</div><div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;while(in=getchar(),in&gt;='0'&amp;&amp;in&lt;='9'){</div><div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;num*=10,num+=in-'0';</div><div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;}</div><div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;if(IsN) num=-num;</div><div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;return true;</div><div>}</div><div>int main ()</div><div>{</div><div>&nbsp;&nbsp; &nbsp;int N;</div><div>&nbsp;&nbsp; &nbsp;while ( scan_d ( N ) )</div><div>&nbsp;&nbsp; &nbsp;{</div><div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; for ( int i = 0; i != N; ++ i )</div><div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; scan_d ( num[i] ),numcopy[i] = num[i];</div><div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; sort ( num, num + N );</div><div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; memset ( com,0,sizeof (com) );</div><div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; nCount = 1;</div><div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; hash[1] = num[0];</div><div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; for ( int i = 1; i &lt; N; ++ i )</div><div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {</div><div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if ( num[i] != num[i-1] )</div><div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;hash[++nCount] = num[i];&nbsp;</div><div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }&nbsp;</div><div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; for ( int i = 0; i &lt; N; ++ i )</div><div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {</div><div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;int pos = find ( numcopy[i] );&nbsp;</div><div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;int res = sum ( pos ) + 1;</div><div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;add ( pos,res );</div><div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }</div><div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; cout &lt;&lt; sum ( nCount ) &lt;&lt; endl;</div><div>&nbsp;&nbsp; &nbsp;}</div><div>&nbsp;&nbsp; &nbsp;return 0;</div><div>}</div><div><br></div></font></div></div><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></span></span></div></div><p>&#160;</p></span>
<img src ="http://www.cppblog.com/MiYu/aggbug/124917.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-08-27 10:07 <a href="http://www.cppblog.com/MiYu/archive/2010/08/27/124917.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>HDOJ 1541 HDU 1541 Stars ACM 1541 IN HDU</title><link>http://www.cppblog.com/MiYu/archive/2010/08/26/124806.html</link><dc:creator>MiYu</dc:creator><author>MiYu</author><pubDate>Thu, 26 Aug 2010 04:33:00 GMT</pubDate><guid>http://www.cppblog.com/MiYu/archive/2010/08/26/124806.html</guid><wfw:comment>http://www.cppblog.com/MiYu/comments/124806.html</wfw:comment><comments>http://www.cppblog.com/MiYu/archive/2010/08/26/124806.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/MiYu/comments/commentRss/124806.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/MiYu/services/trackbacks/124806.html</trackback:ping><description><![CDATA[<span  style="font-family: verdana, 'courier new'; font-size: 14px; line-height: 21px; "><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; ">&nbsp;&nbsp;&nbsp;&nbsp;<a href="http://acm.hdu.edu.cn/showproblem.php?pid=1541">http://acm.hdu.edu.cn/showproblem.php?pid=1541&nbsp;</a></p><p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; ">题目描述:</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; ">Stars</h1><font><strong><span style="font-family: Arial; font-size: 12px; font-weight: bold; color: green; ">Time Limit: 2000/1000 MS (Java/Others)&nbsp;&nbsp;&nbsp;&nbsp;Memory Limit: 65536/32768 K (Java/Others)<br>Total Submission(s): 857&nbsp;&nbsp;&nbsp;&nbsp;Accepted Submission(s): 320<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; ">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><br><img src="http://acm.hdu.edu.cn/data/images/1541-1.jpg" style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; "><br><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><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; ">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.</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; ">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><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; ">5
1 1
5 1
7 1
3 3
5 5</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
1
0</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><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">题目分析 :</font></div><p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; ">&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;<span  style="font-family: Georgia; font-size: 12px; color: rgb(90, 59, 28); letter-spacing: 2px; line-height: 20px; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; ">另外开个数组存储星星的等级，比他小的数的个数作为下标，即等级，每出现一次，数组加一，com数组的大小即为它存储数据的最大值。</span>&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; ">&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; ">MiYu原创, 转帖请注明 : 转载自 ______________白白の屋</p><p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; ">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;http://www.cnblog.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; : 1541</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; "><br></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; ">using namespace std;</p><p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; ">const int MAX = 32005;</p><p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; ">#define lowbit(x) ((x)&amp;(-x))</p><p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; ">int com[MAX], res[MAX], N;</p><p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; ">void modify ( int pos, int val ){</p><p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; ">&nbsp;&nbsp; &nbsp; while ( pos &lt;= MAX ){</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;com[pos] += val;</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;pos += lowbit(pos); &nbsp;</p><p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; ">&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; ">int quy ( int x ){</p><p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; ">&nbsp;&nbsp; &nbsp;int sum = 0;</p><p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; ">&nbsp;&nbsp; &nbsp;while ( x &gt; 0 ){</p><p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; ">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; sum += com[x];</p><p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; ">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; x -= lowbit(x);</p><p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; ">&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;return sum;</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 (int x)</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 ( scanf ( "%d",&amp;N ) != EOF ){</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;memset ( com,0,sizeof (com) ); memset ( res,0,sizeof (res) );</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;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; &nbsp;scanf ( "%d%*d", &amp;x );&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; &nbsp;x++;</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; &nbsp;res[ quy(x) ] ++; &nbsp;modify ( x,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;}</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;for ( int i = 0; 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; &nbsp;printf ( "%d\n",res[i] );</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><div><br></div></div><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></span></font></div></div><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></span>
<img src ="http://www.cppblog.com/MiYu/aggbug/124806.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-08-26 12:33 <a href="http://www.cppblog.com/MiYu/archive/2010/08/26/124806.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>HDOJ 1892 HDU 1892 See you~ ACM 1892 IN HDU </title><link>http://www.cppblog.com/MiYu/archive/2010/08/26/124798.html</link><dc:creator>MiYu</dc:creator><author>MiYu</author><pubDate>Thu, 26 Aug 2010 03:48:00 GMT</pubDate><guid>http://www.cppblog.com/MiYu/archive/2010/08/26/124798.html</guid><wfw:comment>http://www.cppblog.com/MiYu/comments/124798.html</wfw:comment><comments>http://www.cppblog.com/MiYu/archive/2010/08/26/124798.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/MiYu/comments/commentRss/124798.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/MiYu/services/trackbacks/124798.html</trackback:ping><description><![CDATA[<span  style="font-family: verdana, 'courier new'; font-size: 14px; line-height: 21px; "><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; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href="http://acm.hdu.edu.cn/showproblem.php?pid=1892">http://acm.hdu.edu.cn/showproblem.php?pid=1892</a>&nbsp;</p><p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; ">题目描述:</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; "><img src="http://images.cnblogs.com/OutliningIndicators/ExpandedBlockStart.gif" class="code_img_opened" id="code_img_opened_75f56976-74c7-4633-8a8d-6c3700b14301" 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_75f56976-74c7-4633-8a8d-6c3700b14301"><div><span style="font-family: 'Courier New'; color: rgb(0, 0, 0); ">See&nbsp;you</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 0); ">~</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 0); "><br><br>Time&nbsp;Limit:&nbsp;</span><span style="font-family: 'Courier New'; color: rgb(128, 0, 128); ">5000</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 0); ">/</span><span style="font-family: 'Courier New'; color: rgb(128, 0, 128); ">3000</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 0); ">&nbsp;MS&nbsp;(Java</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 0); ">/</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 0); ">Others)&nbsp;&nbsp;&nbsp;&nbsp;Memory&nbsp;Limit:&nbsp;</span><span style="font-family: 'Courier New'; color: rgb(128, 0, 128); ">65535</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 0); ">/</span><span style="font-family: 'Courier New'; color: rgb(128, 0, 128); ">32768</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 0); ">&nbsp;K&nbsp;(Java</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 0); ">/</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 0); ">Others)<br>Total&nbsp;Submission(s):&nbsp;</span><span style="font-family: 'Courier New'; color: rgb(128, 0, 128); ">921</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 0); ">&nbsp;&nbsp;&nbsp;&nbsp;Accepted&nbsp;Submission(s):&nbsp;</span><span style="font-family: 'Courier New'; color: rgb(128, 0, 128); ">291</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 0); "><br><br><br>Problem&nbsp;Description<br>Now&nbsp;I&nbsp;am&nbsp;leaving&nbsp;hust&nbsp;acm.&nbsp;In&nbsp;the&nbsp;past&nbsp;two&nbsp;and&nbsp;half&nbsp;years,&nbsp;I&nbsp;learned&nbsp;so&nbsp;many&nbsp;knowledge&nbsp;about&nbsp;Algorithm&nbsp;and&nbsp;Programming,&nbsp;and&nbsp;I&nbsp;met&nbsp;so&nbsp;many&nbsp;good&nbsp;friends.&nbsp;I&nbsp;want&nbsp;to&nbsp;say&nbsp;sorry&nbsp;to&nbsp;Mr,&nbsp;Yin,&nbsp;I&nbsp;must&nbsp;leave&nbsp;now&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); ">.</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;I&nbsp;am&nbsp;very&nbsp;sorry,&nbsp;we&nbsp;could&nbsp;not&nbsp;advanced&nbsp;to&nbsp;the&nbsp;World&nbsp;Finals&nbsp;last&nbsp;year.&nbsp;<br>When&nbsp;coming&nbsp;into&nbsp;our&nbsp;training&nbsp;room,&nbsp;a&nbsp;lot&nbsp;of&nbsp;books&nbsp;are&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); ">&nbsp;my&nbsp;eyes.&nbsp;And&nbsp;every&nbsp;time&nbsp;the&nbsp;books&nbsp;are&nbsp;moving&nbsp;from&nbsp;one&nbsp;place&nbsp;to&nbsp;another&nbsp;one.&nbsp;Now&nbsp;give&nbsp;you&nbsp;the&nbsp;position&nbsp;of&nbsp;the&nbsp;books&nbsp;at&nbsp;the&nbsp;early&nbsp;of&nbsp;the&nbsp;day.&nbsp;And&nbsp;the&nbsp;moving&nbsp;information&nbsp;of&nbsp;the&nbsp;books&nbsp;the&nbsp;day,&nbsp;your&nbsp;work&nbsp;</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 255); ">is</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 0); ">&nbsp;to&nbsp;tell&nbsp;me&nbsp;how&nbsp;many&nbsp;books&nbsp;are&nbsp;stayed&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); ">&nbsp;some&nbsp;rectangles.&nbsp;<br>To&nbsp;make&nbsp;the&nbsp;problem&nbsp;easier,&nbsp;we&nbsp;divide&nbsp;the&nbsp;room&nbsp;into&nbsp;different&nbsp;grids&nbsp;and&nbsp;a&nbsp;book&nbsp;can&nbsp;only&nbsp;stayed&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); ">&nbsp;one&nbsp;grid.&nbsp;The&nbsp;length&nbsp;and&nbsp;the&nbsp;width&nbsp;of&nbsp;the&nbsp;room&nbsp;are&nbsp;less&nbsp;than&nbsp;</span><span style="font-family: 'Courier New'; color: rgb(128, 0, 128); ">1000</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 0); ">.&nbsp;I&nbsp;can&nbsp;move&nbsp;one&nbsp;book&nbsp;from&nbsp;one&nbsp;position&nbsp;to&nbsp;another&nbsp;position,&nbsp;take&nbsp;away&nbsp;one&nbsp;book&nbsp;from&nbsp;a&nbsp;position&nbsp;or&nbsp;bring&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); ">&nbsp;one&nbsp;book&nbsp;and&nbsp;put&nbsp;it&nbsp;on&nbsp;one&nbsp;position.&nbsp;<br>&nbsp;<br><br>Input<br>In&nbsp;the&nbsp;first&nbsp;line&nbsp;of&nbsp;the&nbsp;input&nbsp;file&nbsp;there&nbsp;</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 255); ">is</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 0); ">&nbsp;an&nbsp;Integer&nbsp;T(</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); ">&lt;=</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 0); ">T</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 0); ">&lt;=</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;which&nbsp;means&nbsp;the&nbsp;number&nbsp;of&nbsp;test&nbsp;cases&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); ">&nbsp;the&nbsp;input&nbsp;file.&nbsp;Then&nbsp;N&nbsp;test&nbsp;cases&nbsp;are&nbsp;followed.&nbsp;<br>For&nbsp;each&nbsp;test&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(0, 0, 255); ">in</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 0); ">&nbsp;the&nbsp;first&nbsp;line&nbsp;there&nbsp;</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 255); ">is</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 0); ">&nbsp;an&nbsp;Integer&nbsp;Q(</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); ">&lt;</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 0); ">Q</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 0); ">&lt;=</span><span style="font-family: 'Courier New'; color: rgb(128, 0, 128); ">100</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 0); ">,</span><span style="font-family: 'Courier New'; color: rgb(128, 0, 128); ">000</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 0); ">),&nbsp;means&nbsp;the&nbsp;queries&nbsp;of&nbsp;the&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;Then&nbsp;followed&nbsp;by&nbsp;Q&nbsp;queries.&nbsp;<br>There&nbsp;are&nbsp;</span><span style="font-family: 'Courier New'; color: rgb(128, 0, 128); ">4</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 0); ">&nbsp;kind&nbsp;of&nbsp;queries,&nbsp;sum,&nbsp;add,&nbsp;delete&nbsp;and&nbsp;move.&nbsp;<br>For&nbsp;example:&nbsp;<br>S&nbsp;x1&nbsp;y1&nbsp;x2&nbsp;y2&nbsp;means&nbsp;you&nbsp;should&nbsp;tell&nbsp;me&nbsp;the&nbsp;total&nbsp;books&nbsp;of&nbsp;the&nbsp;rectangle&nbsp;used&nbsp;(x1,y1)</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 0); ">-</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 0); ">(x2,y2)&nbsp;</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 255); ">as</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 0); ">&nbsp;the&nbsp;diagonal,&nbsp;including&nbsp;the&nbsp;two&nbsp;points.&nbsp;<br>A&nbsp;x1&nbsp;y1&nbsp;n1&nbsp;means&nbsp;I&nbsp;put&nbsp;n1&nbsp;books&nbsp;on&nbsp;the&nbsp;position&nbsp;(x1,y1)&nbsp;<br>D&nbsp;x1&nbsp;y1&nbsp;n1&nbsp;means&nbsp;I&nbsp;move&nbsp;away&nbsp;n1&nbsp;books&nbsp;on&nbsp;the&nbsp;position&nbsp;(x1,y1),&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;less&nbsp;than&nbsp;n1&nbsp;books&nbsp;at&nbsp;that&nbsp;position,&nbsp;move&nbsp;away&nbsp;all&nbsp;of&nbsp;them.&nbsp;<br>M&nbsp;x1&nbsp;y1&nbsp;x2&nbsp;y2&nbsp;n1&nbsp;means&nbsp;you&nbsp;move&nbsp;n1&nbsp;books&nbsp;from&nbsp;(x1,y1)&nbsp;to&nbsp;(x2,y2),&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;less&nbsp;than&nbsp;n1&nbsp;books&nbsp;at&nbsp;that&nbsp;position,&nbsp;move&nbsp;away&nbsp;all&nbsp;of&nbsp;them.&nbsp;<br>Make&nbsp;sure&nbsp;that&nbsp;at&nbsp;first,&nbsp;there&nbsp;</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 255); ">is</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 0); ">&nbsp;one&nbsp;book&nbsp;on&nbsp;every&nbsp;grid&nbsp;and&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); ">&lt;=</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 0); ">x1,y1,x2,y2</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 0); ">&lt;=</span><span style="font-family: 'Courier New'; color: rgb(128, 0, 128); ">1000</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); ">&lt;=</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 0); ">n1</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 0); ">&lt;=</span><span style="font-family: 'Courier New'; color: rgb(128, 0, 128); ">100</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 0); ">.&nbsp;<br>&nbsp;<br><br>Output<br>At&nbsp;the&nbsp;beginning&nbsp;of&nbsp;each&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;output&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;X:</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); ">where</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 0); ">&nbsp;X&nbsp;</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 255); ">is</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 0); ">&nbsp;the&nbsp;index&nbsp;of&nbsp;the&nbsp;test&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;then&nbsp;followed&nbsp;by&nbsp;the&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;queries.&nbsp;<br>For&nbsp;each&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;query,&nbsp;just&nbsp;print&nbsp;</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 255); ">out</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 0); ">&nbsp;the&nbsp;total&nbsp;number&nbsp;of&nbsp;books&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); ">&nbsp;that&nbsp;area.&nbsp;<br>&nbsp;<br><br>Sample&nbsp;Input<br></span><span style="font-family: 'Courier New'; color: rgb(128, 0, 128); ">2</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 0); "><br></span><span style="font-family: 'Courier New'; color: rgb(128, 0, 128); ">3</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 0); "><br>S&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;</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;</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;</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>A&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;</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;</span><span style="font-family: 'Courier New'; color: rgb(128, 0, 128); ">2</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 0); "><br>S&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;</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;</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;</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></span><span style="font-family: 'Courier New'; color: rgb(128, 0, 128); ">3</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 0); "><br>S&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;</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;</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;</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>A&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;</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;</span><span style="font-family: 'Courier New'; color: rgb(128, 0, 128); ">2</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 0); "><br>S&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;</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;</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;</span><span style="font-family: 'Courier New'; color: rgb(128, 0, 128); ">2</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 0); "><br>&nbsp;<br><br>Sample&nbsp;Output<br>Case&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></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></span><span style="font-family: 'Courier New'; color: rgb(128, 0, 128); ">3</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 0); "><br>Case&nbsp;</span><span style="font-family: 'Courier New'; color: rgb(128, 0, 128); ">2</span><span style="font-family: 'Courier New'; color: rgb(0, 0, 0); ">:<br></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></span><span style="font-family: 'Courier New'; color: rgb(128, 0, 128); ">4</span></div><p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; ">&nbsp;</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">题目分析 :</font></div><p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; ">&nbsp;&nbsp; 一道二维树状数组 的裸题, 只是需要对坐标做些处理即可, 另外, 初始化的时候 原来 com[i][j] = lowbit (i) * lowbit (j);&nbsp;<img src="http://www.cnblogs.com/Emoticons/baimantou/134950908.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;WA 好多次, 直接用的modify(i,j,1)</p><p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; ">好了, &nbsp;直接代码吧, 代码过长, 内存多了一点点 , HDU 第二 &nbsp;<img src="http://www.cnblogs.com/Emoticons/baimantou/223332482.gif">&nbsp;&nbsp;&nbsp;</p><span  style="font-family: 'Times New Roman'; line-height: normal; font-size: medium; "><table width="100%" border="0" align="center" cellspacing="2"><tbody><tr bgcolor="#D7EBFF" class="table_text" align="center" style="font-family: Tahoma; font-size: 12px; "><td>2</td><td><a href="http://acm.hdu.edu.cn/userstatus.php?user=lyzardiar" style="color: rgb(26, 92, 200); text-decoration: none; ">HUT-MiYu</a></td><td>156MS</td><td>8044K</td><td>3172B</td><td>C++</td></tr></tbody></table></span><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; ">MiYu原创, 转帖请注明 : 转载自 ______________白白の屋</p><p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; ">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;http://www.cnblog.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; : 1892</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; "><br></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;cmath&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; ">using namespace std;</p><p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; ">#define lowbit(x) (x&amp;(-x))</p><p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; ">int T,N;</p><p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; ">const int MAX = 1001;</p><p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; ">int mat[1002][1002];</p><p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; ">int com[1002][1002];</p><p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; ">void modify ( int x,int y, int n )</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 ( x &lt;= MAX ){</p><p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; ">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; int t = y;</p><p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; ">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; while ( t &lt;= MAX ){</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; &nbsp;com[x][t] += 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; &nbsp; &nbsp; &nbsp; &nbsp;t += lowbit(t);&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; &nbsp; &nbsp; &nbsp; x += lowbit(x);</p><p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; ">&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; ">int quy ( int x, int y )</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; int sum = 0;</p><p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; ">&nbsp;&nbsp; &nbsp; while ( x &gt; 0 ){</p><p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; ">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; int t = y;</p><p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; ">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; while ( t &gt; 0 ){</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; &nbsp;sum += com[x][t];</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; &nbsp;t -= lowbit(t);&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; &nbsp; &nbsp; &nbsp; x -= lowbit(x);</p><p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; ">&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; return sum;&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_d(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; &nbsp; &nbsp;char in;bool IsN=false;</p><p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; ">&nbsp;&nbsp; &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; &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; &nbsp; &nbsp;while(in!='-'&amp;&amp;(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; &nbsp; &nbsp;if(in=='-'){ IsN=true;num=0;}</p><p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; ">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;else num=in-'0';</p><p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; ">&nbsp;&nbsp; &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; &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; &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;if(IsN) num=-num;</p><p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; ">&nbsp;&nbsp; &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; &nbsp;scan_d(T);{</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;int ca = 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;while ( T -- ){</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; &nbsp; printf ( "Case %d:\n",ca++ );</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; &nbsp; scan_d(N); &nbsp;char s[5]; &nbsp;int a,b,x,y,m,res,maxx,maxy,minx,miny;</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; &nbsp; for ( int i = 1; i &lt;= MAX; ++ 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; &nbsp; &nbsp; &nbsp; &nbsp;for ( int j = 1; j &lt;= MAX; ++ j )</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; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;com[i][j] = lowbit(i) * lowbit(j), mat[i][j] = 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; &nbsp; for ( int i = 1; i &lt;= N; &nbsp;++ 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; &nbsp; &nbsp; &nbsp; &nbsp; scanf ( "%s",s );</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; &nbsp; &nbsp; &nbsp; &nbsp; switch ( s[0] ){</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; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;case 'S' : scan_d(a);scan_d(b);scan_d(x);scan_d(y); minx = min ( a,x );miny=min(b,y);maxx=max(a,x)+1;maxy=max(b,y)+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; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; res = 0; &nbsp;res += quy( maxx,maxy ); res -= quy (maxx,miny); res -= quy(minx,maxy); res += quy(minx,miny);</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; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; printf ( "%d\n",res ); break; &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; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;case 'A' : scan_d(x);scan_d(y);scan_d(a);x++;y++; modify ( x,y,a ); mat[x][y] += a; break;</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; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;case 'D' : scan_d(x);scan_d(y);scan_d(a);x++;y++; if ( mat[x][y] &gt;= a ) { modify ( x,y,-a ); mat[x][y] -= a; }</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; &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;else &nbsp;{ modify ( x,y,-mat[x][y] ); mat[x][y] = 0; } break; &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; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;case 'M' : scan_d(a);scan_d(b);scan_d(x);scan_d(y);scan_d(m);a++;b++;x++;y++; if ( mat[a][b] &gt;= m )</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; &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; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;{ &nbsp;mat[a][b] -= m; mat[x][y] += m; modify ( a,b,-m ); modify ( x,y,m ); }</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; &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; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;else { modify ( a,b,-mat[a][b] ); modify ( x,y,mat[a][b] ); mat[x][y] += mat[a][b]; mat[a][b] = 0; } break;</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; &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; &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;}&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><div><br></div></div><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></div></div><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></span>
<img src ="http://www.cppblog.com/MiYu/aggbug/124798.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-08-26 11:48 <a href="http://www.cppblog.com/MiYu/archive/2010/08/26/124798.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>树状数组 小结</title><link>http://www.cppblog.com/MiYu/archive/2010/08/25/124726.html</link><dc:creator>MiYu</dc:creator><author>MiYu</author><pubDate>Wed, 25 Aug 2010 12:19:00 GMT</pubDate><guid>http://www.cppblog.com/MiYu/archive/2010/08/25/124726.html</guid><wfw:comment>http://www.cppblog.com/MiYu/comments/124726.html</wfw:comment><comments>http://www.cppblog.com/MiYu/archive/2010/08/25/124726.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/MiYu/comments/commentRss/124726.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/MiYu/services/trackbacks/124726.html</trackback:ping><description><![CDATA[<span  style="font-family: verdana, 'courier new'; font-size: 14px; line-height: 21px; "><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><span style="font-family: 'Times New Roman'; line-height: normal; font-size: medium; "><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; 　　&nbsp;<span style="font-family: 宋体; font-size: 10pt; ">树状数组是一个查询和修改复杂度都为</span><span lang="EN-US" style="font-family: 'Courier New'; font-size: 10pt; ">log(n)</span><span style="font-family: 宋体; font-size: 10pt; ">的数据结构，假设数组</span><span lang="EN-US" style="font-family: 'Courier New'; font-size: 10pt; ">a[1...n]</span><span style="font-family: 宋体; font-size: 10pt; ">，那么查询</span><span lang="EN-US" style="font-family: 'Courier New'; font-size: 10pt; ">a[1] +&nbsp;</span><span style="font-family: 宋体; font-size: 10pt; ">&#8230;&#8230;</span><span lang="EN-US" style="font-family: 'Courier New'; font-size: 10pt; ">&nbsp;+ a[i]</span><span style="font-family: 宋体; font-size: 10pt; ">　的时间是</span><span lang="EN-US" style="font-family: 'Courier New'; font-size: 10pt; ">log</span><span style="font-family: 宋体; font-size: 10pt; ">级别的，而且是一个在线的数据结构，支持随时修改某个元素的值，复杂度也为</span><span lang="EN-US" style="font-family: 'Courier New'; font-size: 10pt; ">log</span><span style="font-family: 宋体; font-size: 10pt; ">级别。</span></p><p class="MsoNormal" align="left" style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; text-align: left; word-break: break-all; "><span lang="EN-US" style="font-family: 宋体; font-size: 10pt; "><o:p>&nbsp;</o:p></span></p><p class="MsoNormal" align="left" style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; text-align: left; word-break: break-all; "><span style="font-family: 宋体; font-size: 10pt; ">来观察一下这个图：</span><span lang="EN-US" style="font-family: Arial; font-size: 12pt; "><o:p></o:p></span></p><p class="MsoNormal" align="left" style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; text-align: left; word-break: break-all; "><span lang="EN-US" style="font-family: Arial; font-size: 12pt; ">&nbsp;<o:p></o:p></span></p><p class="MsoNormal" align="left" style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; text-align: left; word-break: break-all; "><font face="Arial" size="3"><span style="font-family: 'Courier New'; font-size: 13px; "><img src="http://images.cnblogs.com/cnblogs_com/miyu/3.jpg" border="0" alt="" width="462" height="293" style="border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; "><br></span></font></p><p class="MsoNormal" align="left" style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; text-align: left; word-break: break-all; "><span lang="EN-US" style="font-family: Arial; font-size: 12pt; ">&nbsp;<o:p></o:p></span></p><p class="MsoNormal" align="left" style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; text-align: left; word-break: break-all; "><span style="font-family: 宋体; font-size: 10pt; ">令这棵树的结点编号为</span><span lang="EN-US" style="font-family: 宋体; font-size: 10pt; ">C1</span><span style="font-family: 宋体; font-size: 10pt; ">，</span><span lang="EN-US" style="font-family: 宋体; font-size: 10pt; ">C2</span><span style="font-family: 宋体; font-size: 10pt; ">&#8230;&#8230;</span><span lang="EN-US" style="font-family: 宋体; font-size: 10pt; ">Cn</span><span style="font-family: 宋体; font-size: 10pt; ">。令每个结点的值为这棵树的值的总和，那么容易发现：</span><span lang="EN-US" style="font-family: 宋体; font-size: 12pt; "><o:p></o:p></span></p><p class="MsoNormal" align="left" style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; text-align: left; word-break: break-all; "><span lang="EN-US" style="font-family: 宋体; font-size: 10pt; ">C1 = A1</span><span lang="EN-US" style="font-family: 宋体; font-size: 12pt; "><o:p></o:p></span></p><p class="MsoNormal" align="left" style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; text-align: left; word-break: break-all; "><span lang="EN-US" style="font-family: 宋体; font-size: 10pt; ">C2 = A1 + A2</span><span lang="EN-US" style="font-family: 宋体; font-size: 12pt; "><o:p></o:p></span></p><p class="MsoNormal" align="left" style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; text-align: left; word-break: break-all; "><span lang="EN-US" style="font-family: 宋体; font-size: 10pt; ">C3 = A3</span><span lang="EN-US" style="font-family: 宋体; font-size: 12pt; "><o:p></o:p></span></p><p class="MsoNormal" align="left" style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; text-align: left; word-break: break-all; "><span lang="EN-US" style="font-family: 宋体; font-size: 10pt; ">C4 = A1 + A2 + A3 + A4</span><span lang="EN-US" style="font-family: 宋体; font-size: 12pt; "><o:p></o:p></span></p><p class="MsoNormal" align="left" style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; text-align: left; word-break: break-all; "><span lang="EN-US" style="font-family: 宋体; font-size: 10pt; ">C5 = A5</span><span lang="EN-US" style="font-family: 宋体; font-size: 12pt; "><o:p></o:p></span></p><p class="MsoNormal" align="left" style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; text-align: left; word-break: break-all; "><span lang="EN-US" style="font-family: 宋体; font-size: 10pt; ">C6 = A5 + A6</span><span lang="EN-US" style="font-family: 宋体; font-size: 12pt; "><o:p></o:p></span></p><p class="MsoNormal" align="left" style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; text-align: left; word-break: break-all; "><span lang="EN-US" style="font-family: 宋体; font-size: 10pt; ">C7 = A7</span><span lang="EN-US" style="font-family: 宋体; font-size: 12pt; "><o:p></o:p></span></p><p class="MsoNormal" align="left" style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; text-align: left; word-break: break-all; "><span lang="EN-US" style="font-family: 宋体; font-size: 10pt; ">C8 = A1 + A2 + A3 + A4 + A5 + A6 + A7 + A8</span><span lang="EN-US" style="font-family: 宋体; font-size: 12pt; "><o:p></o:p></span></p><p class="MsoNormal" align="left" style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; text-align: left; word-break: break-all; "><span style="font-family: 宋体; font-size: 10pt; ">&#8230;&#8230;</span><span lang="EN-US" style="font-family: 宋体; font-size: 12pt; "><o:p></o:p></span></p><p class="MsoNormal" align="left" style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; text-align: left; word-break: break-all; "><span lang="EN-US" style="font-family: 宋体; font-size: 10pt; ">C16 = A1 + A2 + A3 + A4 + A5 + A6 + A7 + A8 + A9 + A10 + A11 + A12 + A13 + A14 + A15 + A16</span><span lang="EN-US" style="font-family: 宋体; font-size: 12pt; "><o:p></o:p></span></p><p class="MsoNormal" align="left" style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; text-align: left; word-break: break-all; "><span lang="EN-US" style="font-family: 宋体; font-size: 10pt; "><o:p>&nbsp;</o:p></span></p><p class="MsoNormal" align="left" style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; text-align: left; word-break: break-all; "><span style="font-family: 宋体; font-size: 10pt; ">这里有一个有趣的性质，下午推了一下发现：</span><span lang="EN-US" style="font-family: 宋体; font-size: 12pt; "><o:p></o:p></span></p><p class="MsoNormal" align="left" style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; text-align: left; word-break: break-all; "><span style="font-family: 宋体; font-size: 10pt; ">设节点编号为</span><span lang="EN-US" style="font-family: 宋体; font-size: 10pt; ">x</span><span style="font-family: 宋体; font-size: 10pt; ">，那么这个节点管辖的区间为</span><span lang="EN-US" style="font-family: 宋体; font-size: 10pt; ">2^k</span><span style="font-family: 宋体; font-size: 10pt; ">（其中</span><span lang="EN-US" style="font-family: 宋体; font-size: 10pt; ">k</span><span style="font-family: 宋体; font-size: 10pt; ">为</span><span lang="EN-US" style="font-family: 宋体; font-size: 10pt; ">x</span><span style="font-family: 宋体; font-size: 10pt; ">二进制末尾</span><span lang="EN-US" style="font-family: 宋体; font-size: 10pt; ">0</span><span style="font-family: 宋体; font-size: 10pt; ">的个数）个元素。因为这个区间最后一个元素必然为</span><span lang="EN-US" style="font-family: 宋体; font-size: 10pt; ">Ax</span><span style="font-family: 宋体; font-size: 10pt; ">，所以很明显：</span><span lang="EN-US" style="font-family: 宋体; font-size: 12pt; "><o:p></o:p></span></p><p class="MsoNormal" align="left" style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; text-align: left; word-break: break-all; "><span lang="EN-US" style="font-family: 宋体; font-size: 10pt; ">Cn = A(n &#8211; 2^k + 1) +&nbsp;</span><span style="font-family: 宋体; font-size: 10pt; ">&#8230;&#8230;</span><span lang="EN-US" style="font-family: 宋体; font-size: 10pt; ">&nbsp;+ An</span><span lang="EN-US" style="font-family: 宋体; font-size: 12pt; "><o:p></o:p></span></p><p class="MsoNormal" align="left" style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; text-align: left; word-break: break-all; "><span style="font-family: 宋体; font-size: 10pt; ">算这个</span><span lang="EN-US" style="font-family: 宋体; font-size: 10pt; ">2^k</span><span style="font-family: 宋体; font-size: 10pt; ">有一个快捷的办法，定义一个函数如下即可：</span><span lang="EN-US" style="font-family: 宋体; font-size: 12pt; "><o:p></o:p></span></p><p class="MsoNormal" align="left" style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; text-align: left; word-break: break-all; "><span lang="EN-US" style="font-family: 宋体; font-size: 10pt; ">int lowbit(int x){</span><span lang="EN-US" style="font-family: 宋体; font-size: 12pt; "><o:p></o:p></span></p><p class="MsoNormal" align="left" style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 21.75pt; text-align: left; word-break: break-all; "><span lang="EN-US" style="font-family: 宋体; font-size: 10pt; ">return x &amp; (x ^ (x &#8211; 1));</span><span lang="EN-US" style="font-family: 宋体; font-size: 12pt; "><o:p></o:p></span></p><p class="MsoNormal" align="left" style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; text-align: left; word-break: break-all; "><span lang="EN-US" style="font-family: 宋体; font-size: 10pt; ">}</span><span lang="EN-US" style="font-family: 宋体; font-size: 12pt; "><o:p></o:p></span></p><p class="MsoNormal" align="left" style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; text-align: left; word-break: break-all; "><span lang="EN-US" style="font-family: 宋体; font-size: 10pt; "><o:p>&nbsp;</o:p></span></p><p class="MsoNormal" align="left" style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; text-align: left; word-break: break-all; "><span style="font-family: 宋体; font-size: 10pt; ">当想要查询一个</span><span lang="EN-US" style="font-family: 宋体; font-size: 10pt; ">SUM(n)</span><span style="font-family: 宋体; font-size: 10pt; ">时，可以依据如下算法即可：</span><span lang="EN-US" style="font-family: 宋体; font-size: 12pt; "><o:p></o:p></span></p><p class="MsoNormal" align="left" style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; text-align: left; word-break: break-all; "><span lang="EN-US" style="font-family: 宋体; font-size: 10pt; ">step1:</span><span style="font-family: 宋体; font-size: 10pt; ">　令</span><span lang="EN-US" style="font-family: 宋体; font-size: 10pt; ">sum = 0</span><span style="font-family: 宋体; font-size: 10pt; ">，转第二步；</span><span lang="EN-US" style="font-family: 宋体; font-size: 12pt; "><o:p></o:p></span></p><p class="MsoNormal" align="left" style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; text-align: left; word-break: break-all; "><span lang="EN-US" style="font-family: 宋体; font-size: 10pt; ">step2:</span><span style="font-family: 宋体; font-size: 10pt; ">　假如</span><span lang="EN-US" style="font-family: 宋体; font-size: 10pt; ">n &lt;= 0</span><span style="font-family: 宋体; font-size: 10pt; ">，算法结束，返回</span><span lang="EN-US" style="font-family: 宋体; font-size: 10pt; ">sum</span><span style="font-family: 宋体; font-size: 10pt; ">值，否则</span><span lang="EN-US" style="font-family: 宋体; font-size: 10pt; ">sum = sum + Cn</span><span style="font-family: 宋体; font-size: 10pt; ">，转第三步；</span><span lang="EN-US" style="font-family: 宋体; font-size: 12pt; "><o:p></o:p></span></p><p class="MsoNormal" align="left" style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; text-align: left; word-break: break-all; "><span lang="EN-US" style="font-family: 宋体; font-size: 10pt; ">step3:<span style="font-family: 'Courier New'; ">&nbsp;&nbsp;</span></span><span style="font-family: 宋体; font-size: 10pt; ">令</span><span lang="EN-US" style="font-family: 宋体; font-size: 10pt; ">n = n &#8211; lowbit(n)</span><span style="font-family: 宋体; font-size: 10pt; ">，转第二步。</span><span lang="EN-US" style="font-family: 宋体; font-size: 12pt; "><o:p></o:p></span></p><p class="MsoNormal" align="left" style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; text-align: left; word-break: break-all; "><span lang="EN-US" style="font-family: 宋体; font-size: 10pt; "><o:p>&nbsp;</o:p></span></p><p class="MsoNormal" align="left" style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; text-align: left; word-break: break-all; "><span style="font-family: 宋体; font-size: 10pt; ">可以看出，这个算法就是将这一个个区间的和全部加起来，为什么是效率是</span><span lang="EN-US" style="font-family: 宋体; font-size: 10pt; ">log(n)</span><span style="font-family: 宋体; font-size: 10pt; ">的呢？以下给出证明：</span><span lang="EN-US" style="font-family: 宋体; font-size: 12pt; "><o:p></o:p></span></p><p class="MsoNormal" align="left" style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; text-align: left; word-break: break-all; "><span lang="EN-US" style="font-family: 宋体; font-size: 10pt; ">n = n &#8211; lowbit(n)</span><span style="font-family: 宋体; font-size: 10pt; ">这一步实际上等价于将</span><span lang="EN-US" style="font-family: 宋体; font-size: 10pt; ">n</span><span style="font-family: 宋体; font-size: 10pt; ">的二进制的最后一个</span><span lang="EN-US" style="font-family: 宋体; font-size: 10pt; ">1</span><span style="font-family: 宋体; font-size: 10pt; ">减去。而</span><span lang="EN-US" style="font-family: 宋体; font-size: 10pt; ">n</span><span style="font-family: 宋体; font-size: 10pt; ">的二进制里最多有</span><span lang="EN-US" style="font-family: 宋体; font-size: 10pt; ">log(n)</span><span style="font-family: 宋体; font-size: 10pt; ">个</span><span lang="EN-US" style="font-family: 宋体; font-size: 10pt; ">1</span><span style="font-family: 宋体; font-size: 10pt; ">，所以查询效率是</span><span lang="EN-US" style="font-family: 宋体; font-size: 10pt; ">log(n)</span><span style="font-family: 宋体; font-size: 10pt; ">的。</span><span lang="EN-US" style="font-family: 宋体; font-size: 12pt; "><o:p></o:p></span></p><p class="MsoNormal" align="left" style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; text-align: left; word-break: break-all; "><span lang="EN-US" style="font-family: 宋体; font-size: 10pt; "><o:p>&nbsp;</o:p></span></p><p class="MsoNormal" align="left" style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; text-align: left; word-break: break-all; "><span style="font-family: 宋体; font-size: 10pt; ">那么修改呢，修改一个节点，必须修改其所有祖先，最坏情况下为修改第一个元素，最多有</span><span lang="EN-US" style="font-family: 宋体; font-size: 10pt; ">log(n)</span><span style="font-family: 宋体; font-size: 10pt; ">的祖先。所以修改算法如下（给某个结点</span><span lang="EN-US" style="font-family: 宋体; font-size: 10pt; ">i</span><span style="font-family: 宋体; font-size: 10pt; ">加上</span><span lang="EN-US" style="font-family: 宋体; font-size: 10pt; ">x</span><span style="font-family: 宋体; font-size: 10pt; ">）：</span><span lang="EN-US" style="font-family: 宋体; font-size: 12pt; "><o:p></o:p></span></p><p class="MsoNormal" align="left" style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; text-align: left; word-break: break-all; "><span lang="EN-US" style="font-family: 宋体; font-size: 10pt; ">step1:&nbsp;</span><span style="font-family: 宋体; font-size: 10pt; ">当</span><span lang="EN-US" style="font-family: 宋体; font-size: 10pt; ">i &gt; n</span><span style="font-family: 宋体; font-size: 10pt; ">时，算法结束，否则转第二步；</span><span lang="EN-US" style="font-family: 宋体; font-size: 12pt; "><o:p></o:p></span></p><p class="MsoNormal" align="left" style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; text-align: left; word-break: break-all; "><span lang="PL" style="font-family: 宋体; font-size: 10pt; ">step2: Ci = Ci + x</span><span style="font-family: 宋体; font-size: 10pt; ">，</span><span lang="PL" style="font-family: 宋体; font-size: 10pt; ">&nbsp;i = i + lowbit(i)</span><span style="font-family: 宋体; font-size: 10pt; ">转第一步。</span><span lang="PL" style="font-family: 宋体; font-size: 10pt; "><o:p></o:p></span></p><p class="MsoNormal" align="left" style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; text-align: left; word-break: break-all; "><span lang="PL" style="font-family: 宋体; font-size: 10pt; "><o:p>&nbsp;</o:p></span></p><p class="MsoNormal" align="left" style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; text-align: left; word-break: break-all; "><span lang="PL" style="font-family: 宋体; font-size: 10pt; ">i = i +lowbit(i)</span><span style="font-family: 宋体; font-size: 10pt; ">这个过程实际上也只是一个把末尾</span><span lang="PL" style="font-family: 宋体; font-size: 10pt; ">1</span><span style="font-family: 宋体; font-size: 10pt; ">补为</span><span lang="PL" style="font-family: 宋体; font-size: 10pt; ">0</span><span style="font-family: 宋体; font-size: 10pt; ">的过程。</span><span lang="PL" style="font-family: 宋体; font-size: 10pt; "><o:p></o:p></span></p><p class="MsoNormal" align="left" style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; text-align: left; word-break: break-all; "><span lang="PL" style="font-family: 宋体; font-size: 10pt; ">//</span><span style="font-family: 宋体; font-size: 10pt; ">修改过程必须满足减法规则！</span><span lang="PL" style="font-family: 宋体; font-size: 10pt; "><o:p></o:p></span></p><p class="MsoNormal" align="left" style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; text-align: left; word-break: break-all; "><span lang="PL" style="font-family: 宋体; font-size: 10pt; "><o:p>&nbsp;</o:p></span></p><p class="MsoNormal" align="left" style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; text-align: left; word-break: break-all; "><span style="font-family: 宋体; font-size: 10pt; ">所以整个程序如下：</span><span lang="PL" style="font-family: 宋体; font-size: 10pt; "><o:p></o:p></span></p><p class="MsoNormal" align="left" style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; text-align: left; word-break: break-all; "><span lang="EN-US" style="font-family: 新宋体; font-size: 10pt; color: blue; "></span></p><p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; ">const int MAX = 50000;</p><p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; ">#define lowbit(x) ((x)&amp;(-x))</p><p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; ">int com[ MAX + 1 ],N,T;</p><p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; ">void modify ( int pos, int val ){</p><p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; ">&nbsp;&nbsp; &nbsp; while ( pos &lt;= 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; &nbsp;com[pos] += val;</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;pos = pos + lowbit(pos); &nbsp;</p><p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; ">&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; ">int quy ( int x ){</p><p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; ">&nbsp;&nbsp; &nbsp;int sum = 0;</p><p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; ">&nbsp;&nbsp; &nbsp;while ( x &gt; 0 ){</p><p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; ">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; sum = sum + com[x];</p><p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; ">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; x = x - lowbit(x);</p><p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; ">&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;return sum;</p><p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; ">}</p><p class="MsoNormal" align="left" style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; text-align: left; word-break: break-all; "><span lang="EN-US" style="font-family: 新宋体; font-size: 10pt; "><o:p></o:p></span></p><p class="MsoNormal" align="left" style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; text-align: left; word-break: break-all; "><font face="新宋体" size="3"><span style="font-family: 'Courier New'; font-size: 13px; ">初始化 : &nbsp;　　&nbsp;for ( int i = 1; i &lt;= N; ++ i ){</span></font></p><p class="MsoNormal" align="left" style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; text-align: left; word-break: break-all; "><font face="'Courier New'" size="3"><span style="font-family: 'Courier New'; font-size: 13px; ">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; scanf ( "%d",&amp;x );</span></font></p><p class="MsoNormal" align="left" style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; text-align: left; word-break: break-all; "><font face="'Courier New'" size="3"><span style="font-family: 'Courier New'; font-size: 13px; ">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; modify ( i, x );&nbsp;</span></font></p><p class="MsoNormal" align="left" style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; text-align: left; word-break: break-all; "><font face="'Courier New'" size="3"><span style="font-family: 'Courier New'; font-size: 13px; ">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }&nbsp;</span></font></p></span><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 style="font-size: 24pt; ">为什么要用树状数组 ?</span></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-size: 24pt; ">原因如下:&nbsp;</span></p><p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; ">&nbsp;</p><p:colorscheme colors="#ffffff,#000000,#969696,#000000,#00cc99,#3333cc,#ccccff,#b2b2b2"><div v:shape="_x0000_s1026" class="O"><div><span style="font-family: 'Times New Roman'; font-size: 22px; "><span style="color: rgb(255, 51, 0); position: absolute; left: -3.47656%; top: 0.39em; font-family: Wingdings; font-size: 15px; ">|</span></span><span style="font-family: 宋体; font-size: 28pt; ">&nbsp;&nbsp;1. 首先我们得知道一个问题</span><span lang="EN-US" style="font-family: 'Times New Roman'; font-size: 28pt; ">,</span><span style="font-family: 宋体; font-size: 28pt; ">那就是线段树得作用并</span></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; "><span style="font-family: 宋体; font-size: 28pt; ">不只</span><span style="font-family: 宋体; font-size: 28pt; ">是用来存储线段的</span><span lang="EN-US" style="font-family: 'Times New Roman'; font-size: 28pt; ">,</span><span style="font-family: 宋体; font-size: 28pt; ">也可以存储点的值等等<span style="font-family: 'Times New Roman'; ">. &nbsp;</span></span></p><p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; "><font face="'Times New Roman'"><br></font><span style="color: rgb(255, 51, 0); position: absolute; left: -3.4375%; top: 0.39em; font-family: Wingdings; font-size: 10px; ">|</span><span style="font-family: 宋体; font-size: 28pt; ">&nbsp;&nbsp;2. 对于</span><span style="font-family: 宋体; font-size: 28pt; ">静态的</span><span style="font-family: 宋体; font-size: 28pt; ">线段树</span><span lang="EN-US" style="font-family: 'Times New Roman'; font-size: 28pt; ">,</span><span style="font-family: 宋体; font-size: 28pt; ">空间上需要的数组有</span><span lang="EN-US" style="font-family: 'Times New Roman'; font-size: 28pt; ">:</span><span style="font-family: 宋体; font-size: 28pt; ">当前结点</span></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: 宋体; font-size: 28pt; ">的数</span><span style="font-family: 宋体; font-size: 28pt; ">据值</span><span lang="EN-US" style="font-family: 'Times New Roman'; font-size: 28pt; ">,</span><span style="font-family: 宋体; font-size: 28pt; ">左儿子</span><span style="font-family: 宋体; font-size: 28pt; ">编号</span><span lang="EN-US" style="font-family: 'Times New Roman'; font-size: 28pt; ">,</span><span style="font-family: 宋体; font-size: 28pt; ">右儿子编号</span><span lang="EN-US" style="font-family: 'Times New Roman'; font-size: 28pt; ">.</span><span style="font-family: 宋体; font-size: 28pt; ">至少这么三个数组</span></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 lang="EN-US" style="font-family: 'Times New Roman'; font-size: 28pt; ">&nbsp;&nbsp;&nbsp;&nbsp;3.&nbsp;</span><span style="color: rgb(255, 51, 0); position: absolute; left: -3.80469%; top: 0.39em; font-family: Wingdings; font-size: 10px; ">|</span><span style="font-family: 宋体; font-size: 28pt; ">&nbsp;而在</span><span style="font-family: 宋体; font-size: 28pt; ">时间上虽然是</span><span lang="EN-US" style="font-family: 'Times New Roman'; font-size: 28pt; ">NlogN</span><span style="font-family: 宋体; font-size: 28pt; ">的复杂度</span><span lang="EN-US" style="font-family: 'Times New Roman'; font-size: 28pt; ">,</span><span style="font-family: 宋体; font-size: 28pt; ">但是系数很大</span><span lang="EN-US" style="font-family: 'Times New Roman'; font-size: 28pt; ">.</span><span style="color: rgb(255, 51, 0); position: absolute; left: -3.4375%; top: 0.39em; font-family: Wingdings; font-size: 10px; ">|</span></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: 宋体; font-size: 28pt; ">&nbsp;&nbsp;4. 实现起</span><span style="font-family: 宋体; font-size: 28pt; ">来的时候编程复</span><span style="font-family: 宋体; font-size: 28pt; ">杂度大</span><span lang="EN-US" style="font-family: 'Times New Roman'; font-size: 28pt; ">,</span><span style="font-family: 宋体; font-size: 28pt; ">空间复杂度大</span><span lang="EN-US" style="font-family: 'Times New Roman'; font-size: 28pt; ">,</span><span style="font-family: 宋体; font-size: 28pt; ">时间</span></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: 宋体; font-size: 28pt; ">效率</span><span style="font-family: 宋体; font-size: 28pt; ">也不是</span><span style="font-family: 宋体; font-size: 28pt; ">很理想</span><span lang="EN-US" style="font-family: 'Times New Roman'; font-size: 28pt; ">.&nbsp;</span></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;<span style="font-size: 24pt; color: red; ">所以这个时候树状数组成了一个很好的选择.</span></p><p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; ">&nbsp;</p><p:colorscheme colors="#ffffff,#000000,#969696,#000000,#00cc99,#3333cc,#ccccff,#b2b2b2"><div v:shape="_x0000_s1026" class="O"><div><span style="font-family: 华文彩云; font-size: 32pt; ">先看一个例题:</span></div><p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; ">&nbsp;</p><div><span style="font-family: 黑体; font-size: 32pt; ">数列操作</span><span lang="EN-US" style="font-family: 'Times New Roman'; font-size: 32pt; ">:</span></div><p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; ">&nbsp;</p></div></p:colorscheme><p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; "><span lang="EN-US" style="font-family: 'Times New Roman'; font-size: 32pt; "><span>&nbsp;&nbsp; &nbsp;</span></span><span style="font-family: 宋体; font-size: 32pt; ">给定一个初始值都为</span><span lang="EN-US" style="font-family: 'Times New Roman'; font-size: 32pt; ">0</span><span style="font-family: 宋体; font-size: 32pt; ">的序列</span><span lang="EN-US" style="font-family: 'Times New Roman'; font-size: 32pt; ">,</span><span style="font-family: 宋体; font-size: 32pt; ">动态地修改一些</span>&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: 宋体; font-size: 32pt; ">位置上的数字</span><span lang="EN-US" style="font-family: 'Times New Roman'; font-size: 32pt; ">,</span><span style="font-family: 宋体; font-size: 32pt; ">加上一个数</span><span lang="EN-US" style="font-family: 'Times New Roman'; font-size: 32pt; ">,</span><span style="font-family: 宋体; font-size: 32pt; ">减去一个数</span><span lang="EN-US" style="font-family: 'Times New Roman'; font-size: 32pt; ">,</span><span style="font-family: 宋体; font-size: 32pt; ">或者乘上</span></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: 宋体; font-size: 32pt; ">一个数</span><span lang="EN-US" style="font-family: 'Times New Roman'; font-size: 32pt; ">,</span><span style="font-family: 宋体; font-size: 32pt; ">然后动态地提出问题</span><span lang="EN-US" style="font-family: 'Times New Roman'; font-size: 32pt; ">,</span><span style="font-family: 宋体; font-size: 32pt; ">问题的形式是求出</span></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: 宋体; font-size: 32pt; ">一段数字的和</span><span lang="EN-US" style="font-family: 'Times New Roman'; font-size: 32pt; ">.<span style="font-size: 14px; font-family: verdana, 'courier new'; ">&nbsp;</span></span></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:colorscheme colors="#ffffff,#000000,#969696,#000000,#00cc99,#3333cc,#ccccff,#b2b2b2"></p:colorscheme><p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; "><span style="font-family: 宋体; font-size: 32pt; color: rgb(255, 153, 0); ">如果直接用朴素方法做的话</span><span lang="EN-US" style="font-family: 'Times New Roman'; font-size: 32pt; color: rgb(255, 153, 0); ">,</span><span style="font-family: 宋体; font-size: 32pt; color: rgb(255, 153, 0); ">修改的复杂度是</span><span lang="EN-US" style="font-family: 'Times New Roman'; font-size: 32pt; color: rgb(255, 153, 0); ">O(1),</span>&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: 宋体; font-size: 32pt; color: rgb(255, 153, 0); ">询问的复杂度是</span><span lang="EN-US" style="font-family: 'Times New Roman'; font-size: 32pt; color: rgb(255, 153, 0); ">O(N),M</span><span style="font-family: 宋体; font-size: 32pt; color: rgb(255, 153, 0); ">次询问的复杂度是</span><span lang="EN-US" style="font-family: 'Times New Roman'; font-size: 32pt; color: rgb(255, 153, 0); ">M*N.</span></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 lang="EN-US" style="font-family: 'Times New Roman'; font-size: 32pt; color: rgb(255, 153, 0); ">M,N</span><span style="font-family: 宋体; font-size: 32pt; color: rgb(255, 153, 0); ">的范围可以有</span><span lang="EN-US" style="font-family: 'Times New Roman'; font-size: 32pt; color: rgb(255, 153, 0); ">100000</span><span style="font-family: 宋体; font-size: 32pt; color: rgb(255, 153, 0); ">以上!!!!</span></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; "><span style="font-size: 24pt; color: rgb(255, 0, 0); ">&nbsp;有没有更好的方法???</span></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; "><span style="font-size: 24pt; ">&nbsp;</span><span style="font-size: 24pt; color: rgb(255, 0, 255); ">呵呵, 肯定有啦, 就是我要说的树状数组!!! &nbsp;</span></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-size: 24pt; ">具体的树状数组的解释请看上面, &nbsp;那么这个2<sup>k</sup>怎么求? 是怎么</span></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-size: 24pt; ">来的? &nbsp;</span></p><p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; ">&nbsp;</p><p:colorscheme colors="#ffffff,#000000,#969696,#000000,#00cc99,#3333cc,#ccccff,#b2b2b2"><div v:shape="_x0000_s1026" class="O"><div><span lang="EN-US" style="font-family: 'Times New Roman'; font-size: 28pt; ">K</span><span style="font-family: 宋体; font-size: 28pt; ">的计算可以这样</span><span lang="EN-US" style="font-family: 'Times New Roman'; font-size: 28pt; ">:</span></div><p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; ">&nbsp;</p><div><span style="font-family: 'Times New Roman'; font-size: 22px; "><span style="color: rgb(255, 51, 0); position: absolute; left: -5.54688%; top: 0.39em; font-family: Wingdings; font-size: 15px; ">|</span></span><span lang="EN-US" style="font-family: 'Times New Roman'; font-size: 28pt; ">2<sup>k</sup>=x and (x &amp; (x-1))</span></div><p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; ">&nbsp;</p><div><span style="font-family: 'Times New Roman'; font-size: 22px; "><span style="color: rgb(255, 51, 0); position: absolute; left: -5.54688%; top: 0.39em; font-family: Wingdings; font-size: 15px; ">|</span></span><span style="font-family: 宋体; font-size: 28pt; ">以</span><span lang="EN-US" style="font-family: 'Times New Roman'; font-size: 28pt; ">6</span><span style="font-family: 宋体; font-size: 28pt; ">为例</span></div><p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; ">&nbsp;</p><div><span style="font-family: 'Times New Roman'; font-size: 22px; "><span style="color: rgb(255, 51, 0); position: absolute; left: -5.54688%; top: 0.39em; font-family: Wingdings; font-size: 15px; ">|</span></span><span style="font-family: 'Times New Roman'; font-size: 28pt; "><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span>(6)</span><span lang="EN-US" style="font-family: 'Times New Roman'; font-size: 18pt; position: relative; top: 0.37em; ">10</span><span lang="EN-US" style="font-family: 'Times New Roman'; font-size: 28pt; ">=(0110)</span><span lang="EN-US" style="font-family: 'Times New Roman'; font-size: 18pt; position: relative; top: 0.37em; ">2</span></div><p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; ">&nbsp;</p><div><span style="font-family: 'Times New Roman'; font-size: 22px; "><span style="color: rgb(255, 51, 0); position: absolute; left: -5.54688%; top: 0.39em; font-family: Wingdings; font-size: 15px; ">|</span></span><span lang="EN-US" style="font-family: 'Times New Roman'; font-size: 28pt; ">xor<span>&nbsp;&nbsp;&nbsp;&nbsp;</span>6-1=(5)</span><span lang="EN-US" style="font-family: 'Times New Roman'; font-size: 18pt; position: relative; top: 0.37em; ">10</span><span lang="EN-US" style="font-family: 'Times New Roman'; font-size: 28pt; ">=(0101)</span><span lang="EN-US" style="font-family: 'Times New Roman'; font-size: 18pt; position: relative; top: 0.37em; ">2</span></div><p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; ">&nbsp;</p><div><span style="font-family: 'Times New Roman'; font-size: 22px; "><span style="color: rgb(255, 51, 0); position: absolute; left: -5.54688%; top: 0.39em; font-family: Wingdings; font-size: 15px; ">|</span></span><span lang="EN-US" style="font-family: 'Times New Roman'; font-size: 28pt; "><span>&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>(0011)</span><span lang="EN-US" style="font-family: 'Times New Roman'; font-size: 18pt; position: relative; top: 0.37em; ">2</span></div><p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; ">&nbsp;</p><div><span style="font-family: 'Times New Roman'; font-size: 22px; "><span style="color: rgb(255, 51, 0); position: absolute; left: -5.54688%; top: 0.39em; font-family: Wingdings; font-size: 15px; ">|</span></span><span lang="EN-US" style="font-family: 'Times New Roman'; font-size: 28pt; ">and<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span>(6)</span><span lang="EN-US" style="font-family: 'Times New Roman'; font-size: 18pt; position: relative; top: 0.37em; ">10</span><span lang="EN-US" style="font-family: 'Times New Roman'; font-size: 28pt; ">=(0110)</span><span lang="EN-US" style="font-family: 'Times New Roman'; font-size: 18pt; position: relative; top: 0.37em; ">2</span></div><p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; ">&nbsp;</p><div><span style="font-family: 'Times New Roman'; font-size: 22px; "><span style="color: rgb(255, 51, 0); position: absolute; left: -5.54688%; top: 0.39em; font-family: Wingdings; font-size: 15px; ">|</span></span><span lang="EN-US" style="font-family: 'Times New Roman'; font-size: 28pt; "><span>&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>(0010)</span><span lang="EN-US" style="font-family: 'Times New Roman'; font-size: 18pt; position: relative; top: 0.37em; ">2</span></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; "><span style="font-size: 24pt; ">所以:&nbsp;</span></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-size: 24pt; ">由数字的机器码可以更简单的优化成: &nbsp;</span><span style="font-family: 'Times New Roman'; font-size: 37px; ">x &amp; (-x)</span></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: 宋体; font-size: 24pt; color: rgb(255, 0, 255); ">对于上面那一题</span><span lang="EN-US" style="font-family: 'Times New Roman'; font-size: 24pt; color: rgb(255, 0, 255); ">,</span><span style="font-family: 宋体; font-size: 24pt; color: rgb(255, 0, 255); ">每次修改与询问都是对</span><span lang="EN-US" style="font-family: 'Times New Roman'; font-size: 24pt; color: rgb(255, 0, 255); ">C</span><span style="font-family: 宋体; font-size: 24pt; color: rgb(255, 0, 255); ">数组</span><span style="font-family: 宋体; font-size: 24pt; color: rgb(255, 0, 255); ">做处理</span><span lang="EN-US" style="font-family: 'Times New Roman'; font-size: 24pt; color: rgb(255, 0, 255); ">.</span></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: 宋体; font-size: 24pt; color: rgb(255, 0, 255); ">空间复杂度有</span><span lang="EN-US" style="font-family: 'Times New Roman'; font-size: 24pt; color: rgb(255, 0, 255); ">3N</span><span style="font-family: 宋体; font-size: 24pt; color: rgb(255, 0, 255); ">降为</span><span lang="EN-US" style="font-family: 'Times New Roman'; font-size: 24pt; color: rgb(255, 0, 255); ">N,</span><span style="font-family: 宋体; font-size: 24pt; color: rgb(255, 0, 255); ">时间效率也有所</span><span style="font-family: 宋体; font-size: 24pt; color: rgb(255, 0, 255); ">提高</span><span lang="EN-US" style="font-family: 'Times New Roman'; font-size: 24pt; color: rgb(255, 0, 255); ">.</span><span style="font-family: 宋体; font-size: 24pt; color: rgb(255, 0, 255); ">编程</span><span style="font-family: 宋体; font-size: 24pt; color: rgb(255, 0, 255); ">复杂</span></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: 宋体; font-size: 24pt; color: rgb(255, 0, 255); ">度更是降了不少.</span></p><p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; ">&nbsp;</p><p:colorscheme colors="#ffffff,#000000,#969696,#000000,#00cc99,#3333cc,#ccccff,#b2b2b2"></p:colorscheme><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></div></p:colorscheme></div></p:colorscheme><p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; ">&nbsp;</p></span>
<img src ="http://www.cppblog.com/MiYu/aggbug/124726.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-08-25 20:19 <a href="http://www.cppblog.com/MiYu/archive/2010/08/25/124726.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/08/25/124725.html</link><dc:creator>MiYu</dc:creator><author>MiYu</author><pubDate>Wed, 25 Aug 2010 11:54:00 GMT</pubDate><guid>http://www.cppblog.com/MiYu/archive/2010/08/25/124725.html</guid><wfw:comment>http://www.cppblog.com/MiYu/comments/124725.html</wfw:comment><comments>http://www.cppblog.com/MiYu/archive/2010/08/25/124725.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/MiYu/comments/commentRss/124725.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/MiYu/services/trackbacks/124725.html</trackback:ping><description><![CDATA[<span  style="font-family: verdana, 'courier new'; font-size: 14px; line-height: 21px; "><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; ">　　<a href="http://acm.hdu.edu.cn/showproblem.php?pid=1166">http://acm.hdu.edu.cn/showproblem.php?pid=1166&nbsp;</a></p><p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; ">题目描述:</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><span style="font-family: 'Courier New'; color: rgb(128, 0, 128); "><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; ">敌兵布阵</h1><font><strong><span style="font-family: Arial; font-size: 12px; font-weight: bold; color: green; ">Time Limit: 2000/1000 MS (Java/Others)&nbsp;&nbsp;&nbsp;&nbsp;Memory Limit: 65536/32768 K (Java/Others)<br>Total Submission(s): 4546&nbsp;&nbsp;&nbsp;&nbsp;Accepted Submission(s): 1818<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; ">C国的死对头A国这段时间正在进行军事演习，所以C国间谍头子Derek和他手下Tidy又开始忙乎了。A国在海岸线沿直线布置了N个工兵营地,Derek和Tidy的任务就是要监视这些工兵营地的活动情况。由于采取了某种先进的监测手段，所以每个工兵营地的人数C国都掌握的一清二楚,每个工兵营地的人数都有可能发生变动，可能增加或减少若干人手,但这些都逃不过C国的监视。<br>中央情报局要研究敌人究竟演习什么战术,所以Tidy要随时向Derek汇报某一段连续的工兵营地一共有多少人,例如Derek问:&#8220;Tidy,马上汇报第3个营地到第10个营地共有多少人!&#8221;Tidy就要马上开始计算这一段的总人数并汇报。但敌兵营地的人数经常变动，而Derek每次询问的段都不一样，所以Tidy不得不每次都一个一个营地的去数，很快就精疲力尽了，Derek对Tidy的计算速度越来越不满:"你个死肥仔，算得这么慢，我炒你鱿鱼!&#8221;Tidy想：&#8220;你自己来算算看，这可真是一项累人的工作!我恨不得你炒我鱿鱼呢!&#8221;无奈之下，Tidy只好打电话向计算机专家Windbreaker求救,Windbreaker说：&#8220;死肥仔，叫你平时做多点acm题和看多点算法书，现在尝到苦果了吧!&#8221;Tidy说："我知错了。。。"但Windbreaker已经挂掉电话了。Tidy很苦恼，这么算他真的会崩溃的，聪明的读者，你能写个程序帮他完成这项工作吗？不过如果你的程序效率不够高的话，Tidy还是会受到Derek的责骂的.<br></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; ">第一行一个整数T，表示有T组数据。<br>每组数据第一行一个正整数N（N&lt;=50000）,表示敌人有N个工兵营地，接下来有N个正整数,第i个正整数ai代表第i个工兵营地里开始时有ai个人（1&lt;=ai&lt;=50）。<br>接下来每行有一条命令，命令有4种形式：<br>(1) Add i j,i和j为正整数,表示第i个营地增加j个人（j不超过30）<br>(2)Sub i j ,i和j为正整数,表示第i个营地减少j个人（j不超过30）;<br>(3)Query i j ,i和j为正整数,i&lt;=j，表示询问第i到第j个营地的总人数;<br>(4)End 表示结束，这条命令在每组数据最后出现;<br>每组数据最多有40000条命令<br></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; ">对第i组数据,首先输出&#8220;Case i:&#8221;和回车,<br>对于每个Query询问，输出一个整数并回车,表示询问的段中的总人数,这个数最多不超过1000000。<br></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; ">1
10
1 2 3 4 5 6 7 8 9 10
Query 1 3
Add 3 6
Query 2 7
Sub 10 2
Add 6 3
Query 3 10
End </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; ">Case 1:
6
33
59</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; ">题目分析 :</p><p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; ">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;<span  style="font-family: Verdana, Helvetica, Arial, sans-serif; border-collapse: collapse; color: rgb(68, 68, 68); font-size: 14px; line-height: 22px; ">看了 一下午的书,&nbsp;&nbsp;终于有一点明白了树状数组这东西 , 果然还是要做题啊, 一直不明白的地方, 刷了这<br style="word-wrap: break-word; line-height: normal; ">水题后,&nbsp;&nbsp;貌似明白了一点了&nbsp; &nbsp;<img src="http://www.cppleyuan.com/images/smilies/yangcong/95.gif" smilieid="185" border="0" alt="" style="word-wrap: break-word; line-height: normal; ">&nbsp;&nbsp;.&nbsp;</span></p><p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; ">&nbsp;&nbsp; &nbsp; &nbsp; 这是一道纯粹的 树状数组 的题目, 有模板的话直接模板就可以AC了, 不过手打也用不了什么时间.</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; ">懒, 把 quy 函数写成 quy ( int x, int y ) , 想一次就把结果求出来......还是对树状数组的理解不深刻......从其</p><p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; ">结构而言, 这种想法就不可能实现. &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; ">&nbsp;&nbsp; &nbsp; 　　&nbsp;<span style="font-family: 宋体; font-size: 10pt; ">树状数组是一个查询和修改复杂度都为</span><span lang="EN-US" style="font-family: 'Courier New'; font-size: 10pt; ">log(n)</span><span style="font-family: 宋体; font-size: 10pt; ">的数据结构，假设数组</span><span lang="EN-US" style="font-family: 'Courier New'; font-size: 10pt; ">a[1...n]</span><span style="font-family: 宋体; font-size: 10pt; ">，那么查询</span><span lang="EN-US" style="font-family: 'Courier New'; font-size: 10pt; ">a[1] +&nbsp;</span><span style="font-family: 宋体; font-size: 10pt; ">&#8230;&#8230;</span><span lang="EN-US" style="font-family: 'Courier New'; font-size: 10pt; ">&nbsp;+ a[i]</span><span style="font-family: 宋体; font-size: 10pt; ">　的时间是</span><span lang="EN-US" style="font-family: 'Courier New'; font-size: 10pt; ">log</span><span style="font-family: 宋体; font-size: 10pt; ">级别的，而且是一个在线的数据结构，支持随时修改某个元素的值，复杂度也为</span><span lang="EN-US" style="font-family: 'Courier New'; font-size: 10pt; ">log</span><span style="font-family: 宋体; font-size: 10pt; ">级别。</span></p><p class="MsoNormal" align="left" style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; text-align: left; word-break: break-all; "><span lang="EN-US" style="font-family: 宋体; font-size: 10pt; "><o:p>&nbsp;</o:p></span></p><p class="MsoNormal" align="left" style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; text-align: left; word-break: break-all; "><span style="font-family: 宋体; font-size: 10pt; ">来观察一下这个图：</span><span lang="EN-US" style="font-family: Arial; font-size: 12pt; "><o:p></o:p></span></p><p class="MsoNormal" align="left" style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; text-align: left; word-break: break-all; "><span lang="EN-US" style="font-family: Arial; font-size: 12pt; ">&nbsp;<o:p></o:p></span></p><p class="MsoNormal" align="left" style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; text-align: left; word-break: break-all; "><font  face="Arial" size="3"><span  style="font-family: 'Courier New'; font-size: 13px; "><img src="http://www.cnblogs.com/images/cnblogs_com/miyu/3.jpg" border="0" alt="" width="462" height="293"><br></span></font></p><p class="MsoNormal" align="left" style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; text-align: left; word-break: break-all; "><span lang="EN-US" style="font-family: Arial; font-size: 12pt; ">&nbsp;<o:p></o:p></span></p><p class="MsoNormal" align="left" style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; text-align: left; word-break: break-all; "><span style="font-family: 宋体; font-size: 10pt; ">令这棵树的结点编号为</span><span lang="EN-US" style="font-family: 宋体; font-size: 10pt; ">C1</span><span style="font-family: 宋体; font-size: 10pt; ">，</span><span lang="EN-US" style="font-family: 宋体; font-size: 10pt; ">C2</span><span style="font-family: 宋体; font-size: 10pt; ">&#8230;&#8230;</span><span lang="EN-US" style="font-family: 宋体; font-size: 10pt; ">Cn</span><span style="font-family: 宋体; font-size: 10pt; ">。令每个结点的值为这棵树的值的总和，那么容易发现：</span><span lang="EN-US" style="font-family: 宋体; font-size: 12pt; "><o:p></o:p></span></p><p class="MsoNormal" align="left" style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; text-align: left; word-break: break-all; "><span lang="EN-US" style="font-family: 宋体; font-size: 10pt; ">C1 = A1</span><span lang="EN-US" style="font-family: 宋体; font-size: 12pt; "><o:p></o:p></span></p><p class="MsoNormal" align="left" style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; text-align: left; word-break: break-all; "><span lang="EN-US" style="font-family: 宋体; font-size: 10pt; ">C2 = A1 + A2</span><span lang="EN-US" style="font-family: 宋体; font-size: 12pt; "><o:p></o:p></span></p><p class="MsoNormal" align="left" style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; text-align: left; word-break: break-all; "><span lang="EN-US" style="font-family: 宋体; font-size: 10pt; ">C3 = A3</span><span lang="EN-US" style="font-family: 宋体; font-size: 12pt; "><o:p></o:p></span></p><p class="MsoNormal" align="left" style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; text-align: left; word-break: break-all; "><span lang="EN-US" style="font-family: 宋体; font-size: 10pt; ">C4 = A1 + A2 + A3 + A4</span><span lang="EN-US" style="font-family: 宋体; font-size: 12pt; "><o:p></o:p></span></p><p class="MsoNormal" align="left" style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; text-align: left; word-break: break-all; "><span lang="EN-US" style="font-family: 宋体; font-size: 10pt; ">C5 = A5</span><span lang="EN-US" style="font-family: 宋体; font-size: 12pt; "><o:p></o:p></span></p><p class="MsoNormal" align="left" style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; text-align: left; word-break: break-all; "><span lang="EN-US" style="font-family: 宋体; font-size: 10pt; ">C6 = A5 + A6</span><span lang="EN-US" style="font-family: 宋体; font-size: 12pt; "><o:p></o:p></span></p><p class="MsoNormal" align="left" style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; text-align: left; word-break: break-all; "><span lang="EN-US" style="font-family: 宋体; font-size: 10pt; ">C7 = A7</span><span lang="EN-US" style="font-family: 宋体; font-size: 12pt; "><o:p></o:p></span></p><p class="MsoNormal" align="left" style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; text-align: left; word-break: break-all; "><span lang="EN-US" style="font-family: 宋体; font-size: 10pt; ">C8 = A1 + A2 + A3 + A4 + A5 + A6 + A7 + A8</span><span lang="EN-US" style="font-family: 宋体; font-size: 12pt; "><o:p></o:p></span></p><p class="MsoNormal" align="left" style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; text-align: left; word-break: break-all; "><span style="font-family: 宋体; font-size: 10pt; ">&#8230;&#8230;</span><span lang="EN-US" style="font-family: 宋体; font-size: 12pt; "><o:p></o:p></span></p><p class="MsoNormal" align="left" style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; text-align: left; word-break: break-all; "><span lang="EN-US" style="font-family: 宋体; font-size: 10pt; ">C16 = A1 + A2 + A3 + A4 + A5 + A6 + A7 + A8 + A9 + A10 + A11 + A12 + A13 + A14 + A15 + A16</span><span lang="EN-US" style="font-family: 宋体; font-size: 12pt; "><o:p></o:p></span></p><p class="MsoNormal" align="left" style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; text-align: left; word-break: break-all; "><span lang="EN-US" style="font-family: 宋体; font-size: 10pt; "><o:p>&nbsp;</o:p></span></p><p class="MsoNormal" align="left" style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; text-align: left; word-break: break-all; "><span style="font-family: 宋体; font-size: 10pt; ">这里有一个有趣的性质，下午推了一下发现：</span><span lang="EN-US" style="font-family: 宋体; font-size: 12pt; "><o:p></o:p></span></p><p class="MsoNormal" align="left" style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; text-align: left; word-break: break-all; "><span style="font-family: 宋体; font-size: 10pt; ">设节点编号为</span><span lang="EN-US" style="font-family: 宋体; font-size: 10pt; ">x</span><span style="font-family: 宋体; font-size: 10pt; ">，那么这个节点管辖的区间为</span><span lang="EN-US" style="font-family: 宋体; font-size: 10pt; ">2^k</span><span style="font-family: 宋体; font-size: 10pt; ">（其中</span><span lang="EN-US" style="font-family: 宋体; font-size: 10pt; ">k</span><span style="font-family: 宋体; font-size: 10pt; ">为</span><span lang="EN-US" style="font-family: 宋体; font-size: 10pt; ">x</span><span style="font-family: 宋体; font-size: 10pt; ">二进制末尾</span><span lang="EN-US" style="font-family: 宋体; font-size: 10pt; ">0</span><span style="font-family: 宋体; font-size: 10pt; ">的个数）个元素。因为这个区间最后一个元素必然为</span><span lang="EN-US" style="font-family: 宋体; font-size: 10pt; ">Ax</span><span style="font-family: 宋体; font-size: 10pt; ">，所以很明显：</span><span lang="EN-US" style="font-family: 宋体; font-size: 12pt; "><o:p></o:p></span></p><p class="MsoNormal" align="left" style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; text-align: left; word-break: break-all; "><span lang="EN-US" style="font-family: 宋体; font-size: 10pt; ">Cn = A(n &#8211; 2^k + 1) +&nbsp;</span><span style="font-family: 宋体; font-size: 10pt; ">&#8230;&#8230;</span><span lang="EN-US" style="font-family: 宋体; font-size: 10pt; ">&nbsp;+ An</span><span lang="EN-US" style="font-family: 宋体; font-size: 12pt; "><o:p></o:p></span></p><p class="MsoNormal" align="left" style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; text-align: left; word-break: break-all; "><span style="font-family: 宋体; font-size: 10pt; ">算这个</span><span lang="EN-US" style="font-family: 宋体; font-size: 10pt; ">2^k</span><span style="font-family: 宋体; font-size: 10pt; ">有一个快捷的办法，定义一个函数如下即可：</span><span lang="EN-US" style="font-family: 宋体; font-size: 12pt; "><o:p></o:p></span></p><p class="MsoNormal" align="left" style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; text-align: left; word-break: break-all; "><span lang="EN-US" style="font-family: 宋体; font-size: 10pt; ">int lowbit(int x){</span><span lang="EN-US" style="font-family: 宋体; font-size: 12pt; "><o:p></o:p></span></p><p class="MsoNormal" align="left" style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 21.75pt; text-align: left; word-break: break-all; "><span lang="EN-US" style="font-family: 宋体; font-size: 10pt; ">return x &amp; (x ^ (x &#8211; 1));</span><span lang="EN-US" style="font-family: 宋体; font-size: 12pt; "><o:p></o:p></span></p><p class="MsoNormal" align="left" style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; text-align: left; word-break: break-all; "><span lang="EN-US" style="font-family: 宋体; font-size: 10pt; ">}</span><span lang="EN-US" style="font-family: 宋体; font-size: 12pt; "><o:p></o:p></span></p><p class="MsoNormal" align="left" style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; text-align: left; word-break: break-all; "><span lang="EN-US" style="font-family: 宋体; font-size: 10pt; "><o:p>&nbsp;</o:p></span></p><p class="MsoNormal" align="left" style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; text-align: left; word-break: break-all; "><span style="font-family: 宋体; font-size: 10pt; ">当想要查询一个</span><span lang="EN-US" style="font-family: 宋体; font-size: 10pt; ">SUM(n)</span><span style="font-family: 宋体; font-size: 10pt; ">时，可以依据如下算法即可：</span><span lang="EN-US" style="font-family: 宋体; font-size: 12pt; "><o:p></o:p></span></p><p class="MsoNormal" align="left" style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; text-align: left; word-break: break-all; "><span lang="EN-US" style="font-family: 宋体; font-size: 10pt; ">step1:</span><span style="font-family: 宋体; font-size: 10pt; ">　令</span><span lang="EN-US" style="font-family: 宋体; font-size: 10pt; ">sum = 0</span><span style="font-family: 宋体; font-size: 10pt; ">，转第二步；</span><span lang="EN-US" style="font-family: 宋体; font-size: 12pt; "><o:p></o:p></span></p><p class="MsoNormal" align="left" style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; text-align: left; word-break: break-all; "><span lang="EN-US" style="font-family: 宋体; font-size: 10pt; ">step2:</span><span style="font-family: 宋体; font-size: 10pt; ">　假如</span><span lang="EN-US" style="font-family: 宋体; font-size: 10pt; ">n &lt;= 0</span><span style="font-family: 宋体; font-size: 10pt; ">，算法结束，返回</span><span lang="EN-US" style="font-family: 宋体; font-size: 10pt; ">sum</span><span style="font-family: 宋体; font-size: 10pt; ">值，否则</span><span lang="EN-US" style="font-family: 宋体; font-size: 10pt; ">sum = sum + Cn</span><span style="font-family: 宋体; font-size: 10pt; ">，转第三步；</span><span lang="EN-US" style="font-family: 宋体; font-size: 12pt; "><o:p></o:p></span></p><p class="MsoNormal" align="left" style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; text-align: left; word-break: break-all; "><span lang="EN-US" style="font-family: 宋体; font-size: 10pt; ">step3:<span style="font-family: 'Courier New'; ">&nbsp;&nbsp;</span></span><span style="font-family: 宋体; font-size: 10pt; ">令</span><span lang="EN-US" style="font-family: 宋体; font-size: 10pt; ">n = n &#8211; lowbit(n)</span><span style="font-family: 宋体; font-size: 10pt; ">，转第二步。</span><span lang="EN-US" style="font-family: 宋体; font-size: 12pt; "><o:p></o:p></span></p><p class="MsoNormal" align="left" style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; text-align: left; word-break: break-all; "><span lang="EN-US" style="font-family: 宋体; font-size: 10pt; "><o:p>&nbsp;</o:p></span></p><p class="MsoNormal" align="left" style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; text-align: left; word-break: break-all; "><span style="font-family: 宋体; font-size: 10pt; ">可以看出，这个算法就是将这一个个区间的和全部加起来，为什么是效率是</span><span lang="EN-US" style="font-family: 宋体; font-size: 10pt; ">log(n)</span><span style="font-family: 宋体; font-size: 10pt; ">的呢？以下给出证明：</span><span lang="EN-US" style="font-family: 宋体; font-size: 12pt; "><o:p></o:p></span></p><p class="MsoNormal" align="left" style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; text-align: left; word-break: break-all; "><span lang="EN-US" style="font-family: 宋体; font-size: 10pt; ">n = n &#8211; lowbit(n)</span><span style="font-family: 宋体; font-size: 10pt; ">这一步实际上等价于将</span><span lang="EN-US" style="font-family: 宋体; font-size: 10pt; ">n</span><span style="font-family: 宋体; font-size: 10pt; ">的二进制的最后一个</span><span lang="EN-US" style="font-family: 宋体; font-size: 10pt; ">1</span><span style="font-family: 宋体; font-size: 10pt; ">减去。而</span><span lang="EN-US" style="font-family: 宋体; font-size: 10pt; ">n</span><span style="font-family: 宋体; font-size: 10pt; ">的二进制里最多有</span><span lang="EN-US" style="font-family: 宋体; font-size: 10pt; ">log(n)</span><span style="font-family: 宋体; font-size: 10pt; ">个</span><span lang="EN-US" style="font-family: 宋体; font-size: 10pt; ">1</span><span style="font-family: 宋体; font-size: 10pt; ">，所以查询效率是</span><span lang="EN-US" style="font-family: 宋体; font-size: 10pt; ">log(n)</span><span style="font-family: 宋体; font-size: 10pt; ">的。</span><span lang="EN-US" style="font-family: 宋体; font-size: 12pt; "><o:p></o:p></span></p><p class="MsoNormal" align="left" style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; text-align: left; word-break: break-all; "><span lang="EN-US" style="font-family: 宋体; font-size: 10pt; "><o:p>&nbsp;</o:p></span></p><p class="MsoNormal" align="left" style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; text-align: left; word-break: break-all; "><span style="font-family: 宋体; font-size: 10pt; ">那么修改呢，修改一个节点，必须修改其所有祖先，最坏情况下为修改第一个元素，最多有</span><span lang="EN-US" style="font-family: 宋体; font-size: 10pt; ">log(n)</span><span style="font-family: 宋体; font-size: 10pt; ">的祖先。所以修改算法如下（给某个结点</span><span lang="EN-US" style="font-family: 宋体; font-size: 10pt; ">i</span><span style="font-family: 宋体; font-size: 10pt; ">加上</span><span lang="EN-US" style="font-family: 宋体; font-size: 10pt; ">x</span><span style="font-family: 宋体; font-size: 10pt; ">）：</span><span lang="EN-US" style="font-family: 宋体; font-size: 12pt; "><o:p></o:p></span></p><p class="MsoNormal" align="left" style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; text-align: left; word-break: break-all; "><span lang="EN-US" style="font-family: 宋体; font-size: 10pt; ">step1:&nbsp;</span><span style="font-family: 宋体; font-size: 10pt; ">当</span><span lang="EN-US" style="font-family: 宋体; font-size: 10pt; ">i &gt; n</span><span style="font-family: 宋体; font-size: 10pt; ">时，算法结束，否则转第二步；</span><span lang="EN-US" style="font-family: 宋体; font-size: 12pt; "><o:p></o:p></span></p><p class="MsoNormal" align="left" style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; text-align: left; word-break: break-all; "><span lang="PL" style="font-family: 宋体; font-size: 10pt; ">step2: Ci = Ci + x</span><span style="font-family: 宋体; font-size: 10pt; ">，</span><span lang="PL" style="font-family: 宋体; font-size: 10pt; ">&nbsp;i = i + lowbit(i)</span><span style="font-family: 宋体; font-size: 10pt; ">转第一步。</span><span lang="PL" style="font-family: 宋体; font-size: 10pt; "><o:p></o:p></span></p><p class="MsoNormal" align="left" style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; text-align: left; word-break: break-all; "><span lang="PL" style="font-family: 宋体; font-size: 10pt; "><o:p>&nbsp;</o:p></span></p><p class="MsoNormal" align="left" style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; text-align: left; word-break: break-all; "><span lang="PL" style="font-family: 宋体; font-size: 10pt; ">i = i +lowbit(i)</span><span style="font-family: 宋体; font-size: 10pt; ">这个过程实际上也只是一个把末尾</span><span lang="PL" style="font-family: 宋体; font-size: 10pt; ">1</span><span style="font-family: 宋体; font-size: 10pt; ">补为</span><span lang="PL" style="font-family: 宋体; font-size: 10pt; ">0</span><span style="font-family: 宋体; font-size: 10pt; ">的过程。</span><span lang="PL" style="font-family: 宋体; font-size: 10pt; "><o:p></o:p></span></p><p class="MsoNormal" align="left" style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; text-align: left; word-break: break-all; "><span lang="PL" style="font-family: 宋体; font-size: 10pt; ">//</span><span style="font-family: 宋体; font-size: 10pt; ">修改过程必须满足减法规则！</span><span lang="PL" style="font-family: 宋体; font-size: 10pt; "><o:p></o:p></span></p><p class="MsoNormal" align="left" style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; text-align: left; word-break: break-all; "><span lang="PL" style="font-family: 宋体; font-size: 10pt; "><o:p>&nbsp;</o:p></span></p><p class="MsoNormal" align="left" style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; text-align: left; word-break: break-all; "><span style="font-family: 宋体; font-size: 10pt; ">所以整个程序如下：</span><span lang="PL" style="font-family: 宋体; font-size: 10pt; "><o:p></o:p></span></p><p class="MsoNormal" align="left" style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; text-align: left; word-break: break-all; "><span lang="EN-US" style="font-family: 新宋体; font-size: 10pt; color: blue; "></span></p><p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; ">const int MAX = 50000;</p><p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; ">#define lowbit(x) ((x)&amp;(-x))</p><p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; ">int com[ MAX + 1 ],N,T;</p><p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; ">void modify ( int pos, int val ){</p><p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; ">&nbsp;&nbsp; &nbsp; while ( pos &lt;= 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; &nbsp;com[pos] += val;</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;pos = pos + lowbit(pos); &nbsp;</p><p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; ">&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; ">int quy ( int x ){</p><p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; ">&nbsp;&nbsp; &nbsp;int sum = 0;</p><p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; ">&nbsp;&nbsp; &nbsp;while ( x &gt; 0 ){</p><p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; ">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; sum = sum + com[x];</p><p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; ">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; x = x - lowbit(x);</p><p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; ">&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;return sum;</p><p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; ">}</p><p class="MsoNormal" align="left" style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; text-align: left; word-break: break-all; "><span lang="EN-US" style="font-family: 新宋体; font-size: 10pt; "><o:p></o:p></span></p><p class="MsoNormal" align="left" style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; text-align: left; word-break: break-all; "><font  face="新宋体" size="3"><span  style="font-family: 'Courier New'; font-size: 13px; ">初始化 : &nbsp;　　&nbsp;for ( int i = 1; i &lt;= N; ++ i ){</span></font></p><p class="MsoNormal" align="left" style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; text-align: left; word-break: break-all; "><font  face="'Courier New'" size="3"><span  style="font-family: 'Courier New'; font-size: 13px; ">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; scanf ( "%d",&amp;x );</span></font></p><p class="MsoNormal" align="left" style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; text-align: left; word-break: break-all; "><font  face="'Courier New'" size="3"><span  style="font-family: 'Courier New'; font-size: 13px; ">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; modify ( i, x );&nbsp;</span></font></p><p class="MsoNormal" align="left" style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; text-align: left; word-break: break-all; "><font  face="'Courier New'" size="3"><span  style="font-family: 'Courier New'; font-size: 13px; ">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }&nbsp;</span></font></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; ">本题代码如下 :</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; ">MiYu原创, 转帖请注明 : 转载自 ______________白白の屋</p><p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; ">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;http://www.cnblog.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; : 1166</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; "><br></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; ">using namespace std;</p><p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; ">const int MAX = 50000;</p><p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; ">#define lowbit(x) ((x)&amp;(-x))</p><p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; ">int com[ MAX + 1 ],N,T;</p><p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; ">void modify ( int pos, int val ){</p><p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; ">&nbsp;&nbsp; &nbsp; while ( pos &lt;= 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; &nbsp;com[pos] += val;</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;pos = pos + lowbit(pos); &nbsp;</p><p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; ">&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; ">int quy ( int x ){</p><p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; ">&nbsp;&nbsp; &nbsp;int sum = 0;</p><p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; ">&nbsp;&nbsp; &nbsp;while ( x &gt; 0 ){</p><p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; ">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; sum = sum + com[x];</p><p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; ">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; x = x - lowbit(x);</p><p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; ">&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;return sum;</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 ( scanf ( "%d",&amp;T ) != EOF ){</p><p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; ">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;int ca = 1,x,y;</p><p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; ">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;while ( T -- ){ &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; printf ( "Case %d:\n",ca++ );</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; scanf ( "%d",&amp;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; &nbsp; &nbsp; &nbsp; for ( int i = 0; i &lt;= N; ++ i ) com[i] &amp;= 0;</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; 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; &nbsp; &nbsp; &nbsp; scanf ( "%d",&amp;x );</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; &nbsp; &nbsp; &nbsp; modify ( i, x );&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; }&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; char ask[10];</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; while ( scanf ( "%s",ask ), ask[0] != 'E' ){ &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; &nbsp; &nbsp; &nbsp; &nbsp;scanf ( "%d%d",&amp;x,&amp;y );</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; &nbsp; &nbsp; &nbsp; &nbsp;switch ( ask[0] ){</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; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;case 'A': modify ( x, y ); break;</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; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;case 'S': modify ( x, -y ); break;</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; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;case 'Q': printf ( "%d\n",quy ( y ) - quy ( x-1 ) ); break;</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; &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; &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;}</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><div><br></div><p>&#160;</p></span></span></div></div><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></span>
<img src ="http://www.cppblog.com/MiYu/aggbug/124725.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-08-25 19:54 <a href="http://www.cppblog.com/MiYu/archive/2010/08/25/124725.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>