锘??xml version="1.0" encoding="utf-8" standalone="yes"?>久久99国产精品久久99果冻传媒,国产午夜久久影院,久久久这里有精品中文字幕http://cppblog.com/y346491470/category/17778.html涓烘ⅵ鎯寵屽鏂楋紒zh-cnTue, 03 Apr 2012 11:17:37 GMTTue, 03 Apr 2012 11:17:37 GMT60hdoj 4193 Non-negative Partial Sums - 鍗曡皟闃熷垪http://www.shnenglu.com/y346491470/articles/169921.htmly @ The Angry Teletubbiesy @ The Angry TeletubbiesTue, 03 Apr 2012 03:56:00 GMThttp://www.shnenglu.com/y346491470/articles/169921.htmlhttp://www.shnenglu.com/y346491470/comments/169921.htmlhttp://www.shnenglu.com/y346491470/articles/169921.html#Feedback0http://www.shnenglu.com/y346491470/comments/commentRss/169921.htmlhttp://www.shnenglu.com/y346491470/services/trackbacks/169921.html
銆愰瑙c戯細棣栧厛鎶婄幆搴忓垪鍒囨柇錛屽彉鎴愪袱鍊嶉暱搴︺傞澶勭悊鎵鏈夊墠 i 欏瑰拰銆?br />               鏋氫婦璧風偣j錛屼嬌鐢ㄥ崟璋冮槦鍒楁眰鍖洪棿鏈灝忓鹼紝濡傛灉鏈灝忓煎ぇ浜巗um[j]鍒欑瓟妗堝姞涓銆?br />
銆愪唬鐮併戯細
 1 #include "iostream"
 2 #include "cstdio"
 3 #include "cstring"
 4 #include "algorithm"
 5 #include "vector"
 6 #include "queue"
 7 #include "cmath"
 8 #include "string"
 9 #include "cctype"
10 #include "map"
11 #include "iomanip"
12 using namespace std;
13 #define pb push_back
14 #define mp make_pair
15 #define fi first
16 #define se second
17 #define lc(x) (x << 1)
18 #define rc(x) (x << 1 | 1)
19 #define lowbit(x) (x & (-x))
20 #define ll long long
21 #define maxn 1000050
22 int n;
23 int val[maxn];
24 int sum[maxn<<1];
25 int que[maxn<<1], head, tail;
26 
27 int main() {
28     while(~scanf("%d", &n)) {
29         if(!n) break;
30         sum[0] = 0;
31         for(int i = 1; i <= n; i++) {
32             scanf("%d", &val[i]);
33             sum[i] = sum[i-1] + val[i];
34         }
35         for(int i = n + 1; i <= 2 * n; i++) {
36             sum[i] = sum[i-1] + val[i-n];
37         }
38         int ans = 0;
39         head = tail = 0;
40         que[tail++] = 0;
41         for(int i = 1; i <= 2 * n; i++) {
42             if(i > n) {
43                 while(head < tail && que[head] < i - n - 1) head++;
44                 if(sum[que[head]] >= sum[i-n-1]) ans++;
45             }
46             while(head < tail && sum[que[tail-1]] > sum[i]) tail--;
47             que[tail++] = i;
48         }
49         cout << ans << endl;
50     }
51 
52     return 0;
53 }
54 


y @ The Angry Teletubbies 2012-04-03 11:56 鍙戣〃璇勮
]]>
hdoj 3415 Max Sum of Max-K-sub-sequence - 鍗曡皟闃熷垪http://www.shnenglu.com/y346491470/articles/169893.htmly @ The Angry Teletubbiesy @ The Angry TeletubbiesMon, 02 Apr 2012 13:14:00 GMThttp://www.shnenglu.com/y346491470/articles/169893.htmlhttp://www.shnenglu.com/y346491470/comments/169893.htmlhttp://www.shnenglu.com/y346491470/articles/169893.html#Feedback0http://www.shnenglu.com/y346491470/comments/commentRss/169893.htmlhttp://www.shnenglu.com/y346491470/services/trackbacks/169893.html
銆愰瑙c戯細寰堝鏄撴兂鍒癘(n*k)鐨勫仛娉曪紝浣嗘槸璧よ8瑁哥殑TLE銆?br />               鍏堟眰鍑烘墍鏈夊墠n欏瑰拰銆?br />               鏋氫婦姣忎竴涓綅緗?i 浣滀負緇撴潫鐐癸紝鐜板湪鎴戜滑瑕佹壘鍒版渶灝忕殑sum[j], i - k <= j < i .
               鏈寸礌鍋氭硶鏄洿鎺ユ灇涓綩(k)錛屾敼榪涗竴鐐圭殑鍋氭硶鏄敤綰挎鏍戞煡璇㈠尯闂存渶澶у糘(logk).
               浣嗘槸鍙互璇佹槑鏈夊崟璋冩э紝鏁呭彲浠ョ敤鍗曡皟闃熷垪浼樺寲錛屾煡璇㈢洿鎺ヤ紭鍖栧埌O(1)銆?br />               鎵浠ユ渶緇堝鏉傚害鏄疧(n)銆?br />
銆愪唬鐮併戯細
 1 #include "iostream"
 2 #include "cstdio"
 3 #include "cstring"
 4 #include "algorithm"
 5 #include "vector"
 6 #include "queue"
 7 #include "cmath"
 8 #include "string"
 9 #include "cctype"
10 #include "map"
11 #include "iomanip"
12 using namespace std;
13 #define pb push_back
14 #define mp make_pair
15 #define fi first
16 #define se second
17 #define lc(x) (x << 1)
18 #define rc(x) (x << 1 | 1)
19 #define lowbit(x) (x & (-x))
20 #define ll long long
21 #define maxn 100050
22 const int inf = 1 << 30;
23 int que[maxn<<1], head, tail;
24 int sum[maxn<<1];
25 int val[maxn];
26 int n, k;
27 int ans, s, t;
28 int main() {
29     int T;
30     scanf("%d", &T);
31     while(T--) {
32         scanf("%d%d", &n, &k);
33         sum[0] = 0;
34         for(int i = 1; i <= n; i++) {
35             scanf("%d", &val[i]);
36             sum[i] = val[i] + sum[i-1];
37         }
38         for(int i = n + 1; i <= 2 * n; i++) {
39             sum[i] = sum[i-1] + val[i-n];
40         }
41         ans = -inf;
42         head = tail = 0;
43         que[tail++] = 0;
44         for(int i = 1; i <= 2 * n; i++) {
45             while(head < tail && que[head] < i - k) head++;
46             if(ans < sum[i] - sum[que[head]]) {
47                 ans = sum[i] - sum[que[head]];
48                 s = que[head] + 1, t = i;
49             }
50             while(head < tail && sum[que[tail-1]] > sum[i]) tail--;
51             que[tail++] = i;
52         }
53         if(s > n) s -= n;
54         if(t > n) t -= n;
55         cout << ans << " " << s << " " << t << endl;
56     }
57     return 0;
58 }
59 


