aboutsummaryrefslogtreecommitdiffstats
path: root/doc/html/SegmentTree_8h_source.html
blob: fd9119d41ece2770155d6d0709a5c7650eb9978d (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
<!-- HTML header for doxygen 1.8.3.1-->
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<meta name="generator" content="Doxygen 1.8.6"/>
<title>Templates -- Meow: meowpp/dsa/SegmentTree.h Source File</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="dynsections.js"></script>
<link href="navtree.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="resize.js"></script>
<script type="text/javascript" src="navtree.js"></script>
<script type="text/javascript">
  $(document).ready(initResizable);
  $(window).load(resizeHeight);
</script>
<link href="stylesheet.css" rel="stylesheet" type="text/css" />
<link href="custom.css" rel="stylesheet" type="text/css"/>
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  <td id="projectlogo"><img alt="Logo" src="logo.png"/></td>
  <td style="padding-left: 0.5em;">
   <div id="projectname">Templates -- Meow
   &#160;<span id="projectnumber">1.2.11</span>
   </div>
   <div id="projectbrief">A C++ template contains kinds of interesting classes and functions</div>
  </td>
 </tr>
 </tbody>
</table>
</div>
<!-- end header part -->
<!-- Generated by Doxygen 1.8.6 -->
</div><!-- top -->
<div id="side-nav" class="ui-resizable side-nav-resizable">
  <div id="nav-tree">
    <div id="nav-tree-contents">
      <div id="nav-sync" class="sync"></div>
    </div>
  </div>
  <div id="splitbar" style="-moz-user-select:none;" 
       class="ui-resizable-handle">
  </div>
</div>
<script type="text/javascript">
$(document).ready(function(){initNavTree('SegmentTree_8h_source.html','');});
</script>
<div id="doc-content">
<div class="header">
  <div class="headertitle">
<div class="title">SegmentTree.h</div>  </div>
</div><!--header-->
<div class="contents">
<a href="SegmentTree_8h.html">Go to the documentation of this file.</a><div class="fragment"><div class="line"><a name="l00001"></a><span class="lineno">    1</span>&#160;<span class="preprocessor">#ifndef   dsa_SegmentTree_H__</span></div>
<div class="line"><a name="l00002"></a><span class="lineno">    2</span>&#160;<span class="preprocessor"></span><span class="preprocessor">#define   dsa_SegmentTree_H__</span></div>
<div class="line"><a name="l00003"></a><span class="lineno">    3</span>&#160;<span class="preprocessor"></span></div>
<div class="line"><a name="l00004"></a><span class="lineno">    4</span>&#160;<span class="preprocessor">#include &quot;../math/utility.h&quot;</span></div>
<div class="line"><a name="l00005"></a><span class="lineno">    5</span>&#160;</div>
<div class="line"><a name="l00006"></a><span class="lineno">    6</span>&#160;<span class="preprocessor">#include &lt;vector&gt;</span></div>
<div class="line"><a name="l00007"></a><span class="lineno">    7</span>&#160;<span class="preprocessor">#include &lt;algorithm&gt;</span></div>
<div class="line"><a name="l00008"></a><span class="lineno">    8</span>&#160;</div>
<div class="line"><a name="l00009"></a><span class="lineno">    9</span>&#160;<span class="preprocessor">#include &lt;cstdlib&gt;</span></div>
<div class="line"><a name="l00010"></a><span class="lineno">   10</span>&#160;</div>
<div class="line"><a name="l00011"></a><span class="lineno">   11</span>&#160;<span class="keyword">namespace </span>meow {</div>
<div class="line"><a name="l00044"></a><span class="lineno">   44</span>&#160;<span class="keyword">template</span>&lt;<span class="keyword">class</span> Value&gt;</div>
<div class="line"><a name="l00045"></a><span class="lineno"><a class="line" href="classmeow_1_1SegmentTree.html">   45</a></span>&#160;<span class="keyword">class </span><a class="code" href="classmeow_1_1SegmentTree.html">SegmentTree</a> {</div>
<div class="line"><a name="l00046"></a><span class="lineno">   46</span>&#160;<span class="keyword">private</span>:</div>
<div class="line"><a name="l00047"></a><span class="lineno">   47</span>&#160;  <span class="keyword">struct </span>Node {</div>
<div class="line"><a name="l00048"></a><span class="lineno">   48</span>&#160;    Value     value_;</div>
<div class="line"><a name="l00049"></a><span class="lineno">   49</span>&#160;    Value    offset_;</div>
<div class="line"><a name="l00050"></a><span class="lineno">   50</span>&#160;    <span class="keywordtype">bool</span>  sameFlage_;</div>
<div class="line"><a name="l00051"></a><span class="lineno">   51</span>&#160;  };</div>
<div class="line"><a name="l00052"></a><span class="lineno">   52</span>&#160;  <span class="comment">//</span></div>
<div class="line"><a name="l00053"></a><span class="lineno">   53</span>&#160;  <span class="keywordtype">size_t</span>             size_;</div>
<div class="line"><a name="l00054"></a><span class="lineno">   54</span>&#160;  std::vector&lt;Node&gt; nodes_;</div>
<div class="line"><a name="l00055"></a><span class="lineno">   55</span>&#160;  <span class="comment">//</span></div>
<div class="line"><a name="l00056"></a><span class="lineno">   56</span>&#160;  <span class="keywordtype">void</span> update(<span class="keywordtype">size_t</span> index, <span class="keywordtype">size_t</span> <a class="code" href="classmeow_1_1SegmentTree.html#a8985a196cfb954bc469e7dae146ad4ed">size</a>, Value <span class="keyword">const</span>&amp; value, <span class="keywordtype">bool</span> <span class="keyword">override</span>) {</div>
<div class="line"><a name="l00057"></a><span class="lineno">   57</span>&#160;    <span class="keywordflow">if</span> (<span class="keyword">override</span>) {</div>
<div class="line"><a name="l00058"></a><span class="lineno">   58</span>&#160;      nodes_[index].value_    = value * <a class="code" href="classmeow_1_1SegmentTree.html#a8985a196cfb954bc469e7dae146ad4ed">size</a>;</div>
<div class="line"><a name="l00059"></a><span class="lineno">   59</span>&#160;      nodes_[index].offset_   = value;</div>
<div class="line"><a name="l00060"></a><span class="lineno">   60</span>&#160;      nodes_[index].sameFlage_ = <span class="keyword">true</span>;</div>
<div class="line"><a name="l00061"></a><span class="lineno">   61</span>&#160;    }</div>
<div class="line"><a name="l00062"></a><span class="lineno">   62</span>&#160;    <span class="keywordflow">else</span> {</div>
<div class="line"><a name="l00063"></a><span class="lineno">   63</span>&#160;      nodes_[index].value_  = nodes_[index].value_  + value * <a class="code" href="classmeow_1_1SegmentTree.html#a8985a196cfb954bc469e7dae146ad4ed">size</a>;</div>
<div class="line"><a name="l00064"></a><span class="lineno">   64</span>&#160;      nodes_[index].offset_ = nodes_[index].offset_ + value;</div>
<div class="line"><a name="l00065"></a><span class="lineno">   65</span>&#160;    }</div>
<div class="line"><a name="l00066"></a><span class="lineno">   66</span>&#160;  }</div>
<div class="line"><a name="l00067"></a><span class="lineno">   67</span>&#160;  <span class="keywordtype">void</span> update(<span class="keywordtype">size_t</span> l, <span class="keywordtype">size_t</span> r, <span class="keywordtype">size_t</span> L, <span class="keywordtype">size_t</span> R,</div>
<div class="line"><a name="l00068"></a><span class="lineno">   68</span>&#160;              <span class="keywordtype">size_t</span> index, Value <span class="keyword">const</span>&amp; value,</div>
<div class="line"><a name="l00069"></a><span class="lineno">   69</span>&#160;              <span class="keywordtype">bool</span> <span class="keyword">override</span>) {</div>
<div class="line"><a name="l00070"></a><span class="lineno">   70</span>&#160;    <span class="keywordflow">if</span> (l == L &amp;&amp; r == R) {</div>
<div class="line"><a name="l00071"></a><span class="lineno">   71</span>&#160;      update(index, R - L + 1, value, <span class="keyword">override</span>);</div>
<div class="line"><a name="l00072"></a><span class="lineno">   72</span>&#160;      return ;</div>
<div class="line"><a name="l00073"></a><span class="lineno">   73</span>&#160;    }</div>
<div class="line"><a name="l00074"></a><span class="lineno">   74</span>&#160;    <span class="keywordtype">size_t</span> mid = (L + R) / 2;</div>
<div class="line"><a name="l00075"></a><span class="lineno">   75</span>&#160;    <span class="keywordflow">if</span> (L &lt; R) {</div>
<div class="line"><a name="l00076"></a><span class="lineno">   76</span>&#160;      update(index * 2 + 1, mid - L + 1,</div>
<div class="line"><a name="l00077"></a><span class="lineno">   77</span>&#160;             nodes_[index].offset_, nodes_[index].sameFlage_);</div>
<div class="line"><a name="l00078"></a><span class="lineno">   78</span>&#160;      update(index * 2 + 2, R - mid,</div>
<div class="line"><a name="l00079"></a><span class="lineno">   79</span>&#160;             nodes_[index].offset_, nodes_[index].sameFlage_);</div>
<div class="line"><a name="l00080"></a><span class="lineno">   80</span>&#160;      nodes_[index].offset_ = Value(0);</div>
<div class="line"><a name="l00081"></a><span class="lineno">   81</span>&#160;      nodes_[index].sameFlage_ = <span class="keyword">false</span>;</div>
<div class="line"><a name="l00082"></a><span class="lineno">   82</span>&#160;    }</div>
<div class="line"><a name="l00083"></a><span class="lineno">   83</span>&#160;    <span class="keywordflow">if</span> (r &lt;= mid) {</div>
<div class="line"><a name="l00084"></a><span class="lineno">   84</span>&#160;      update(l, r, L ,mid, index * 2 + 1, value, <span class="keyword">override</span>);</div>
<div class="line"><a name="l00085"></a><span class="lineno">   85</span>&#160;    }</div>
<div class="line"><a name="l00086"></a><span class="lineno">   86</span>&#160;    <span class="keywordflow">else</span> <span class="keywordflow">if</span> (mid + 1 &lt;= l) {</div>
<div class="line"><a name="l00087"></a><span class="lineno">   87</span>&#160;      update(l, r, mid + 1,R, index*2 + 2, value, <span class="keyword">override</span>);</div>
<div class="line"><a name="l00088"></a><span class="lineno">   88</span>&#160;    }</div>
<div class="line"><a name="l00089"></a><span class="lineno">   89</span>&#160;    <span class="keywordflow">else</span> {</div>
<div class="line"><a name="l00090"></a><span class="lineno">   90</span>&#160;      update(l, mid       , L, mid       , index * 2 + 1, value, <span class="keyword">override</span>);</div>
<div class="line"><a name="l00091"></a><span class="lineno">   91</span>&#160;      update(   mid + 1, r,    mid + 1, R, index * 2 + 2, value, <span class="keyword">override</span>);</div>
<div class="line"><a name="l00092"></a><span class="lineno">   92</span>&#160;    }</div>
<div class="line"><a name="l00093"></a><span class="lineno">   93</span>&#160;    nodes_[index].value_ = (</div>
<div class="line"><a name="l00094"></a><span class="lineno">   94</span>&#160;      (nodes_[index * 2 + 1].value_ | nodes_[index * 2 + 2].value_)</div>
<div class="line"><a name="l00095"></a><span class="lineno">   95</span>&#160;      + nodes_[index].offset_</div>
<div class="line"><a name="l00096"></a><span class="lineno">   96</span>&#160;    );</div>
<div class="line"><a name="l00097"></a><span class="lineno">   97</span>&#160;  }</div>
<div class="line"><a name="l00098"></a><span class="lineno">   98</span>&#160;  Value query(<span class="keywordtype">size_t</span> l, <span class="keywordtype">size_t</span> r, <span class="keywordtype">size_t</span> L, <span class="keywordtype">size_t</span> R, <span class="keywordtype">size_t</span> index) {</div>
<div class="line"><a name="l00099"></a><span class="lineno">   99</span>&#160;    <span class="keywordflow">if</span> (l == L &amp;&amp; r == R) <span class="keywordflow">return</span> nodes_[index].value_;</div>
<div class="line"><a name="l00100"></a><span class="lineno">  100</span>&#160;    Value off = nodes_[index].offset_ * (r - l + 1);</div>
<div class="line"><a name="l00101"></a><span class="lineno">  101</span>&#160;    <span class="keywordflow">if</span> (nodes_[index].sameFlage_) <span class="keywordflow">return</span> off;</div>
<div class="line"><a name="l00102"></a><span class="lineno">  102</span>&#160;    <span class="keywordtype">size_t</span> mid = (L + R) / 2;</div>
<div class="line"><a name="l00103"></a><span class="lineno">  103</span>&#160;    <span class="keywordflow">if</span>     (r       &lt;= mid) <span class="keywordflow">return</span> query(l, r, L   ,  mid, index * 2 + 1) + off;</div>
<div class="line"><a name="l00104"></a><span class="lineno">  104</span>&#160;    <span class="keywordflow">else</span> <span class="keywordflow">if</span>(mid + 1 &lt;=   l) <span class="keywordflow">return</span> query(l, r, mid + 1, R, index * 2 + 2) + off;</div>
<div class="line"><a name="l00105"></a><span class="lineno">  105</span>&#160;    <span class="keywordflow">else</span>{</div>
<div class="line"><a name="l00106"></a><span class="lineno">  106</span>&#160;      <span class="keywordflow">return</span> (  query(l, mid       , L,  mid       , index * 2 + 1)</div>
<div class="line"><a name="l00107"></a><span class="lineno">  107</span>&#160;              | query(   mid + 1, r,     mid + 1, R, index * 2 + 2)</div>
<div class="line"><a name="l00108"></a><span class="lineno">  108</span>&#160;      ) + off;</div>
<div class="line"><a name="l00109"></a><span class="lineno">  109</span>&#160;    }</div>
<div class="line"><a name="l00110"></a><span class="lineno">  110</span>&#160;  }</div>
<div class="line"><a name="l00111"></a><span class="lineno">  111</span>&#160;  <span class="comment">//</span></div>
<div class="line"><a name="l00112"></a><span class="lineno">  112</span>&#160;  <span class="keywordtype">bool</span> rangeCorrect(ssize_t* first, ssize_t* last)<span class="keyword"> const </span>{</div>
<div class="line"><a name="l00113"></a><span class="lineno">  113</span>&#160;    <span class="keywordflow">if</span> (*last &lt; *first || *last &lt; 0 || (ssize_t)size_ - 1 &lt; *first)</div>
<div class="line"><a name="l00114"></a><span class="lineno">  114</span>&#160;      <span class="keywordflow">return</span> <span class="keyword">false</span>;</div>
<div class="line"><a name="l00115"></a><span class="lineno">  115</span>&#160;    *first = <a class="code" href="namespacemeow.html#a98d838d338a3e6f3c57e94562fab3fa7">inRange</a>((ssize_t)0, (ssize_t)size_ - 1, *first);</div>
<div class="line"><a name="l00116"></a><span class="lineno">  116</span>&#160;    *last  = <a class="code" href="namespacemeow.html#a98d838d338a3e6f3c57e94562fab3fa7">inRange</a>((ssize_t)0, (ssize_t)size_ - 1, *last );</div>
<div class="line"><a name="l00117"></a><span class="lineno">  117</span>&#160;    <span class="keywordflow">return</span> <span class="keyword">true</span>;</div>
<div class="line"><a name="l00118"></a><span class="lineno">  118</span>&#160;  }</div>
<div class="line"><a name="l00119"></a><span class="lineno">  119</span>&#160;<span class="keyword">public</span>:</div>
<div class="line"><a name="l00121"></a><span class="lineno"><a class="line" href="classmeow_1_1SegmentTree.html#a8e8365f0440c68f3c0853b94a7de3ccb">  121</a></span>&#160;  <a class="code" href="classmeow_1_1SegmentTree.html#a8e8365f0440c68f3c0853b94a7de3ccb">SegmentTree</a>() {</div>
<div class="line"><a name="l00122"></a><span class="lineno">  122</span>&#160;    <a class="code" href="classmeow_1_1SegmentTree.html#a80c550b0a3b997bc541ae0947ae2f55d">reset</a>(1);</div>
<div class="line"><a name="l00123"></a><span class="lineno">  123</span>&#160;  }</div>
<div class="line"><a name="l00124"></a><span class="lineno">  124</span>&#160;</div>
<div class="line"><a name="l00126"></a><span class="lineno"><a class="line" href="classmeow_1_1SegmentTree.html#a1fe904372d3cdd01f07a1c88f86b14a1">  126</a></span>&#160;  <a class="code" href="classmeow_1_1SegmentTree.html#a1fe904372d3cdd01f07a1c88f86b14a1">SegmentTree</a>(<span class="keywordtype">size_t</span> size) {</div>
<div class="line"><a name="l00127"></a><span class="lineno">  127</span>&#160;    <a class="code" href="classmeow_1_1SegmentTree.html#a80c550b0a3b997bc541ae0947ae2f55d">reset</a>(size);</div>
<div class="line"><a name="l00128"></a><span class="lineno">  128</span>&#160;  }</div>
<div class="line"><a name="l00129"></a><span class="lineno">  129</span>&#160;</div>
<div class="line"><a name="l00131"></a><span class="lineno"><a class="line" href="classmeow_1_1SegmentTree.html#a12a47cdf24eacb80d0bad4010f6a2953">  131</a></span>&#160;  <a class="code" href="classmeow_1_1SegmentTree.html#a12a47cdf24eacb80d0bad4010f6a2953">SegmentTree</a>(<a class="code" href="classmeow_1_1SegmentTree.html">SegmentTree</a> <span class="keyword">const</span>&amp; tree2):</div>
<div class="line"><a name="l00132"></a><span class="lineno">  132</span>&#160;  size_(tree2.size_), nodes_(tree2.nodes_) {</div>
<div class="line"><a name="l00133"></a><span class="lineno">  133</span>&#160;  }</div>
<div class="line"><a name="l00134"></a><span class="lineno">  134</span>&#160;</div>
<div class="line"><a name="l00138"></a><span class="lineno"><a class="line" href="classmeow_1_1SegmentTree.html#a889f38048ffe08ce3c80911878faac44">  138</a></span>&#160;  <a class="code" href="classmeow_1_1SegmentTree.html">SegmentTree</a> <a class="code" href="classmeow_1_1SegmentTree.html#a889f38048ffe08ce3c80911878faac44">copyFrom</a>(<a class="code" href="classmeow_1_1SegmentTree.html">SegmentTree</a> <span class="keyword">const</span>&amp; b) {</div>
<div class="line"><a name="l00139"></a><span class="lineno">  139</span>&#160;    size_  = b.size_;</div>
<div class="line"><a name="l00140"></a><span class="lineno">  140</span>&#160;    nodes_ = b.nodes_;</div>
<div class="line"><a name="l00141"></a><span class="lineno">  141</span>&#160;    <span class="keywordflow">return</span> *<span class="keyword">this</span>;</div>
<div class="line"><a name="l00142"></a><span class="lineno">  142</span>&#160;  }</div>
<div class="line"><a name="l00143"></a><span class="lineno">  143</span>&#160;</div>
<div class="line"><a name="l00147"></a><span class="lineno"><a class="line" href="classmeow_1_1SegmentTree.html#a8985a196cfb954bc469e7dae146ad4ed">  147</a></span>&#160;  <span class="keywordtype">size_t</span> <a class="code" href="classmeow_1_1SegmentTree.html#a8985a196cfb954bc469e7dae146ad4ed">size</a>()<span class="keyword"> const </span>{</div>
<div class="line"><a name="l00148"></a><span class="lineno">  148</span>&#160;    <span class="keywordflow">return</span> size_;</div>
<div class="line"><a name="l00149"></a><span class="lineno">  149</span>&#160;  }</div>
<div class="line"><a name="l00150"></a><span class="lineno">  150</span>&#160;</div>
<div class="line"><a name="l00154"></a><span class="lineno"><a class="line" href="classmeow_1_1SegmentTree.html#a80c550b0a3b997bc541ae0947ae2f55d">  154</a></span>&#160;  <span class="keywordtype">void</span> <a class="code" href="classmeow_1_1SegmentTree.html#a80c550b0a3b997bc541ae0947ae2f55d">reset</a>(<span class="keywordtype">size_t</span> size){</div>
<div class="line"><a name="l00155"></a><span class="lineno">  155</span>&#160;    size_ = std::max(size, (<span class="keywordtype">size_t</span>)1);</div>
<div class="line"><a name="l00156"></a><span class="lineno">  156</span>&#160;    nodes_.resize(size * 4);</div>
<div class="line"><a name="l00157"></a><span class="lineno">  157</span>&#160;    nodes_[0].sameFlage_ = <span class="keyword">true</span>;</div>
<div class="line"><a name="l00158"></a><span class="lineno">  158</span>&#160;    nodes_[0].value_  = Value(0);</div>
<div class="line"><a name="l00159"></a><span class="lineno">  159</span>&#160;    nodes_[0].offset_ = Value(0);</div>
<div class="line"><a name="l00160"></a><span class="lineno">  160</span>&#160;  }</div>
<div class="line"><a name="l00161"></a><span class="lineno">  161</span>&#160;</div>
<div class="line"><a name="l00165"></a><span class="lineno"><a class="line" href="classmeow_1_1SegmentTree.html#a18bb3667abd9810ce3534af3d70b14d5">  165</a></span>&#160;  Value <a class="code" href="classmeow_1_1SegmentTree.html#a18bb3667abd9810ce3534af3d70b14d5">query</a>(ssize_t first, ssize_t last)<span class="keyword"> const </span>{</div>
<div class="line"><a name="l00166"></a><span class="lineno">  166</span>&#160;    <span class="keywordflow">if</span> (rangeCorrect(&amp;first, &amp;last) == <span class="keyword">false</span>) <span class="keywordflow">return</span> Value();</div>
<div class="line"><a name="l00167"></a><span class="lineno">  167</span>&#160;    <span class="keywordflow">return</span> ((<a class="code" href="classmeow_1_1SegmentTree.html">SegmentTree</a>*)<span class="keyword">this</span>)-&gt;query(first, last, 0, size_ - 1, 0);</div>
<div class="line"><a name="l00168"></a><span class="lineno">  168</span>&#160;  }</div>
<div class="line"><a name="l00169"></a><span class="lineno">  169</span>&#160;</div>
<div class="line"><a name="l00173"></a><span class="lineno"><a class="line" href="classmeow_1_1SegmentTree.html#a2f300a5fd5ffdd19e4b3efc6899a7439">  173</a></span>&#160;  <span class="keywordtype">void</span> <span class="keyword">override</span>(ssize_t first, ssize_t last, Value <span class="keyword">const</span>&amp; value) {</div>
<div class="line"><a name="l00174"></a><span class="lineno">  174</span>&#160;    <span class="keywordflow">if</span> (rangeCorrect(&amp;first, &amp;last) == <span class="keyword">false</span>) <span class="keywordflow">return</span> ;</div>
<div class="line"><a name="l00175"></a><span class="lineno">  175</span>&#160;    update(first, last, 0, size_ - 1, 0, value, <span class="keyword">true</span>);</div>
<div class="line"><a name="l00176"></a><span class="lineno">  176</span>&#160;  }</div>
<div class="line"><a name="l00177"></a><span class="lineno">  177</span>&#160;</div>
<div class="line"><a name="l00181"></a><span class="lineno"><a class="line" href="classmeow_1_1SegmentTree.html#aaeca3de355dc367e2664e83800ee6aa5">  181</a></span>&#160;  <span class="keywordtype">void</span> <a class="code" href="classmeow_1_1SegmentTree.html#aaeca3de355dc367e2664e83800ee6aa5">offset</a>(ssize_t first, ssize_t last, Value <span class="keyword">const</span>&amp; delta) {</div>
<div class="line"><a name="l00182"></a><span class="lineno">  182</span>&#160;    <span class="keywordflow">if</span> (rangeCorrect(&amp;first, &amp;last) == <span class="keyword">false</span>) return ;</div>
<div class="line"><a name="l00183"></a><span class="lineno">  183</span>&#160;    update(first, last, 0, size_ - 1, 0, delta, <span class="keyword">false</span>);</div>
<div class="line"><a name="l00184"></a><span class="lineno">  184</span>&#160;  }</div>
<div class="line"><a name="l00185"></a><span class="lineno">  185</span>&#160;</div>
<div class="line"><a name="l00187"></a><span class="lineno"><a class="line" href="classmeow_1_1SegmentTree.html#a765e794af604ab7c20a4245dfafcf14c">  187</a></span>&#160;  <a class="code" href="classmeow_1_1SegmentTree.html">SegmentTree</a>&amp; <a class="code" href="classmeow_1_1SegmentTree.html#a765e794af604ab7c20a4245dfafcf14c">operator=</a>(<a class="code" href="classmeow_1_1SegmentTree.html">SegmentTree</a> <span class="keyword">const</span>&amp; b) {</div>
<div class="line"><a name="l00188"></a><span class="lineno">  188</span>&#160;    <span class="keywordflow">return</span> <a class="code" href="classmeow_1_1SegmentTree.html#a889f38048ffe08ce3c80911878faac44">copyFrom</a>(b);</div>
<div class="line"><a name="l00189"></a><span class="lineno">  189</span>&#160;  }</div>
<div class="line"><a name="l00190"></a><span class="lineno">  190</span>&#160;};</div>
<div class="line"><a name="l00191"></a><span class="lineno">  191</span>&#160;</div>
<div class="line"><a name="l00192"></a><span class="lineno">  192</span>&#160;} <span class="comment">// meow</span></div>
<div class="line"><a name="l00193"></a><span class="lineno">  193</span>&#160;</div>
<div class="line"><a name="l00194"></a><span class="lineno">  194</span>&#160;<span class="preprocessor">#endif // dsa_SegmentTree_H__</span></div>
<div class="ttc" id="classmeow_1_1SegmentTree_html_a8e8365f0440c68f3c0853b94a7de3ccb"><div class="ttname"><a href="classmeow_1_1SegmentTree.html#a8e8365f0440c68f3c0853b94a7de3ccb">meow::SegmentTree::SegmentTree</a></div><div class="ttdeci">SegmentTree()</div><div class="ttdoc">constructor </div><div class="ttdef"><b>Definition:</b> <a href="SegmentTree_8h_source.html#l00121">SegmentTree.h:121</a></div></div>
<div class="ttc" id="classmeow_1_1SegmentTree_html"><div class="ttname"><a href="classmeow_1_1SegmentTree.html">meow::SegmentTree</a></div><div class="ttdoc">中文名 線段樹 </div><div class="ttdef"><b>Definition:</b> <a href="SegmentTree_8h_source.html#l00045">SegmentTree.h:45</a></div></div>
<div class="ttc" id="classmeow_1_1SegmentTree_html_a8985a196cfb954bc469e7dae146ad4ed"><div class="ttname"><a href="classmeow_1_1SegmentTree.html#a8985a196cfb954bc469e7dae146ad4ed">meow::SegmentTree::size</a></div><div class="ttdeci">size_t size() const </div><div class="ttdoc">回傳size </div><div class="ttdef"><b>Definition:</b> <a href="SegmentTree_8h_source.html#l00147">SegmentTree.h:147</a></div></div>
<div class="ttc" id="classmeow_1_1SegmentTree_html_aaeca3de355dc367e2664e83800ee6aa5"><div class="ttname"><a href="classmeow_1_1SegmentTree.html#aaeca3de355dc367e2664e83800ee6aa5">meow::SegmentTree::offset</a></div><div class="ttdeci">void offset(ssize_t first, ssize_t last, Value const &amp;delta)</div><div class="ttdoc">將區間 [first,last] 全部都加上 delta </div><div class="ttdef"><b>Definition:</b> <a href="SegmentTree_8h_source.html#l00181">SegmentTree.h:181</a></div></div>
<div class="ttc" id="classmeow_1_1SegmentTree_html_a765e794af604ab7c20a4245dfafcf14c"><div class="ttname"><a href="classmeow_1_1SegmentTree.html#a765e794af604ab7c20a4245dfafcf14c">meow::SegmentTree::operator=</a></div><div class="ttdeci">SegmentTree &amp; operator=(SegmentTree const &amp;b)</div><div class="ttdoc">same as copyFrom(b) </div><div class="ttdef"><b>Definition:</b> <a href="SegmentTree_8h_source.html#l00187">SegmentTree.h:187</a></div></div>
<div class="ttc" id="classmeow_1_1SegmentTree_html_a889f38048ffe08ce3c80911878faac44"><div class="ttname"><a href="classmeow_1_1SegmentTree.html#a889f38048ffe08ce3c80911878faac44">meow::SegmentTree::copyFrom</a></div><div class="ttdeci">SegmentTree copyFrom(SegmentTree const &amp;b)</div><div class="ttdoc">複製 </div><div class="ttdef"><b>Definition:</b> <a href="SegmentTree_8h_source.html#l00138">SegmentTree.h:138</a></div></div>
<div class="ttc" id="classmeow_1_1SegmentTree_html_a12a47cdf24eacb80d0bad4010f6a2953"><div class="ttname"><a href="classmeow_1_1SegmentTree.html#a12a47cdf24eacb80d0bad4010f6a2953">meow::SegmentTree::SegmentTree</a></div><div class="ttdeci">SegmentTree(SegmentTree const &amp;tree2)</div><div class="ttdoc">constructor, 並且複製資料 </div><div class="ttdef"><b>Definition:</b> <a href="SegmentTree_8h_source.html#l00131">SegmentTree.h:131</a></div></div>
<div class="ttc" id="classmeow_1_1SegmentTree_html_a1fe904372d3cdd01f07a1c88f86b14a1"><div class="ttname"><a href="classmeow_1_1SegmentTree.html#a1fe904372d3cdd01f07a1c88f86b14a1">meow::SegmentTree::SegmentTree</a></div><div class="ttdeci">SegmentTree(size_t size)</div><div class="ttdoc">constructor, with size gived </div><div class="ttdef"><b>Definition:</b> <a href="SegmentTree_8h_source.html#l00126">SegmentTree.h:126</a></div></div>
<div class="ttc" id="namespacemeow_html_a98d838d338a3e6f3c57e94562fab3fa7"><div class="ttname"><a href="namespacemeow.html#a98d838d338a3e6f3c57e94562fab3fa7">meow::inRange</a></div><div class="ttdeci">T inRange(T const &amp;mn, T const &amp;mx, T const &amp;v)</div><div class="ttdoc">std::min(mx,std::max(mn,v)) </div><div class="ttdef"><b>Definition:</b> <a href="math_2utility_8h_source.html#l00061">utility.h:61</a></div></div>
<div class="ttc" id="classmeow_1_1SegmentTree_html_a80c550b0a3b997bc541ae0947ae2f55d"><div class="ttname"><a href="classmeow_1_1SegmentTree.html#a80c550b0a3b997bc541ae0947ae2f55d">meow::SegmentTree::reset</a></div><div class="ttdeci">void reset(size_t size)</div><div class="ttdoc">將資料清空且設定維護範圍是 0~size-1 </div><div class="ttdef"><b>Definition:</b> <a href="SegmentTree_8h_source.html#l00154">SegmentTree.h:154</a></div></div>
<div class="ttc" id="classmeow_1_1SegmentTree_html_a18bb3667abd9810ce3534af3d70b14d5"><div class="ttname"><a href="classmeow_1_1SegmentTree.html#a18bb3667abd9810ce3534af3d70b14d5">meow::SegmentTree::query</a></div><div class="ttdeci">Value query(ssize_t first, ssize_t last) const </div><div class="ttdoc">回傳區間 [first,last] (邊界都含) 的區間值 </div><div class="ttdef"><b>Definition:</b> <a href="SegmentTree_8h_source.html#l00165">SegmentTree.h:165</a></div></div>
</div><!-- fragment --></div><!-- contents -->
</div><!-- doc-content -->
<!-- HTML footer for doxygen 1.8.3.1-->
<!-- start footer part -->
<div id="nav-path" class="navpath"><!-- id is needed for treeview function! -->
  <ul>
    <li class="navelem"><a class="el" href="dir_92fecd8d02dd5e7a67429447fdf0f60f.html">meowpp</a></li><li class="navelem"><a class="el" href="dir_a17ff8dcb3a1c1b842af541700214096.html">dsa</a></li><li class="navelem"><a class="el" href="SegmentTree_8h.html">SegmentTree.h</a></li>
    <li class="footer">Generated on Mon Sep 8 2014 21:25:40 for Templates -- Meow by
    <a href="http://www.doxygen.org/index.html">
    <img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.8.6 </li>
  </ul>
</div>
</body>
</html>