y @ The Angry Teletubbies 2012-04-02 21:14 鍙戣〃璇勮
]]>
poj 1703 Find them, Catch them - 騫舵煡闆?/title><link>http://www.shnenglu.com/y346491470/articles/167425.html</link><dc:creator>y @ The Angry Teletubbies</dc:creator><author>y @ The Angry Teletubbies</author><pubDate>Thu, 08 Mar 2012 10:32:00 GMT</pubDate><guid>http://www.shnenglu.com/y346491470/articles/167425.html</guid><wfw:comment>http://www.shnenglu.com/y346491470/comments/167425.html</wfw:comment><comments>http://www.shnenglu.com/y346491470/articles/167425.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.shnenglu.com/y346491470/comments/commentRss/167425.html</wfw:commentRss><trackback:ping>http://www.shnenglu.com/y346491470/services/trackbacks/167425.html</trackback:ping><description><![CDATA[銆愰鎰忋戯細<span style="background-color: #ffffff; font-family: Arial; line-height: 26px; text-align: left; ">鏈塶涓粦甯洟浼欐垚鍛橈紝涓旀湁涓や釜甯淳 銆?br /></span>               D x y 琛ㄧず x y灞炰簬涓嶅悓鐨勫府媧撅紱<br />               A x y 璇㈤棶 x y鐨勫叧緋匯?br />               鍏崇郴鏈変笁縐嶏細1.Not sure yet. 2.In different gangs. 3.In the same gangs.<br />               緇欏嚭m涓搷浣滐紝鍥炵瓟鎵鏈夎闂?br /><br />銆愰瑙c戯細騫舵煡闆嗛鐩紝鍙槸鎯充笉鍑烘潵錛岀粰闃熷弸鐐規槑浜嗐?br />               瀵逛簬姣忎釜浜猴紝鎷嗙偣x x’銆?br />               瀵逛簬D x y榪欎釜鎿嶄綔,鎶妜鍜寉’鎵鍦ㄧ殑鍒嗛噺鍚堝茍錛寈’鍜寉鎵鍦ㄧ殑鍒嗛噺鍚堝茍銆?br />               瀵逛簬A x y榪欎釜璇㈤棶,<br />                        濡傛灉find(x) == find(y)錛屽垯浠栦滑灞炰簬鍚屼竴涓府媧撅紱<br />                        鍚﹀垯錛屽鏋渇ind(x) == find(y')錛屼粬浠睘浜庝笉鍚屽府媧撅紱<br />                        鍚﹀垯錛屼粬浠殑鍏崇郴涓嶇‘瀹氥?br /><br />               鏈濂藉湪綰鎬笂鐢諱笅鍥撅紝榪欐牱姣旇緝瀹規槗鐞嗚В銆?br /><br />銆愪唬鐮併戯細<br /><div style="background-color:#eeeeee;font-size:13px;border:1px solid #CCCCCC;padding-right: 5px;padding-bottom: 4px;padding-left: 4px;padding-top: 4px;width: 98%;word-break:break-all"><!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />--><span style="color: #008080; "> 1</span> #include "iostream"<br /><span style="color: #008080; "> 2</span> #include "cstdio"<br /><span style="color: #008080; "> 3</span> #include "cstring"<br /><span style="color: #008080; "> 4</span> #include "algorithm"<br /><span style="color: #008080; "> 5</span> #include "vector"<br /><span style="color: #008080; "> 6</span> #include "queue"<br /><span style="color: #008080; "> 7</span> #include "cmath"<br /><span style="color: #008080; "> 8</span> #include "string"<br /><span style="color: #008080; "> 9</span> #include "cctype"<br /><span style="color: #008080; ">10</span> #include "map"<br /><span style="color: #008080; ">11</span> #include "iomanip"<br /><span style="color: #008080; ">12</span> <span style="color: #0000FF; ">using</span> <span style="color: #0000FF; ">namespace</span> std;<br /><span style="color: #008080; ">13</span> <span style="color: #0000FF; ">#define</span> pb push_back<br /><span style="color: #008080; ">14</span> <span style="color: #0000FF; ">#define</span> lc(x) (x << 1)<br /><span style="color: #008080; ">15</span> <span style="color: #0000FF; ">#define</span> rc(x) (x << 1 | 1)<br /><span style="color: #008080; ">16</span> <span style="color: #0000FF; ">#define</span> lowbit(x) (x & (-x))<br /><span style="color: #008080; ">17</span> <span style="color: #0000FF; ">#define</span> ll long long<br /><span style="color: #008080; ">18</span> <span style="color: #0000FF; ">#define</span> maxn 200050<br /><span style="color: #008080; ">19</span> <span style="color: #0000FF; ">int</span> n, m;<br /><span style="color: #008080; ">20</span> <span style="color: #0000FF; ">int</span> fa[maxn];<br /><span style="color: #008080; ">21</span> <br /><span style="color: #008080; ">22</span> <span style="color: #0000FF; ">void</span> init() {<br /><span style="color: #008080; ">23</span>     <span style="color: #0000FF; ">for</span>(<span style="color: #0000FF; ">int</span> i = 0; i < maxn; i++) fa[i] = i;<br /><span style="color: #008080; ">24</span> }<br /><span style="color: #008080; ">25</span> <br /><span style="color: #008080; ">26</span> <span style="color: #0000FF; ">int</span> find(<span style="color: #0000FF; ">int</span> x) {<br /><span style="color: #008080; ">27</span>     <span style="color: #0000FF; ">if</span>(x != fa[x]) <span style="color: #0000FF; ">return</span> fa[x] = find(fa[x]);<br /><span style="color: #008080; ">28</span>     <span style="color: #0000FF; ">return</span> fa[x];<br /><span style="color: #008080; ">29</span> }<br /><span style="color: #008080; ">30</span> <br /><span style="color: #008080; ">31</span> <span style="color: #0000FF; ">bool</span> un(<span style="color: #0000FF; ">int</span> a, <span style="color: #0000FF; ">int</span> b) {<br /><span style="color: #008080; ">32</span>     a = find(a), b = find(b);<br /><span style="color: #008080; ">33</span>     <span style="color: #0000FF; ">if</span>(a == b) <span style="color: #0000FF; ">return</span> <span style="color: #0000FF; ">false</span>;<br /><span style="color: #008080; ">34</span>     fa[a] = b;<br /><span style="color: #008080; ">35</span>     <span style="color: #0000FF; ">return</span> <span style="color: #0000FF; ">true</span>;<br /><span style="color: #008080; ">36</span> }<br /><span style="color: #008080; ">37</span> <br /><span style="color: #008080; ">38</span> <span style="color: #0000FF; ">int</span> main() {<br /><span style="color: #008080; ">39</span>     <span style="color: #0000FF; ">int</span> T, a, b;<br /><span style="color: #008080; ">40</span>     <span style="color: #0000FF; ">char</span> op[5];<br /><span style="color: #008080; ">41</span>     scanf("%d", &T);<br /><span style="color: #008080; ">42</span>     <span style="color: #0000FF; ">while</span>(T--) {<br /><span style="color: #008080; ">43</span>         init();<br /><span style="color: #008080; ">44</span>         scanf("%d%d", &n, &m);<br /><span style="color: #008080; ">45</span>         <span style="color: #0000FF; ">for</span>(<span style="color: #0000FF; ">int</span> i = 0; i < m; i++) {<br /><span style="color: #008080; ">46</span>             scanf("%s%d%d", op, &a, &b);<br /><span style="color: #008080; ">47</span>             <span style="color: #0000FF; ">if</span>(op[0] == 'A') {<br /><span style="color: #008080; ">48</span>                 <span style="color: #0000FF; ">if</span>(find(a) == find(b)) printf("In the same gang.\n");<br /><span style="color: #008080; ">49</span>                 <span style="color: #0000FF; ">else</span> <span style="color: #0000FF; ">if</span>(find(a) == find(b+n)) printf("In different gangs.\n");<br /><span style="color: #008080; ">50</span>                 <span style="color: #0000FF; ">else</span> printf("Not sure yet.\n");<br /><span style="color: #008080; ">51</span>             } <span style="color: #0000FF; ">else</span> {<br /><span style="color: #008080; ">52</span>                 un(a, b + n), un(a + n, b);<br /><span style="color: #008080; ">53</span>             }<br /><span style="color: #008080; ">54</span>         }<br /><span style="color: #008080; ">55</span>     }<br /><span style="color: #008080; ">56</span>     <span style="color: #0000FF; ">return</span> 0;<br /><span style="color: #008080; ">57</span> }<br /><span style="color: #008080; ">58</span> </div><img src ="http://www.shnenglu.com/y346491470/aggbug/167425.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.shnenglu.com/y346491470/" target="_blank">y @ The Angry Teletubbies</a> 2012-03-08 18:32 <a href="http://www.shnenglu.com/y346491470/articles/167425.html#Feedback" target="_blank" style="text-decoration:none;">鍙戣〃璇勮</a></div>]]></description></item><item><title>poj 1330 Nearest Common Ancestors - LCA + Tarjan綆楁硶http://www.shnenglu.com/y346491470/articles/164579.htmly @ The Angry Teletubbiesy @ The Angry TeletubbiesFri, 27 Jan 2012 08:35:00 GMThttp://www.shnenglu.com/y346491470/articles/164579.htmlhttp://www.shnenglu.com/y346491470/comments/164579.htmlhttp://www.shnenglu.com/y346491470/articles/164579.html#Feedback0http://www.shnenglu.com/y346491470/comments/commentRss/164579.htmlhttp://www.shnenglu.com/y346491470/services/trackbacks/164579.html
銆愰瑙c戯細妯℃澘棰樸?br />
銆愪唬鐮併戯細
 1 #include "iostream"
 2 #include "cstdio"
 3 #include "cstring"
 4 #include "algorithm"
 5 #include "vector"
 6 #include "queue"
 7 #include "cmath"
 8 #include "string"
 9 #include "cctype"
10 using namespace std;
11 #define pb push_back
12 #define lc(x) (x << 1)
13 #define rc(x) (x << 1 | 1)
14 #define lowbit(x) (x & (-x))
15 #define ll long long
16 #define maxn 10005
17 vector<int> tree[maxn], Q[maxn];
18 int in[maxn], n;
19 bool visit[maxn];
20 int fa[maxn];
21 
22 void init() {
23     for(int i = 0; i <= n; i++) fa[i] = i, tree[i].clear(), Q[i].clear();
24     memset(visit, falsesizeof(visit));
25     memset(in, 0, sizeof(in));
26 }
27 
28 int find(int x) {
29     if(x == fa[x]) return x;
30     else return fa[x] = find(fa[x]);
31 }
32 
33 bool un(int a, int b) {
34     a = find(a), b = find(b);
35     if(a == b) return false;
36     fa[b] = a;
37     return true;
38 }
39 
40 void Tarjan(int u) {
41     int size = tree[u].size();
42     for(int i = 0; i < size; i++) {
43         Tarjan(tree[u][i]);
44         un(u, tree[u][i]);
45     }
46     visit[u] = true, size = Q[u].size();
47     for(int i = 0; i < size; i++) {
48         if(visit[Q[u][i]]) {
49             printf("%d\n", find(Q[u][i]));
50             return;
51         }
52     }
53 }
54 
55 int main() {
56     int T, u, v;
57     scanf("%d", &T);
58     while(T--) {
59         scanf("%d", &n);
60         init();
61         for(int i = 0; i < n - 1; i++) {
62             scanf("%d%d", &u, &v);
63             tree[u].pb(v);
64             in[v]++;
65         }
66         scanf("%d%d", &u, &v);
67         Q[u].pb(v), Q[v].pb(u);
68         int root = -1;
69         for(int i = 1; i <= n; i++) {
70             if(in[i] == 0) {
71                 root = i;
72                 break;
73             }
74         }
75         Tarjan(root);
76     }
77     return 0;
78 }
79 


y @ The Angry Teletubbies 2012-01-27 16:35 鍙戣〃璇勮
]]>
hdoj 2795 Billboard - 綰挎鏍?/title><link>http://www.shnenglu.com/y346491470/articles/164441.html</link><dc:creator>y @ The Angry Teletubbies</dc:creator><author>y @ The Angry Teletubbies</author><pubDate>Sat, 21 Jan 2012 14:28:00 GMT</pubDate><guid>http://www.shnenglu.com/y346491470/articles/164441.html</guid><wfw:comment>http://www.shnenglu.com/y346491470/comments/164441.html</wfw:comment><comments>http://www.shnenglu.com/y346491470/articles/164441.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.shnenglu.com/y346491470/comments/commentRss/164441.html</wfw:commentRss><trackback:ping>http://www.shnenglu.com/y346491470/services/trackbacks/164441.html</trackback:ping><description><![CDATA[銆愰鎰忋戯細鏈変竴鍧楅潰縐負h*w鐨勯氱煡鏍忥紝寰涓婇潰璐翠竴浜?*wi鐨勯氱煡涓婂幓錛岃創鐨勪綅緗繪槸閫夋嫨鍙互璐寸殑鏈楂樹綅緗殑鏈宸︾錛屼笖閫氱煡涓嶈兘閲嶅彔銆傜粰鍑簄涓氱煡錛屽茍璇㈤棶瀹冧滑鍒嗗埆璐村湪絎嚑琛屻?br /><br />銆愰瑙c戯細綰挎鏍戯紝緇存姢綰挎鏍戠殑鍖洪棿涓篬1, min(h,n)]錛屽洜涓烘渶鍧忔儏鍐典篃灝變竴琛岃創涓涓紝鎵浠ュ悗闈㈢殑鏄浣欑殑銆?br />               鍥犱負鏌ヨ鍜屾洿鏂版槸鍚屾椂鐨勶紝鎵浠ユ垜鍐欏湪涓璧蜂簡銆?br /><br />銆愪唬鐮併戯細<br /><div style="background-color:#eeeeee;font-size:13px;border:1px solid #CCCCCC;padding-right: 5px;padding-bottom: 4px;padding-left: 4px;padding-top: 4px;width: 98%;word-break:break-all"><!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />--><span style="color: #008080; "> 1</span> #include "iostream"<br /><span style="color: #008080; "> 2</span> #include "cstdio"<br /><span style="color: #008080; "> 3</span> #include "cstring"<br /><span style="color: #008080; "> 4</span> #include "algorithm"<br /><span style="color: #008080; "> 5</span> #include "vector"<br /><span style="color: #008080; "> 6</span> #include "queue"<br /><span style="color: #008080; "> 7</span> #include "cmath"<br /><span style="color: #008080; "> 8</span> #include "string"<br /><span style="color: #008080; "> 9</span> #include "cctype"<br /><span style="color: #008080; ">10</span> <span style="color: #0000FF; ">using</span> <span style="color: #0000FF; ">namespace</span> std;<br /><span style="color: #008080; ">11</span> <span style="color: #0000FF; ">#define</span> pb push_back<br /><span style="color: #008080; ">12</span> <span style="color: #0000FF; ">#define</span> lc(x) (x << 1)<br /><span style="color: #008080; ">13</span> <span style="color: #0000FF; ">#define</span> rc(x) (x << 1 | 1)<br /><span style="color: #008080; ">14</span> <span style="color: #0000FF; ">#define</span> lowbit(x) (x & (-x))<br /><span style="color: #008080; ">15</span> <span style="color: #0000FF; ">#define</span> ll long long<br /><span style="color: #008080; ">16</span> <span style="color: #0000FF; ">#define</span> MAX 200050<br /><span style="color: #008080; ">17</span> <span style="color: #0000FF; ">int</span> sum[MAX<<2];<br /><span style="color: #008080; ">18</span> <span style="color: #0000FF; ">int</span> h, w, n;<br /><span style="color: #008080; ">19</span> <br /><span style="color: #008080; ">20</span> <span style="color: #0000FF; ">void</span> pushup(<span style="color: #0000FF; ">int</span> p) {<br /><span style="color: #008080; ">21</span>     sum[p] = max(sum[lc(p)], sum[rc(p)]);<br /><span style="color: #008080; ">22</span> }<br /><span style="color: #008080; ">23</span> <br /><span style="color: #008080; ">24</span> <span style="color: #0000FF; ">void</span> build(<span style="color: #0000FF; ">int</span> l, <span style="color: #0000FF; ">int</span> r, <span style="color: #0000FF; ">int</span> p) {<br /><span style="color: #008080; ">25</span>     sum[p] = w;<br /><span style="color: #008080; ">26</span>     <span style="color: #0000FF; ">if</span>(l == r) <span style="color: #0000FF; ">return</span>;<br /><span style="color: #008080; ">27</span>     <span style="color: #0000FF; ">int</span> mid = (l + r) >> 1;<br /><span style="color: #008080; ">28</span>     build(l, mid, lc(p));<br /><span style="color: #008080; ">29</span>     build(mid + 1, r, rc(p));<br /><span style="color: #008080; ">30</span> }<br /><span style="color: #008080; ">31</span> <br /><span style="color: #008080; ">32</span> <span style="color: #0000FF; ">int</span> query(<span style="color: #0000FF; ">int</span> L, <span style="color: #0000FF; ">int</span> l, <span style="color: #0000FF; ">int</span> r, <span style="color: #0000FF; ">int</span> p) {<br /><span style="color: #008080; ">33</span>     <span style="color: #0000FF; ">if</span>(l == r) {<br /><span style="color: #008080; ">34</span>         sum[p] -= L; <span style="color: #008000; ">//</span><span style="color: #008000; "> 鎵懼埌鏈浼樹綅緗茍鏇存柊</span><span style="color: #008000; "><br /></span><span style="color: #008080; ">35</span> <span style="color: #008000; "></span>        <span style="color: #0000FF; ">return</span> l;<br /><span style="color: #008080; ">36</span>     }<br /><span style="color: #008080; ">37</span>     <span style="color: #0000FF; ">int</span> mid = (l + r) >> 1, ans = -1;<br /><span style="color: #008080; ">38</span>     <span style="color: #0000FF; ">if</span>(L <= sum[lc(p)]) ans = query(L, l, mid, lc(p));<br /><span style="color: #008080; ">39</span>     <span style="color: #0000FF; ">else</span> ans = query(L, mid + 1, r, rc(p));<br /><span style="color: #008080; ">40</span>     pushup(p);<br /><span style="color: #008080; ">41</span>     <span style="color: #0000FF; ">return</span> ans;<br /><span style="color: #008080; ">42</span> }<br /><span style="color: #008080; ">43</span> <br /><span style="color: #008080; ">44</span> <span style="color: #0000FF; ">int</span> main() {<br /><span style="color: #008080; ">45</span>     <span style="color: #0000FF; ">int</span> L;<br /><span style="color: #008080; ">46</span>     <span style="color: #0000FF; ">while</span>(~scanf("%d%d%d", &h, &w, &n)) {<br /><span style="color: #008080; ">47</span>         <span style="color: #0000FF; ">if</span>(h > n) h = n;<br /><span style="color: #008080; ">48</span>         build(1, h, 1);<br /><span style="color: #008080; ">49</span>         <span style="color: #0000FF; ">for</span>(<span style="color: #0000FF; ">int</span> i = 0; i < n; i++) {<br /><span style="color: #008080; ">50</span>             scanf("%d", &L);<br /><span style="color: #008080; ">51</span>             <span style="color: #0000FF; ">if</span>(sum[1] < L) printf("-1\n");<br /><span style="color: #008080; ">52</span>             <span style="color: #0000FF; ">else</span> printf("%d\n", query(L, 1, h, 1));<br /><span style="color: #008080; ">53</span>         }<br /><span style="color: #008080; ">54</span>     }<br /><span style="color: #008080; ">55</span>     <span style="color: #0000FF; ">return</span> 0;<br /><span style="color: #008080; ">56</span> }<br /><span style="color: #008080; ">57</span> </div><img src ="http://www.shnenglu.com/y346491470/aggbug/164441.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.shnenglu.com/y346491470/" target="_blank">y @ The Angry Teletubbies</a> 2012-01-21 22:28 <a href="http://www.shnenglu.com/y346491470/articles/164441.html#Feedback" target="_blank" style="text-decoration:none;">鍙戣〃璇勮</a></div>]]></description></item><item><title>hdoj 1394 Minimum Inversion Number - 鏍戠姸鏁扮粍姹傞嗗簭瀵?/title><link>http://www.shnenglu.com/y346491470/articles/164212.html</link><dc:creator>y @ The Angry Teletubbies</dc:creator><author>y @ The Angry Teletubbies</author><pubDate>Sun, 15 Jan 2012 06:44:00 GMT</pubDate><guid>http://www.shnenglu.com/y346491470/articles/164212.html</guid><wfw:comment>http://www.shnenglu.com/y346491470/comments/164212.html</wfw:comment><comments>http://www.shnenglu.com/y346491470/articles/164212.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.shnenglu.com/y346491470/comments/commentRss/164212.html</wfw:commentRss><trackback:ping>http://www.shnenglu.com/y346491470/services/trackbacks/164212.html</trackback:ping><description><![CDATA[銆愰鎰忋戯細緇欏嚭n涓暟緇勬垚鐨勪竴涓簭鍒楋紝鎴戜滑鍙互鎶婂墠m涓暟縐誨埌搴忓垪鐨勫悗闈紝榪欐牱鎴戜滑涓鍏卞彲浠ュ緱鍒皀涓笉鍚岀殑搴忓垪銆傛眰榪檔涓簭鍒椾腑錛岄嗗簭瀵規渶灝忎負澶氬皯銆?br /><br />銆愰瑙c戯細鍙互鍒╃敤鏍戠姸鏁扮粍鎴栬呯嚎孌墊爲鍦∣(nlogn)鏃墮棿閲屾眰鍑哄垵濮嬪簭鍒楃殑閫嗗簭瀵癸紝鐒跺悗姣忔鐢∣(1)鐨勬椂闂存帹鍑烘瘡縐誨姩涓涓暟鍒板簭鍒楀悗闈箣鍚庣殑閫嗗簭瀵廣?br />               鎬誨鏉傚害O(nlogn + n)銆?br /><br />銆愪唬鐮併戯細<br /><div style="background-color:#eeeeee;font-size:13px;border:1px solid #CCCCCC;padding-right: 5px;padding-bottom: 4px;padding-left: 4px;padding-top: 4px;width: 98%;word-break:break-all"><!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />--><span style="color: #008080; "> 1</span> #include "iostream"<br /><span style="color: #008080; "> 2</span> #include "cstdio"<br /><span style="color: #008080; "> 3</span> #include "cstring"<br /><span style="color: #008080; "> 4</span> #include "algorithm"<br /><span style="color: #008080; "> 5</span> #include "vector"<br /><span style="color: #008080; "> 6</span> #include "queue"<br /><span style="color: #008080; "> 7</span> #include "cmath"<br /><span style="color: #008080; "> 8</span> #include "string"<br /><span style="color: #008080; "> 9</span> <span style="color: #0000FF; ">using</span> <span style="color: #0000FF; ">namespace</span> std;<br /><span style="color: #008080; ">10</span> <span style="color: #0000FF; ">#define</span> pb push_back<br /><span style="color: #008080; ">11</span> <span style="color: #0000FF; ">#define</span> lc(x) (x << 1)<br /><span style="color: #008080; ">12</span> <span style="color: #0000FF; ">#define</span> rc(x) (x << 1 | 1)<br /><span style="color: #008080; ">13</span> <span style="color: #0000FF; ">#define</span> lowbit(x) (x & (-x))<br /><span style="color: #008080; ">14</span> <span style="color: #0000FF; ">#define</span> ll long long<br /><span style="color: #008080; ">15</span> <span style="color: #0000FF; ">#define</span> maxn 5005<br /><span style="color: #008080; ">16</span> <span style="color: #0000FF; ">const</span> <span style="color: #0000FF; ">int</span> inf = 1 << 30;<br /><span style="color: #008080; ">17</span> <span style="color: #0000FF; ">int</span> sum[maxn], n, val[maxn];<br /><span style="color: #008080; ">18</span> <br /><span style="color: #008080; ">19</span> <span style="color: #0000FF; ">void</span> update(<span style="color: #0000FF; ">int</span> x) {<br /><span style="color: #008080; ">20</span>     <span style="color: #0000FF; ">for</span>(<span style="color: #0000FF; ">int</span> i = x; i < maxn; i += lowbit(i))<br /><span style="color: #008080; ">21</span>         sum[i]++;<br /><span style="color: #008080; ">22</span> }<br /><span style="color: #008080; ">23</span> <br /><span style="color: #008080; ">24</span> <span style="color: #0000FF; ">int</span> SUM(<span style="color: #0000FF; ">int</span> x) {<br /><span style="color: #008080; ">25</span>     <span style="color: #0000FF; ">int</span> res = 0;<br /><span style="color: #008080; ">26</span>     <span style="color: #0000FF; ">for</span>(<span style="color: #0000FF; ">int</span> i = x; i; i -= lowbit(i))<br /><span style="color: #008080; ">27</span>         res += sum[i];<br /><span style="color: #008080; ">28</span>     <span style="color: #0000FF; ">return</span> res;<br /><span style="color: #008080; ">29</span> }<br /><span style="color: #008080; ">30</span> <br /><span style="color: #008080; ">31</span> <span style="color: #0000FF; ">int</span> main() {<br /><span style="color: #008080; ">32</span>     <span style="color: #0000FF; ">while</span>(~scanf("%d", &n)) {<br /><span style="color: #008080; ">33</span>         memset(sum, 0, <span style="color: #0000FF; ">sizeof</span>(sum)); <br /><span style="color: #008080; ">34</span>         <span style="color: #0000FF; ">int</span> ans = inf, tmp = 0;<br /><span style="color: #008080; ">35</span>         <span style="color: #0000FF; ">for</span>(<span style="color: #0000FF; ">int</span> i = 0; i < n; i++) {<br /><span style="color: #008080; ">36</span>             scanf("%d", &val[i]);<br /><span style="color: #008080; ">37</span>             tmp += SUM(n) - SUM(val[i]);<br /><span style="color: #008080; ">38</span>             update(val[i]+1);<br /><span style="color: #008080; ">39</span>         }<br /><span style="color: #008080; ">40</span>         <span style="color: #0000FF; ">for</span>(<span style="color: #0000FF; ">int</span> i = 0; i < n - 1; i++) {<br /><span style="color: #008080; ">41</span>             tmp += n - 2 * val[i] - 1;<br /><span style="color: #008080; ">42</span>             ans = min(ans, tmp);<br /><span style="color: #008080; ">43</span>         }<br /><span style="color: #008080; ">44</span>         cout << ans << endl;<br /><span style="color: #008080; ">45</span>     }<br /><span style="color: #008080; ">46</span>     <span style="color: #0000FF; ">return</span> 0;<br /><span style="color: #008080; ">47</span> }<br /><span style="color: #008080; ">48</span> </div><img src ="http://www.shnenglu.com/y346491470/aggbug/164212.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.shnenglu.com/y346491470/" target="_blank">y @ The Angry Teletubbies</a> 2012-01-15 14:44 <a href="http://www.shnenglu.com/y346491470/articles/164212.html#Feedback" target="_blank" style="text-decoration:none;">鍙戣〃璇勮</a></div>]]></description></item><item><title>poj 3468 A Simple Problem with Integers - 綰挎鏍?/title><link>http://www.shnenglu.com/y346491470/articles/163996.html</link><dc:creator>y @ The Angry Teletubbies</dc:creator><author>y @ The Angry Teletubbies</author><pubDate>Wed, 11 Jan 2012 07:39:00 GMT</pubDate><guid>http://www.shnenglu.com/y346491470/articles/163996.html</guid><wfw:comment>http://www.shnenglu.com/y346491470/comments/163996.html</wfw:comment><comments>http://www.shnenglu.com/y346491470/articles/163996.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.shnenglu.com/y346491470/comments/commentRss/163996.html</wfw:commentRss><trackback:ping>http://www.shnenglu.com/y346491470/services/trackbacks/163996.html</trackback:ping><description><![CDATA[銆愰鎰忋戯細緇欏嚭n(n<=100000)涓暟鐨勫垵濮嬪鹼紝緙栧彿1~n錛屽啀緇欏嚭q(q<=100000)涓搷浣滐紝涓嶅畾鏃跺線絎琲涓暟鍒扮j涓暟涓婂姞涓婁竴涓父鏁癱鎴栬呮煡璇㈢i涓暟鍒扮j涓暟鐨勫拰銆?br /><br />銆愰瑙c戯細榪樻槸綰挎鏍戠殑鍏ラ棬棰樼洰錛屽嚟鑷繁鐨勭悊瑙h8鎵撲簡涓嬈$嚎孌墊爲錛屽寤惰繜鏍囪鐞嗚В寰楁洿閫忓垏浜嗐?br />               娉ㄦ剰瑕佺敤long long.<br /><br />銆愪唬鐮併戯細<br /><div style="font-size: 13px; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-color: #cccccc; border-right-color: #cccccc; border-bottom-color: #cccccc; border-left-color: #cccccc; border-image: initial; padding-right: 5px; padding-bottom: 4px; padding-left: 4px; padding-top: 4px; width: 98%; word-break: break-all; background-color: #eeeeee; "><!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />--><span style="color: #008080; "> 1</span> #include "iostream"<br /><span style="color: #008080; "> 2</span> #include "cstdio"<br /><span style="color: #008080; "> 3</span> #include "cstring"<br /><span style="color: #008080; "> 4</span> #include "algorithm"<br /><span style="color: #008080; "> 5</span> #include "vector"<br /><span style="color: #008080; "> 6</span> #include "queue"<br /><span style="color: #008080; "> 7</span> <span style="color: #0000FF; ">using</span> <span style="color: #0000FF; ">namespace</span> std;<br /><span style="color: #008080; "> 8</span> <span style="color: #0000FF; ">#define</span> pb push_back<br /><span style="color: #008080; "> 9</span> <span style="color: #0000FF; ">#define</span> lc(x) (x << 1)<br /><span style="color: #008080; ">10</span> <span style="color: #0000FF; ">#define</span> rc(x) (x << 1 | 1)<br /><span style="color: #008080; ">11</span> <span style="color: #0000FF; ">#define</span> lowbit(x) (x & (-x))<br /><span style="color: #008080; ">12</span> <span style="color: #0000FF; ">#define</span> MAX 100050<br /><span style="color: #008080; ">13</span> <span style="color: #0000FF; ">#define</span> ll long long<br /><span style="color: #008080; ">14</span> ll lazy[MAX<<2], sum[MAX<<2];<br /><span style="color: #008080; ">15</span> <span style="color: #0000FF; ">int</span> n, q;<br /><span style="color: #008080; ">16</span> <br /><span style="color: #008080; ">17</span> <span style="color: #0000FF; ">void</span> pushup(<span style="color: #0000FF; ">int</span> p) {<br /><span style="color: #008080; ">18</span>     sum[p] = sum[lc(p)] + sum[rc(p)];<br /><span style="color: #008080; ">19</span> }<br /><span style="color: #008080; ">20</span> <br /><span style="color: #008080; ">21</span> <span style="color: #0000FF; ">void</span> pushdown(<span style="color: #0000FF; ">int</span> p, <span style="color: #0000FF; ">int</span> len) {<br /><span style="color: #008080; ">22</span>     <span style="color: #0000FF; ">if</span>(lazy[p]) {<br /><span style="color: #008080; ">23</span>         lazy[lc(p)] += lazy[p];<br /><span style="color: #008080; ">24</span>         lazy[rc(p)] += lazy[p];<br /><span style="color: #008080; ">25</span>         sum[lc(p)] += (len - (len >> 1)) * lazy[p];<br /><span style="color: #008080; ">26</span>         sum[rc(p)] += (len >> 1) * lazy[p];<br /><span style="color: #008080; ">27</span>         lazy[p] = 0;<br /><span style="color: #008080; ">28</span>     }<br /><span style="color: #008080; ">29</span> }<br /><span style="color: #008080; ">30</span> <br /><span style="color: #008080; ">31</span> <span style="color: #0000FF; ">void</span> build(<span style="color: #0000FF; ">int</span> l, <span style="color: #0000FF; ">int</span> r, <span style="color: #0000FF; ">int</span> p) {<br /><span style="color: #008080; ">32</span>     lazy[p] = 0;<br /><span style="color: #008080; ">33</span>     <span style="color: #0000FF; ">if</span>(l == r) {<br /><span style="color: #008080; ">34</span>         scanf("%lld", &sum[p]);<br /><span style="color: #008080; ">35</span>         <span style="color: #0000FF; ">return</span>;<br /><span style="color: #008080; ">36</span>     }<br /><span style="color: #008080; ">37</span>     <span style="color: #0000FF; ">int</span> mid = (l + r) >> 1;<br /><span style="color: #008080; ">38</span>     build(l, mid, lc(p));<br /><span style="color: #008080; ">39</span>     build(mid + 1, r, rc(p));<br /><span style="color: #008080; ">40</span>     pushup(p);<br /><span style="color: #008080; ">41</span> }<br /><span style="color: #008080; ">42</span> <br /><span style="color: #008080; ">43</span> <span style="color: #0000FF; ">void</span> update(<span style="color: #0000FF; ">int</span> L, <span style="color: #0000FF; ">int</span> R, ll c, <span style="color: #0000FF; ">int</span> l, <span style="color: #0000FF; ">int</span> r, <span style="color: #0000FF; ">int</span> p) {<br /><span style="color: #008080; ">44</span>     <span style="color: #0000FF; ">if</span>(L <= l && r <= R) {<br /><span style="color: #008080; ">45</span>         lazy[p] += c;<br /><span style="color: #008080; ">46</span>         sum[p] += c * (r - l + 1);<br /><span style="color: #008080; ">47</span>         <span style="color: #0000FF; ">return</span>;<br /><span style="color: #008080; ">48</span>     }<br /><span style="color: #008080; ">49</span>     pushdown(p, r - l + 1);<br /><span style="color: #008080; ">50</span>     <span style="color: #0000FF; ">int</span> mid = (l + r) >> 1;<br /><span style="color: #008080; ">51</span>     <span style="color: #0000FF; ">if</span>(L <= mid) update(L, R, c, l, mid, lc(p));<br /><span style="color: #008080; ">52</span>     <span style="color: #0000FF; ">if</span>(R > mid) update(L, R, c, mid + 1, r, rc(p));<br /><span style="color: #008080; ">53</span>     pushup(p);<br /><span style="color: #008080; ">54</span> }<br /><span style="color: #008080; ">55</span> <br /><span style="color: #008080; ">56</span> ll query(<span style="color: #0000FF; ">int</span> L, <span style="color: #0000FF; ">int</span> R, <span style="color: #0000FF; ">int</span> l, <span style="color: #0000FF; ">int</span> r, <span style="color: #0000FF; ">int</span> p) {<br /><span style="color: #008080; ">57</span>     ll res = 0;<br /><span style="color: #008080; ">58</span>     <span style="color: #0000FF; ">if</span>(L <= l && r <= R) {<br /><span style="color: #008080; ">59</span>         <span style="color: #0000FF; ">return</span> sum[p];<br /><span style="color: #008080; ">60</span>     }<br /><span style="color: #008080; ">61</span>     pushdown(p, r - l + 1);<br /><span style="color: #008080; ">62</span>     <span style="color: #0000FF; ">int</span> mid = (l + r) >> 1;<br /><span style="color: #008080; ">63</span>     <span style="color: #0000FF; ">if</span>(L <= mid) res += query(L, R, l, mid, lc(p));<br /><span style="color: #008080; ">64</span>     <span style="color: #0000FF; ">if</span>(R > mid) res += query(L, R, mid + 1, r, rc(p));<br /><span style="color: #008080; ">65</span>     pushup(p);<br /><span style="color: #008080; ">66</span>     <span style="color: #0000FF; ">return</span> res; <br /><span style="color: #008080; ">67</span> }<br /><span style="color: #008080; ">68</span> <br /><span style="color: #008080; ">69</span> <span style="color: #0000FF; ">int</span> main() {<br /><span style="color: #008080; ">70</span>     <span style="color: #0000FF; ">char</span> str[5];<br /><span style="color: #008080; ">71</span>     <span style="color: #0000FF; ">int</span> a, b;<br /><span style="color: #008080; ">72</span>     ll c;<br /><span style="color: #008080; ">73</span>     <span style="color: #0000FF; ">while</span>(~scanf("%d%d", &n, &q)) {<br /><span style="color: #008080; ">74</span>         build(1, n, 1);<br /><span style="color: #008080; ">75</span>         <span style="color: #0000FF; ">while</span>(q--) {<br /><span style="color: #008080; ">76</span>             scanf("%s%d%d", str, &a, &b);<br /><span style="color: #008080; ">77</span>             <span style="color: #0000FF; ">if</span>(str[0] == 'Q') printf("%lld\n", query(a, b, 1, n, 1));<br /><span style="color: #008080; ">78</span>             <span style="color: #0000FF; ">else</span> {<br /><span style="color: #008080; ">79</span>                 scanf("%lld", &c);<br /><span style="color: #008080; ">80</span>                 update(a, b, c, 1, n, 1);<br /><span style="color: #008080; ">81</span>             }<br /><span style="color: #008080; ">82</span>         }<br /><span style="color: #008080; ">83</span>     }<br /><span style="color: #008080; ">84</span>     <span style="color: #0000FF; ">return</span> 0;<br /><span style="color: #008080; ">85</span> }<font color="#008080"><br /></font></div><img src ="http://www.shnenglu.com/y346491470/aggbug/163996.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.shnenglu.com/y346491470/" target="_blank">y @ The Angry Teletubbies</a> 2012-01-11 15:39 <a href="http://www.shnenglu.com/y346491470/articles/163996.html#Feedback" target="_blank" style="text-decoration:none;">鍙戣〃璇勮</a></div>]]></description></item><item><title>hdoj 1698 Just a Hook - 綰挎鏍?/title><link>http://www.shnenglu.com/y346491470/articles/163994.html</link><dc:creator>y @ The Angry Teletubbies</dc:creator><author>y @ The Angry Teletubbies</author><pubDate>Wed, 11 Jan 2012 07:12:00 GMT</pubDate><guid>http://www.shnenglu.com/y346491470/articles/163994.html</guid><wfw:comment>http://www.shnenglu.com/y346491470/comments/163994.html</wfw:comment><comments>http://www.shnenglu.com/y346491470/articles/163994.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.shnenglu.com/y346491470/comments/commentRss/163994.html</wfw:commentRss><trackback:ping>http://www.shnenglu.com/y346491470/services/trackbacks/163994.html</trackback:ping><description><![CDATA[銆愰鎰忋戯細鎬繪墍鍛ㄧ煡錛孌ota閲岄潰鏈変釜灞犲か錛屼粬鏈変釜鍚婇挬銆傜幇鍦ㄨ冭檻浠栫殑鍚婇挬鐢眓(n<=100000)孌靛皬媯掔粍鎴愶紝鍒濆鏃訛紝閮芥槸閾滄銆傜粰鍑簈(q<=100000)涓搷浣滐紝姣忎釜鎿嶄綔閮藉彲浠ユ妸絎琲孌靛埌絎琷孌電殑灝忔鏇挎崲鎴愬叾浠栫被鍨嬬殑媯掞紙閾滄錛岄摱媯掞紝閲戞錛屼環鍊煎垎鍒負1,2,3錛夈傞棶錛岀粡榪噏涓搷浣滀箣鍚庯紝榪欎釜鍚婇挬鐨勬諱環鍊間負澶氬皯銆?br /><br />銆愰瑙c戯細綰挎鏍戯紝鍖洪棿鏇挎崲錛屽尯闂存煡璇€?br />               鍒濆綰挎鏍戯紝鐞嗚В寤惰繜鏍囪鏄叧閿?br />               鏈姣旇緝鐗規畩錛屾煡璇㈠彧鏈変竴嬈★紝鑰屼笖鏄煡璇㈡暣涓尯闂達紝杈撳嚭stick[1]鍗沖彲銆?br /><br />銆愪唬鐮併戯細<br /><div style="background-color:#eeeeee;font-size:13px;border:1px solid #CCCCCC;padding-right: 5px;padding-bottom: 4px;padding-left: 4px;padding-top: 4px;width: 98%;word-break:break-all"><!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />--><span style="color: #008080; "> 1</span> #include "iostream"<br /><span style="color: #008080; "> 2</span> #include "cstdio"<br /><span style="color: #008080; "> 3</span> #include "cstring"<br /><span style="color: #008080; "> 4</span> #include "algorithm"<br /><span style="color: #008080; "> 5</span> #include "vector"<br /><span style="color: #008080; "> 6</span> #include "queue"<br /><span style="color: #008080; "> 7</span> <span style="color: #0000FF; ">using</span> <span style="color: #0000FF; ">namespace</span> std;<br /><span style="color: #008080; "> 8</span> <span style="color: #0000FF; ">#define</span> pb push_back<br /><span style="color: #008080; "> 9</span> <span style="color: #0000FF; ">#define</span> lc(x) (x << 1)<br /><span style="color: #008080; ">10</span> <span style="color: #0000FF; ">#define</span> rc(x) (x << 1 | 1)<br /><span style="color: #008080; ">11</span> <span style="color: #0000FF; ">#define</span> MAX 100005<br /><span style="color: #008080; ">12</span> <span style="color: #0000FF; ">int</span> stick[MAX<<2], n, m;<br /><span style="color: #008080; ">13</span> <span style="color: #0000FF; ">int</span> lazy[MAX<<2];<br /><span style="color: #008080; ">14</span> <br /><span style="color: #008080; ">15</span> <span style="color: #0000FF; ">void</span> pushup(<span style="color: #0000FF; ">int</span> p) {<br /><span style="color: #008080; ">16</span>     stick[p] = stick[lc(p)] + stick[rc(p)];<br /><span style="color: #008080; ">17</span> }<br /><span style="color: #008080; ">18</span> <br /><span style="color: #008080; ">19</span> <span style="color: #0000FF; ">void</span> pushdown(<span style="color: #0000FF; ">int</span> p, <span style="color: #0000FF; ">int</span> len) {<br /><span style="color: #008080; ">20</span>     <span style="color: #0000FF; ">if</span>(lazy[p]) {<br /><span style="color: #008080; ">21</span>         lazy[lc(p)] = lazy[rc(p)] = lazy[p];<br /><span style="color: #008080; ">22</span>         stick[lc(p)] = (len - (len >> 1)) * lazy[p];<br /><span style="color: #008080; ">23</span>         stick[rc(p)] = (len >> 1) * lazy[p];<br /><span style="color: #008080; ">24</span>         lazy[p] = 0;<br /><span style="color: #008080; ">25</span>     }<br /><span style="color: #008080; ">26</span> }<br /><span style="color: #008080; ">27</span> <br /><span style="color: #008080; ">28</span> <span style="color: #0000FF; ">void</span> build(<span style="color: #0000FF; ">int</span> l, <span style="color: #0000FF; ">int</span> r, <span style="color: #0000FF; ">int</span> p) {<br /><span style="color: #008080; ">29</span>     lazy[p] = 0;<br /><span style="color: #008080; ">30</span>     <span style="color: #0000FF; ">if</span>(l == r) {<br /><span style="color: #008080; ">31</span>         stick[p] = 1;<br /><span style="color: #008080; ">32</span>         <span style="color: #0000FF; ">return</span>;<br /><span style="color: #008080; ">33</span>     }<br /><span style="color: #008080; ">34</span>     <span style="color: #0000FF; ">int</span> mid = (l + r) >> 1;<br /><span style="color: #008080; ">35</span>     build(l, mid, lc(p));<br /><span style="color: #008080; ">36</span>     build(mid + 1, r, rc(p));<br /><span style="color: #008080; ">37</span>     pushup(p);<br /><span style="color: #008080; ">38</span> }<br /><span style="color: #008080; ">39</span> <br /><span style="color: #008080; ">40</span> <span style="color: #0000FF; ">void</span> update(<span style="color: #0000FF; ">int</span> L, <span style="color: #0000FF; ">int</span> R, <span style="color: #0000FF; ">int</span> c, <span style="color: #0000FF; ">int</span> l, <span style="color: #0000FF; ">int</span> r, <span style="color: #0000FF; ">int</span> p) {<br /><span style="color: #008080; ">41</span>     <span style="color: #0000FF; ">if</span>(L <= l && r <= R) {<br /><span style="color: #008080; ">42</span>         lazy[p] = c;<br /><span style="color: #008080; ">43</span>         stick[p] = c * (r - l + 1);<br /><span style="color: #008080; ">44</span>         <span style="color: #0000FF; ">return</span>;<br /><span style="color: #008080; ">45</span>     }<br /><span style="color: #008080; ">46</span>     pushdown(p, r - l + 1);<br /><span style="color: #008080; ">47</span>     <span style="color: #0000FF; ">int</span> mid = (l + r) >> 1;<br /><span style="color: #008080; ">48</span>     <span style="color: #0000FF; ">if</span>(L <= mid) update(L, R, c, l, mid, lc(p));<br /><span style="color: #008080; ">49</span>     <span style="color: #0000FF; ">if</span>(R > mid) update(L, R, c, mid + 1, r, rc(p));<br /><span style="color: #008080; ">50</span>     pushup(p);<br /><span style="color: #008080; ">51</span> }<br /><span style="color: #008080; ">52</span> <br /><span style="color: #008080; ">53</span> <span style="color: #0000FF; ">int</span> main() {<br /><span style="color: #008080; ">54</span>     <span style="color: #0000FF; ">int</span> T, Case = 1;<br /><span style="color: #008080; ">55</span>     <span style="color: #0000FF; ">int</span> x, y, z;<br /><span style="color: #008080; ">56</span>     scanf("%d", &T);<br /><span style="color: #008080; ">57</span>     <span style="color: #0000FF; ">while</span>(T--) {<br /><span style="color: #008080; ">58</span>         scanf("%d%d", &n, &m);<br /><span style="color: #008080; ">59</span>         build(1, n, 1);<br /><span style="color: #008080; ">60</span>         <span style="color: #0000FF; ">while</span>(m--) {<br /><span style="color: #008080; ">61</span>             scanf("%d%d%d", &x, &y, &z);<br /><span style="color: #008080; ">62</span>             update(x, y, z, 1, n, 1);<br /><span style="color: #008080; ">63</span>         }<br /><span style="color: #008080; ">64</span>         printf("Case %d: The total value of the hook is %d.\n", Case++, stick[1]);<br /><span style="color: #008080; ">65</span>     }<br /><span style="color: #008080; ">66</span>     <span style="color: #0000FF; ">return</span> 0;<br /><span style="color: #008080; ">67</span> }<br /><span style="color: #008080; ">68</span> </div><img src ="http://www.shnenglu.com/y346491470/aggbug/163994.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.shnenglu.com/y346491470/" target="_blank">y @ The Angry Teletubbies</a> 2012-01-11 15:12 <a href="http://www.shnenglu.com/y346491470/articles/163994.html#Feedback" target="_blank" style="text-decoration:none;">鍙戣〃璇勮</a></div>]]></description></item><item><title>hdoj 1754 I Hate It - 綰挎鏍?/title><link>http://www.shnenglu.com/y346491470/articles/163936.html</link><dc:creator>y @ The Angry Teletubbies</dc:creator><author>y @ The Angry Teletubbies</author><pubDate>Tue, 10 Jan 2012 07:00:00 GMT</pubDate><guid>http://www.shnenglu.com/y346491470/articles/163936.html</guid><wfw:comment>http://www.shnenglu.com/y346491470/comments/163936.html</wfw:comment><comments>http://www.shnenglu.com/y346491470/articles/163936.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.shnenglu.com/y346491470/comments/commentRss/163936.html</wfw:commentRss><trackback:ping>http://www.shnenglu.com/y346491470/services/trackbacks/163936.html</trackback:ping><description><![CDATA[銆愰鎰忋戯細緇欏嚭n涓鐢熺殑鍒濆鎴愮嘩錛岀紪鍙?~n錛屼笉瀹氭椂鐨勪慨鏀規煇涓鐢熺殑鎴愮嘩鍜屾煡璇㈡煇涓孌佃繛緇紪鍙鋒垚緇╃殑鏈楂樺箋?n<=200000)<br /><br />銆愰瑙c戯細鏁版嵁緇撴瀯棰樼洰錛岀嚎孌墊爲縐掍簡錛屼笉鐭ラ亾鏍戠姸鏁扮粍琛屼笉琛屻?br /><br />銆愪唬鐮併戯細<br /><div style="font-size: 13px; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-color: #cccccc; border-right-color: #cccccc; border-bottom-color: #cccccc; border-left-color: #cccccc; border-image: initial; padding-right: 5px; padding-bottom: 4px; padding-left: 4px; padding-top: 4px; width: 98%; word-break: break-all; background-color: #eeeeee; "><!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />--><span style="color: #008080; "> 1</span> #include "iostream"<br /><span style="color: #008080; "> 2</span> #include "cstdio"<br /><span style="color: #008080; "> 3</span> #include "cstring"<br /><span style="color: #008080; "> 4</span> #include "algorithm"<br /><span style="color: #008080; "> 5</span> #include "vector"<br /><span style="color: #008080; "> 6</span> #include "queue"<br /><span style="color: #008080; "> 7</span> <span style="color: #0000FF; ">using</span> <span style="color: #0000FF; ">namespace</span> std;<br /><span style="color: #008080; "> 8</span> <span style="color: #0000FF; ">#define</span> pb push_back<br /><span style="color: #008080; "> 9</span> <span style="color: #0000FF; ">#define</span> MAX 200050<br /><span style="color: #008080; ">10</span> <span style="color: #0000FF; ">#define</span> lc(x) (x << 1)<br /><span style="color: #008080; ">11</span> <span style="color: #0000FF; ">#define</span> rc(x) (x << 1 | 1)<br /><span style="color: #008080; ">12</span> <span style="color: #0000FF; ">const</span> <span style="color: #0000FF; ">int</span> inf = 1 << 30;<br /><span style="color: #008080; ">13</span> <span style="color: #0000FF; ">int</span> grade[MAX<<2], n, m;<br /><span style="color: #008080; ">14</span> <br /><span style="color: #008080; ">15</span> <span style="color: #0000FF; ">void</span> pushup(<span style="color: #0000FF; ">int</span> p) {<br /><span style="color: #008080; ">16</span>     grade[p] = max(grade[lc(p)], grade[rc(p)]);<br /><span style="color: #008080; ">17</span> }<br /><span style="color: #008080; ">18</span> <br /><span style="color: #008080; ">19</span> <span style="color: #0000FF; ">void</span> build(<span style="color: #0000FF; ">int</span> l, <span style="color: #0000FF; ">int</span> r, <span style="color: #0000FF; ">int</span> p) {<br /><span style="color: #008080; ">20</span>     <span style="color: #0000FF; ">if</span>(l == r) {<br /><span style="color: #008080; ">21</span>         scanf("%d", &grade[p]);<br /><span style="color: #008080; ">22</span>         <span style="color: #0000FF; ">return</span>;<br /><span style="color: #008080; ">23</span>     }<br /><span style="color: #008080; ">24</span>     <span style="color: #0000FF; ">int</span> mid = (l + r) >> 1;<br /><span style="color: #008080; ">25</span>     build(l, mid, lc(p));<br /><span style="color: #008080; ">26</span>     build(mid + 1, r, rc(p));<br /><span style="color: #008080; ">27</span>     pushup(p);<br /><span style="color: #008080; ">28</span> }<br /><span style="color: #008080; ">29</span> <br /><span style="color: #008080; ">30</span> <span style="color: #0000FF; ">int</span> query(<span style="color: #0000FF; ">int</span> L, <span style="color: #0000FF; ">int</span> R, <span style="color: #0000FF; ">int</span> l, <span style="color: #0000FF; ">int</span> r, <span style="color: #0000FF; ">int</span> p) {<br /><span style="color: #008080; ">31</span>     <span style="color: #0000FF; ">int</span> res = -inf; <br /><span style="color: #008080; ">32</span>     <span style="color: #0000FF; ">if</span>(L == l && R == r) <span style="color: #0000FF; ">return</span> grade[p];<br /><span style="color: #008080; ">33</span>     <span style="color: #0000FF; ">int</span> mid = (l + r) >> 1;<br /><span style="color: #008080; ">34</span>     <span style="color: #0000FF; ">if</span>(L > mid) res = max(res, query(L, R, mid + 1, r, rc(p)));<br /><span style="color: #008080; ">35</span>     <span style="color: #0000FF; ">else</span> <span style="color: #0000FF; ">if</span>(R <= mid) res = max(res, query(L, R, l, mid, lc(p)));<br /><span style="color: #008080; ">36</span>     <span style="color: #0000FF; ">else</span> res = max(res, max(query(L, mid, l, mid, lc(p)), query(mid + 1, R, mid + 1, r, rc(p))));<br /><span style="color: #008080; ">37</span>     <span style="color: #0000FF; ">return</span> res;<br /><span style="color: #008080; ">38</span> }<br /><span style="color: #008080; ">39</span> <br /><span style="color: #008080; ">40</span> <span style="color: #0000FF; ">void</span> update(<span style="color: #0000FF; ">int</span> x, <span style="color: #0000FF; ">int</span> val, <span style="color: #0000FF; ">int</span> l, <span style="color: #0000FF; ">int</span> r, <span style="color: #0000FF; ">int</span> p) {<br /><span style="color: #008080; ">41</span>     <span style="color: #0000FF; ">if</span>(l == r) {<br /><span style="color: #008080; ">42</span>         grade[p] = val;<br /><span style="color: #008080; ">43</span>         <span style="color: #0000FF; ">return</span>;<br /><span style="color: #008080; ">44</span>     }<br /><span style="color: #008080; ">45</span>     <span style="color: #0000FF; ">int</span> mid = (l + r) >> 1;<br /><span style="color: #008080; ">46</span>     <span style="color: #0000FF; ">if</span>(x <= mid) update(x, val, l, mid, lc(p));<br /><span style="color: #008080; ">47</span>     <span style="color: #0000FF; ">else</span> update(x, val, mid + 1, r, rc(p));<br /><span style="color: #008080; ">48</span>     pushup(p);<br /><span style="color: #008080; ">49</span> }<br /><span style="color: #008080; ">50</span> <br /><span style="color: #008080; ">51</span> <span style="color: #0000FF; ">int</span> main() {<br /><span style="color: #008080; ">52</span>     <span style="color: #0000FF; ">int</span> a, b;<br /><span style="color: #008080; ">53</span>     <span style="color: #0000FF; ">char</span> str[10];<br /><span style="color: #008080; ">54</span>     <span style="color: #0000FF; ">while</span>(~scanf("%d%d", &n, &m)) {<br /><span style="color: #008080; ">55</span>         build(1, n, 1);<br /><span style="color: #008080; ">56</span>         <span style="color: #0000FF; ">while</span>(m--) {<br /><span style="color: #008080; ">57</span>             scanf("%s%d%d", str, &a, &b);<br /><span style="color: #008080; ">58</span>             <span style="color: #0000FF; ">if</span>(str[0] == 'Q') printf("%d\n", query(a, b, 1, n, 1));<br /><span style="color: #008080; ">59</span>             <span style="color: #0000FF; ">else</span> update(a, b, 1, n, 1);<br /><span style="color: #008080; ">60</span>         }<br /><span style="color: #008080; ">61</span>     }<br /><span style="color: #008080; ">62</span>     <span style="color: #0000FF; ">return</span> 0;<br /><span style="color: #008080; ">63</span> }</div><img src ="http://www.shnenglu.com/y346491470/aggbug/163936.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.shnenglu.com/y346491470/" target="_blank">y @ The Angry Teletubbies</a> 2012-01-10 15:00 <a href="http://www.shnenglu.com/y346491470/articles/163936.html#Feedback" target="_blank" style="text-decoration:none;">鍙戣〃璇勮</a></div>]]></description></item><item><title>hdoj 1166 鏁屽叺甯冮樀 - 鏍戠姸鏁扮粍 or 綰挎鏍?/title><link>http://www.shnenglu.com/y346491470/articles/163905.html</link><dc:creator>y @ The Angry Teletubbies</dc:creator><author>y @ The Angry Teletubbies</author><pubDate>Mon, 09 Jan 2012 17:25:00 GMT</pubDate><guid>http://www.shnenglu.com/y346491470/articles/163905.html</guid><wfw:comment>http://www.shnenglu.com/y346491470/comments/163905.html</wfw:comment><comments>http://www.shnenglu.com/y346491470/articles/163905.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.shnenglu.com/y346491470/comments/commentRss/163905.html</wfw:commentRss><trackback:ping>http://www.shnenglu.com/y346491470/services/trackbacks/163905.html</trackback:ping><description><![CDATA[銆愰鎰忋戯細緇欏嚭n涓叺钀ワ紝姣忎釜鍏佃惀鍒濆閮芥湁涓瀹氭暟閲忕殑澹叺錛屽叺钀ョ殑澹叺鏁伴噺浼氭敼鍙橈紝涓嶅畾鏃舵煡璇㈢i涓叺钀ュ埌絎琷涓叺钀ョ殑澹叺鏁伴噺錛岃緭鍑烘瘡嬈¤闂殑緇撴灉銆?n <= 50000)<br /><br />銆愰瑙c戯細寰堢畝鍗曠殑涓閬撴暟鎹粨鏋勯鐩?br />               榪欑棰樼洰濡傛灉鑳界敤鏍戠姸鏁扮粍鏈濂藉氨鐢紝鍥犱負鏍戠姸鏁扮粍澶鏄撳啓浜嗐?br />               鏈榪戝湪瀛︾嚎孌墊爲錛屾墍浠ヤ袱縐嶇増鏈殑閮藉啓浜嗕竴嬈°?br /><br />銆愪唬鐮併戯細<br /><br />   銆愭爲鐘舵暟緇勩戯細<br /><div style="background-color:#eeeeee;font-size:13px;border:1px solid #CCCCCC;padding-right: 5px;padding-bottom: 4px;padding-left: 4px;padding-top: 4px;width: 98%;word-break:break-all"><!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />--><span style="color: #008080; "> 1</span> #include "iostream"<br /><span style="color: #008080; "> 2</span> #include "cstdio"<br /><span style="color: #008080; "> 3</span> #include "cstring"<br /><span style="color: #008080; "> 4</span> #include "algorithm"<br /><span style="color: #008080; "> 5</span> #include "vector"<br /><span style="color: #008080; "> 6</span> #include "queue"<br /><span style="color: #008080; "> 7</span> <span style="color: #0000FF; ">using</span> <span style="color: #0000FF; ">namespace</span> std;<br /><span style="color: #008080; "> 8</span> <span style="color: #0000FF; ">#define</span> pb push_back<br /><span style="color: #008080; "> 9</span> <span style="color: #0000FF; ">#define</span> maxn 50005<br /><span style="color: #008080; ">10</span> <span style="color: #0000FF; ">#define</span> lowbit(x) (x & (-x))<br /><span style="color: #008080; ">11</span> <span style="color: #0000FF; ">int</span> val[maxn], n;<br /><span style="color: #008080; ">12</span> <br /><span style="color: #008080; ">13</span> <span style="color: #0000FF; ">void</span> add(<span style="color: #0000FF; ">int</span> x, <span style="color: #0000FF; ">int</span> e) {<br /><span style="color: #008080; ">14</span>     <span style="color: #0000FF; ">for</span>(<span style="color: #0000FF; ">int</span> i = x; i < maxn; i += lowbit(i)) {<br /><span style="color: #008080; ">15</span>         val[i] += e;<br /><span style="color: #008080; ">16</span>     }<br /><span style="color: #008080; ">17</span> }<br /><span style="color: #008080; ">18</span> <br /><span style="color: #008080; ">19</span> <span style="color: #0000FF; ">int</span> sum(<span style="color: #0000FF; ">int</span> x) {<br /><span style="color: #008080; ">20</span>     <span style="color: #0000FF; ">int</span> res = 0;<br /><span style="color: #008080; ">21</span>     <span style="color: #0000FF; ">for</span>(<span style="color: #0000FF; ">int</span> i = x; i; i -= lowbit(i)) {<br /><span style="color: #008080; ">22</span>         res += val[i];<br /><span style="color: #008080; ">23</span>     }<br /><span style="color: #008080; ">24</span>     <span style="color: #0000FF; ">return</span> res;<br /><span style="color: #008080; ">25</span> }<br /><span style="color: #008080; ">26</span> <br /><span style="color: #008080; ">27</span> <span style="color: #0000FF; ">int</span> main() {<br /><span style="color: #008080; ">28</span>     <span style="color: #0000FF; ">int</span> T, Case = 1, e, a, b;<br /><span style="color: #008080; ">29</span>     <span style="color: #0000FF; ">char</span> str[10];<br /><span style="color: #008080; ">30</span>     scanf("%d", &T);<br /><span style="color: #008080; ">31</span>     <span style="color: #0000FF; ">while</span>(T--) {<br /><span style="color: #008080; ">32</span>         scanf("%d", &n);<br /><span style="color: #008080; ">33</span>         memset(val, 0, <span style="color: #0000FF; ">sizeof</span>(val));<br /><span style="color: #008080; ">34</span>         <span style="color: #0000FF; ">for</span>(<span style="color: #0000FF; ">int</span> i = 1; i <= n; i++) {<br /><span style="color: #008080; ">35</span>             scanf("%d", &e);<br /><span style="color: #008080; ">36</span>             add(i, e);<br /><span style="color: #008080; ">37</span>         }<br /><span style="color: #008080; ">38</span>         printf("Case %d:\n", Case++);<br /><span style="color: #008080; ">39</span>         <span style="color: #0000FF; ">while</span>(1) {<br /><span style="color: #008080; ">40</span>             scanf("%s", str);<br /><span style="color: #008080; ">41</span>             <span style="color: #0000FF; ">if</span>(str[0] == 'E') <span style="color: #0000FF; ">break</span>;<br /><span style="color: #008080; ">42</span>             <span style="color: #0000FF; ">else</span> {<br /><span style="color: #008080; ">43</span>                 scanf("%d%d", &a, &b);<br /><span style="color: #008080; ">44</span>                 <span style="color: #0000FF; ">if</span>(str[0] == 'Q') printf("%d\n", sum(b) - sum(a - 1));<br /><span style="color: #008080; ">45</span>                 <span style="color: #0000FF; ">else</span> <span style="color: #0000FF; ">if</span>(str[0] == 'A') add(a, b);<br /><span style="color: #008080; ">46</span>                 <span style="color: #0000FF; ">else</span> add(a, -b);<br /><span style="color: #008080; ">47</span>             }<br /><span style="color: #008080; ">48</span>         }<br /><span style="color: #008080; ">49</span>     }<br /><span style="color: #008080; ">50</span>     <span style="color: #0000FF; ">return</span> 0;<br /><span style="color: #008080; ">51</span> }</div><br />   銆愮嚎孌墊爲銆戯細<br /><div style="background-color:#eeeeee;font-size:13px;border:1px solid #CCCCCC;padding-right: 5px;padding-bottom: 4px;padding-left: 4px;padding-top: 4px;width: 98%;word-break:break-all"><!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />--><span style="color: #008080; "> 1</span> #include "iostream"<br /><span style="color: #008080; "> 2</span> #include "cstdio"<br /><span style="color: #008080; "> 3</span> #include "cstring"<br /><span style="color: #008080; "> 4</span> #include "algorithm"<br /><span style="color: #008080; "> 5</span> #include "vector"<br /><span style="color: #008080; "> 6</span> #include "queue"<br /><span style="color: #008080; "> 7</span> <span style="color: #0000FF; ">using</span> <span style="color: #0000FF; ">namespace</span> std;<br /><span style="color: #008080; "> 8</span> <span style="color: #0000FF; ">#define</span> pb push_back<br /><span style="color: #008080; "> 9</span> <span style="color: #0000FF; ">#define</span> lc(x) (x << 1)<br /><span style="color: #008080; ">10</span> <span style="color: #0000FF; ">#define</span> rc(x) (x << 1 | 1)<br /><span style="color: #008080; ">11</span> <span style="color: #0000FF; ">#define</span> MAX 50005<br /><span style="color: #008080; ">12</span> <span style="color: #0000FF; ">int</span> seg[MAX<<2];<br /><span style="color: #008080; ">13</span> <span style="color: #0000FF; ">int</span> n;<br /><span style="color: #008080; ">14</span> <span style="color: #0000FF; ">void</span> pushup(<span style="color: #0000FF; ">int</span> p) {<br /><span style="color: #008080; ">15</span>     seg[p] = seg[lc(p)] + seg[rc(p)];<br /><span style="color: #008080; ">16</span> }<br /><span style="color: #008080; ">17</span> <br /><span style="color: #008080; ">18</span> <span style="color: #0000FF; ">void</span> build(<span style="color: #0000FF; ">int</span> l, <span style="color: #0000FF; ">int</span> r, <span style="color: #0000FF; ">int</span> p) {<br /><span style="color: #008080; ">19</span>     <span style="color: #0000FF; ">if</span>(l == r) {<br /><span style="color: #008080; ">20</span>         scanf("%d", &seg[p]);<br /><span style="color: #008080; ">21</span>         <span style="color: #0000FF; ">return</span>;<br /><span style="color: #008080; ">22</span>     }<br /><span style="color: #008080; ">23</span>     <span style="color: #0000FF; ">int</span> mid = (l + r) >> 1;<br /><span style="color: #008080; ">24</span>     build(l, mid, lc(p));<br /><span style="color: #008080; ">25</span>     build(mid + 1, r, rc(p));<br /><span style="color: #008080; ">26</span>     pushup(p);<br /><span style="color: #008080; ">27</span> }<br /><span style="color: #008080; ">28</span> <br /><span style="color: #008080; ">29</span> <span style="color: #0000FF; ">int</span> query(<span style="color: #0000FF; ">int</span> L, <span style="color: #0000FF; ">int</span> R, <span style="color: #0000FF; ">int</span> l, <span style="color: #0000FF; ">int</span> r, <span style="color: #0000FF; ">int</span> p) {<br /><span style="color: #008080; ">30</span>     <span style="color: #0000FF; ">if</span>(L == l && R == r) <span style="color: #0000FF; ">return</span> seg[p];<br /><span style="color: #008080; ">31</span>     <span style="color: #0000FF; ">int</span> mid = (l + r) >> 1;<br /><span style="color: #008080; ">32</span>     <span style="color: #0000FF; ">if</span>(L > mid) <span style="color: #0000FF; ">return</span> query(L, R, mid + 1, r, rc(p));<br /><span style="color: #008080; ">33</span>     <span style="color: #0000FF; ">else</span> <span style="color: #0000FF; ">if</span>(R <= mid) <span style="color: #0000FF; ">return</span> query(L, R, l, mid, lc(p));<br /><span style="color: #008080; ">34</span>     <span style="color: #0000FF; ">else</span> <span style="color: #0000FF; ">return</span> query(L, mid, l, mid, lc(p)) + query(mid + 1, R, mid + 1, r, rc(p));<br /><span style="color: #008080; ">35</span> }<br /><span style="color: #008080; ">36</span> <br /><span style="color: #008080; ">37</span> <span style="color: #0000FF; ">void</span> update(<span style="color: #0000FF; ">int</span> x, <span style="color: #0000FF; ">int</span> val, <span style="color: #0000FF; ">int</span> l, <span style="color: #0000FF; ">int</span> r, <span style="color: #0000FF; ">int</span> p) {<br /><span style="color: #008080; ">38</span>     <span style="color: #0000FF; ">if</span>(l == r) {<br /><span style="color: #008080; ">39</span>         seg[p] += val;<br /><span style="color: #008080; ">40</span>         <span style="color: #0000FF; ">return</span>;<br /><span style="color: #008080; ">41</span>     }<br /><span style="color: #008080; ">42</span>     <span style="color: #0000FF; ">int</span> mid = (l + r) >> 1;<br /><span style="color: #008080; ">43</span>     <span style="color: #0000FF; ">if</span>(x <= mid) update(x, val, l, mid, lc(p));<br /><span style="color: #008080; ">44</span>     <span style="color: #0000FF; ">else</span> update(x, val, mid + 1, r, rc(p));<br /><span style="color: #008080; ">45</span>     pushup(p);<br /><span style="color: #008080; ">46</span> }<br /><span style="color: #008080; ">47</span> <br /><span style="color: #008080; ">48</span> <span style="color: #0000FF; ">int</span> main() {<br /><span style="color: #008080; ">49</span>     <span style="color: #0000FF; ">int</span> T, Case = 1, a, b;<br /><span style="color: #008080; ">50</span>     <span style="color: #0000FF; ">char</span> str[10];<br /><span style="color: #008080; ">51</span>     scanf("%d", &T);<br /><span style="color: #008080; ">52</span>     <span style="color: #0000FF; ">while</span>(T--) {<br /><span style="color: #008080; ">53</span>         scanf("%d", &n);<br /><span style="color: #008080; ">54</span>         build(1, n, 1);<br /><span style="color: #008080; ">55</span>         printf("Case %d:\n", Case++);<br /><span style="color: #008080; ">56</span>         <span style="color: #0000FF; ">while</span>(1) {<br /><span style="color: #008080; ">57</span>             scanf("%s", str);<br /><span style="color: #008080; ">58</span>             <span style="color: #0000FF; ">if</span>(str[0] == 'E') <span style="color: #0000FF; ">break</span>;<br /><span style="color: #008080; ">59</span>             <span style="color: #0000FF; ">else</span> {<br /><span style="color: #008080; ">60</span>                 scanf("%d%d", &a, &b);<br /><span style="color: #008080; ">61</span>                 <span style="color: #0000FF; ">if</span>(str[0] == 'Q') printf("%d\n", query(a, b, 1, n, 1));<br /><span style="color: #008080; ">62</span>                 <span style="color: #0000FF; ">else</span> <span style="color: #0000FF; ">if</span>(str[0] == 'A') update(a, b, 1, n, 1);<br /><span style="color: #008080; ">63</span>                 <span style="color: #0000FF; ">else</span> update(a, -b, 1, n, 1);<br /><span style="color: #008080; ">64</span>             }<br /><span style="color: #008080; ">65</span>         }<br /><span style="color: #008080; ">66</span>     }<br /><span style="color: #008080; ">67</span>     <span style="color: #0000FF; ">return</span> 0;<br /><span style="color: #008080; ">68</span> }<font color="#008080"><br /></font></div><img src ="http://www.shnenglu.com/y346491470/aggbug/163905.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.shnenglu.com/y346491470/" target="_blank">y @ The Angry Teletubbies</a> 2012-01-10 01:25 <a href="http://www.shnenglu.com/y346491470/articles/163905.html#Feedback" target="_blank" style="text-decoration:none;">鍙戣〃璇勮</a></div>]]></description></item><item><title>poj 2823 Sliding Window - 鍗曡皟闃熷垪http://www.shnenglu.com/y346491470/articles/159653.htmly @ The Angry Teletubbiesy @ The Angry TeletubbiesSat, 05 Nov 2011 01:54:00 GMThttp://www.shnenglu.com/y346491470/articles/159653.htmlhttp://www.shnenglu.com/y346491470/comments/159653.htmlhttp://www.shnenglu.com/y346491470/articles/159653.html#Feedback0http://www.shnenglu.com/y346491470/comments/commentRss/159653.htmlhttp://www.shnenglu.com/y346491470/services/trackbacks/159653.html
銆愰瑙c戯細鍗曡皟闃熷垪鍏ラ棬棰樸?br />
銆愪唬鐮併戯細
 1 #include "iostream"
 2 #include "cstdio"
 3 #include "cstring"
 4 using namespace std;
 5 #define maxn 1000500
 6 int n, k, val;
 7 int maxx[maxn], minn[maxn];
 8 int head1, tail1, head2, tail2, tot;
 9 struct Drab {
10     int val, idx;
11     Drab(){}
12     Drab(int _val, int _idx) {
13         val = _val, idx = _idx;
14     }
15 }que1[maxn], que2[maxn];
16 
17 void init() {
18     tot = 0;
19     head1 = tail1 = head1 = tail1 = 0;
20 }
21 
22 void push1(int val, int idx) {
23     while(head1 < tail1 && que1[tail1 - 1].val > val) tail1--;
24     que1[tail1++= Drab(val, idx);
25 }
26 
27 void push2(int val, int idx) {
28     while(head2 < tail2 && que2[tail2 - 1].val < val) tail2--;
29     que2[tail2++= Drab(val, idx);
30 }
31 
32 int main() {
33     while(~scanf("%d%d"&n, &k)) {
34         init();
35         for(int i = 0; i < n; i++) {
36             scanf("%d"&val);
37             push1(val, i), push2(val, i);
38             if(i >= k - 1) {
39                 if(que1[head1].idx <= i - k) head1++;
40                 minn[tot] = que1[head1].val;
41                 if(que2[head2].idx <= i - k) head2++;
42                 maxx[tot] = que2[head2].val;
43                 tot++;
44             }
45         }
46         for(int i = 0; i < tot; i++) printf("%d ", minn[i]);
47         printf("\n");
48         for(int i = 0; i < tot; i++) printf("%d ", maxx[i]);
49         printf("\n");
50     }
51     return 0;
52 }



y @ The Angry Teletubbies 2011-11-05 09:54 鍙戣〃璇勮
]]>
hdoj 4006 The kth great number - 浼樺厛闃熷垪http://www.shnenglu.com/y346491470/articles/156050.htmly @ The Angry Teletubbiesy @ The Angry TeletubbiesSat, 17 Sep 2011 12:47:00 GMThttp://www.shnenglu.com/y346491470/articles/156050.htmlhttp://www.shnenglu.com/y346491470/comments/156050.htmlhttp://www.shnenglu.com/y346491470/articles/156050.html#Feedback0http://www.shnenglu.com/y346491470/comments/commentRss/156050.htmlhttp://www.shnenglu.com/y346491470/services/trackbacks/156050.html
銆愰瑙c戯細棰樻剰寰堝ソ鐞嗚В錛岃繖閲屽彲浠ョ洿鎺ョ敤stl 鐨?priority queue錛屼唬鐮佽秴綰х煭銆傜淮鎶や竴涓紭鍏堥槦鍒楋紝浣塊槦鍒椾腑鍏冪礌涓暟鎬諱笉瓚呰繃k錛屾煡璇㈡椂鐩存帴杈撳嚭鍫嗛《鍏冪礌鍗沖彲銆?br />
銆愪唬鐮併戯細
 1 #include "iostream"
 2 #include "cstdio"
 3 #include "cstring"
 4 #include "queue"
 5 #include "functional"
 6 #include "string"
 7 using namespace std;
 8 int n, k;
 9 void solve() {
10     int val;
11     string s;
12     priority_queue<int, vector<int>, greater<int> > que;
13     for(int i = 0; i < n; i++) {
14         cin >> s;
15         if(s[0== 'I') {
16             scanf("%d"&val);
17             que.push(val);
18             if(que.size() > k) que.pop();
19         } else cout << que.top() << endl;
20     }
21 }
22 
23 int main() {
24     while(~scanf("%d%d"&n, &k)) solve();
25     return 0;
26 }




y @ The Angry Teletubbies 2011-09-17 20:47 鍙戣〃璇勮
]]>
久久婷婷五月综合成人D啪| 久久精品成人免费网站| 久久国产免费直播| 66精品综合久久久久久久| 亚洲AV无码一区东京热久久| 超级碰碰碰碰97久久久久| 久久影院亚洲一区| 欧美与黑人午夜性猛交久久久| AA级片免费看视频久久| 色综合久久88色综合天天| 国产亚洲美女精品久久久久狼| 久久精品国产精品青草app| 久久99精品国产| 99国内精品久久久久久久| 久久99精品免费一区二区| 久久国产福利免费| 日韩久久久久中文字幕人妻| 亚洲精品午夜国产va久久| 少妇高潮惨叫久久久久久| 久久久久亚洲av无码专区导航 | 国产亚洲精久久久久久无码77777| 国产精品久久久香蕉| 无码人妻久久久一区二区三区| 久久精品国产亚洲AV香蕉| 99久久国产主播综合精品 | 2020国产成人久久精品| 久久久久高潮综合影院| 久久精品国产亚洲AV无码偷窥| 99久久精品国产一区二区| 亚洲午夜无码AV毛片久久| 国内精品九九久久久精品| 内射无码专区久久亚洲| 久久精品一本到99热免费| 久久九九免费高清视频| 久久久久无码精品国产不卡| 国产精品欧美久久久久天天影视| 久久人人添人人爽添人人片牛牛| 99国产精品久久久久久久成人热| 久久综合九色综合久99| 国产精品一区二区久久| 亚洲精品无码久久久久|