锘??xml version="1.0" encoding="utf-8" standalone="yes"?>美女主播一区,欧美专区在线观看一区,欧美日韩xxxxxhttp://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戯細(xì)棣栧厛鎶婄幆搴忓垪鍒囨柇錛屽彉鎴愪袱鍊嶉暱搴︺傞澶勭悊鎵鏈夊墠 i 欏瑰拰銆?br />               鏋氫婦璧風(fēng)偣j錛屼嬌鐢ㄥ崟璋冮槦鍒楁眰鍖洪棿鏈灝忓鹼紝濡傛灉鏈灝忓煎ぇ浜巗um[j]鍒欑瓟妗堝姞涓銆?br />
銆愪唬鐮併戯細(xì)
 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戯細(xì)寰堝鏄撴兂鍒癘(n*k)鐨勫仛娉曪紝浣嗘槸璧よ8瑁哥殑TLE銆?br />               鍏堟眰鍑烘墍鏈夊墠n欏瑰拰銆?br />               鏋氫婦姣忎竴涓綅緗?i 浣滀負(fù)緇撴潫鐐癸紝鐜板湪鎴戜滑瑕佹壘鍒版渶灝忕殑sum[j], i - k <= j < i .
               鏈寸礌鍋氭硶鏄洿鎺ユ灇涓綩(k)錛屾敼榪涗竴鐐圭殑鍋氭硶鏄敤綰挎鏍?wèi)鏌ヨ鍖洪棿鏈澶у糘(logk).
               浣嗘槸鍙互璇佹槑鏈夊崟璋冩э紝鏁呭彲浠ョ敤鍗曡皟闃熷垪浼樺寲錛屾煡璇㈢洿鎺ヤ紭鍖栧埌O(1)銆?br />               鎵浠ユ渶緇堝鏉傚害鏄疧(n)銆?br />
銆愪唬鐮併戯細(xì)
 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[銆愰鎰忋戯細(xì)<span style="background-color: #ffffff; font-family: Arial; line-height: 26px; text-align: left; ">鏈塶涓粦甯洟浼欐垚鍛橈紝涓旀湁涓や釜甯淳 銆?br /></span>               D x y 琛ㄧず x y灞炰簬涓嶅悓鐨勫府?huà)z撅紱<br />               A x y 璇㈤棶 x y鐨勫叧緋匯?br />               鍏崇郴鏈変笁縐嶏細(xì)1.Not sure yet. 2.In different gangs. 3.In the same gangs.<br />               緇欏嚭m涓搷浣滐紝鍥炵瓟鎵鏈夎闂?br /><br />銆愰瑙c戯細(xì)騫舵煡闆嗛鐩紝鍙槸鎯充笉鍑烘潵錛岀粰闃熷弸鐐規(guī)槑浜?jiǎn)銆?br />               瀵逛簬姣忎釜浜猴紝鎷嗙偣x x’銆?br />               瀵逛簬D x y榪欎釜鎿嶄綔,鎶妜鍜寉’鎵鍦ㄧ殑鍒嗛噺鍚堝茍錛寈’鍜寉鎵鍦ㄧ殑鍒嗛噺鍚堝茍銆?br />               瀵逛簬A x y榪欎釜璇㈤棶,<br />                        濡傛灉find(x) == find(y)錛屽垯浠栦滑灞炰簬鍚屼竴涓府?huà)z撅紱<br />                        鍚﹀垯錛屽鏋渇ind(x) == find(y')錛屼粬浠睘浜庝笉鍚屽府?huà)z撅紱<br />                        鍚﹀垯錛屼粬浠殑鍏崇郴涓嶇‘瀹氥?br /><br />               鏈濂藉湪綰鎬笂鐢諱笅鍥撅紝榪欐牱姣旇緝瀹規(guī)槗鐞嗚В銆?br /><br />銆愪唬鐮併戯細(xì)<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戯細(xì)妯℃澘棰樸?br />
銆愪唬鐮併戯細(xì)
 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[銆愰鎰忋戯細(xì)鏈変竴鍧楅潰縐負(fù)h*w鐨勯氱煡鏍忥紝寰涓婇潰璐翠竴浜?*wi鐨勯氱煡涓婂幓錛岃創(chuàng)鐨勪綅緗繪槸閫夋嫨鍙互璐寸殑鏈楂樹(shù)綅緗殑鏈宸︾錛屼笖閫氱煡涓嶈兘閲嶅彔銆傜粰鍑簄涓氱煡錛屽茍璇㈤棶瀹冧滑鍒嗗埆璐村湪絎嚑琛屻?br /><br />銆愰瑙c戯細(xì)綰挎鏍?wèi)锛尵l存姢綰挎鏍?wèi)鐨勫尯闂翠负[1, min(h,n)]錛屽洜涓烘渶鍧忔儏鍐典篃灝變竴琛岃創(chuàng)涓涓紝鎵浠ュ悗闈㈢殑鏄浣欑殑銆?br />               鍥犱負(fù)鏌ヨ鍜屾洿鏂版槸鍚屾椂鐨勶紝鎵浠ユ垜鍐欏湪涓璧蜂簡(jiǎn)銆?br /><br />銆愪唬鐮併戯細(xì)<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; "> 鎵懼埌鏈浼樹(shù)綅緗茍鏇存柊</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 - 鏍?wèi)鐘舵暟缁勬眰閫嗗簭瀵?/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[銆愰鎰忋戯細(xì)緇欏嚭n涓暟緇勬垚鐨勪竴涓簭鍒楋紝鎴戜滑鍙互鎶婂墠m涓暟縐誨埌搴忓垪鐨勫悗闈紝榪欐牱鎴戜滑涓鍏卞彲浠ュ緱鍒皀涓笉鍚岀殑搴忓垪銆傛眰榪檔涓簭鍒椾腑錛岄嗗簭瀵規(guī)渶灝忎負(fù)澶氬皯銆?br /><br />銆愰瑙c戯細(xì)鍙互鍒╃敤鏍?wèi)鐘舵暟缁勬垨鑰呯嚎孌墊爲(wèi)鍦∣(nlogn)鏃墮棿閲屾眰鍑哄垵濮嬪簭鍒楃殑閫嗗簭瀵癸紝鐒跺悗姣忔鐢∣(1)鐨勬椂闂存帹鍑烘瘡縐誨姩涓涓暟鍒板簭鍒楀悗闈箣鍚庣殑閫嗗簭瀵廣?br />               鎬誨鏉傚害O(nlogn + n)銆?br /><br />銆愪唬鐮併戯細(xì)<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[銆愰鎰忋戯細(xì)緇欏嚭n(n<=100000)涓暟鐨勫垵濮嬪鹼紝緙栧彿1~n錛屽啀緇欏嚭q(q<=100000)涓搷浣滐紝涓嶅畾鏃跺線絎琲涓暟鍒扮j涓暟涓婂姞涓婁竴涓父鏁癱鎴栬呮煡璇㈢i涓暟鍒扮j涓暟鐨勫拰銆?br /><br />銆愰瑙c戯細(xì)榪樻槸綰挎鏍?wèi)鐨勫叆闂ㄩ鐩Q屽嚟鑷繁鐨勭悊瑙h8鎵撲簡(jiǎn)涓嬈$嚎孌墊爲(wèi)錛屽寤惰繜鏍囪鐞嗚В寰楁洿閫忓垏浜?jiǎn)銆?br />               娉ㄦ剰瑕佺敤long long.<br /><br />銆愪唬鐮併戯細(xì)<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[銆愰鎰忋戯細(xì)鎬繪墍鍛ㄧ煡錛孌ota閲岄潰鏈変釜灞犲か錛屼粬鏈変釜鍚婇挬銆傜幇鍦ㄨ冭檻浠栫殑鍚婇挬鐢眓(n<=100000)孌靛皬媯掔粍鎴愶紝鍒濆鏃訛紝閮芥槸閾滄銆傜粰鍑簈(q<=100000)涓搷浣滐紝姣忎釜鎿嶄綔閮藉彲浠ユ妸絎琲孌靛埌絎琷孌電殑灝忔鏇挎崲鎴愬叾浠栫被鍨嬬殑媯掞紙閾滄錛岄摱媯掞紝閲戞錛屼環(huán)鍊煎垎鍒負(fù)1,2,3錛夈傞棶錛岀粡榪噏涓搷浣滀箣鍚庯紝榪欎釜鍚婇挬鐨勬諱環(huán)鍊間負(fù)澶氬皯銆?br /><br />銆愰瑙c戯細(xì)綰挎鏍?wèi)锛屽尯闂存浛鎹㈠Q屽尯闂存煡璇€?br />               鍒濆綰挎鏍?wèi)锛岀悊瑙e欢杩熸爣璁版槸鍏抽敭銆?br />               鏈姣旇緝鐗規(guī)畩錛屾煡璇㈠彧鏈変竴嬈★紝鑰屼笖鏄煡璇㈡暣涓尯闂達(dá)紝杈撳嚭stick[1]鍗沖彲銆?br /><br />銆愪唬鐮併戯細(xì)<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[銆愰鎰忋戯細(xì)緇欏嚭n涓鐢熺殑鍒濆鎴愮嘩錛岀紪鍙?~n錛屼笉瀹氭椂鐨勪慨鏀規(guī)煇涓鐢熺殑鎴愮嘩鍜屾煡璇㈡煇涓孌佃繛緇紪鍙鋒垚緇╃殑鏈楂樺箋?n<=200000)<br /><br />銆愰瑙c戯細(xì)鏁版嵁緇撴瀯棰樼洰錛岀嚎孌墊爲(wèi)縐掍簡(jiǎn)錛屼笉鐭ラ亾鏍?wèi)鐘舵暟缁勮涓嶈銆?br /><br />銆愪唬鐮併戯細(xì)<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 鏁屽叺甯冮樀 - 鏍?wèi)鐘舵暟缁?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[銆愰鎰忋戯細(xì)緇欏嚭n涓叺钀ワ紝姣忎釜鍏佃惀鍒濆閮芥湁涓瀹氭暟閲忕殑澹叺錛屽叺钀ョ殑澹叺鏁伴噺浼?xì)鏀瑰彉锛屼笉瀹氭椂鏌ヨ绗琲涓叺钀ュ埌絎琷涓叺钀ョ殑澹叺鏁伴噺錛岃緭鍑烘瘡嬈¤闂殑緇撴灉銆?n <= 50000)<br /><br />銆愰瑙c戯細(xì)寰堢畝鍗曠殑涓閬撴暟鎹粨鏋勯鐩?br />               榪欑棰樼洰濡傛灉鑳界敤鏍?wèi)鐘舵暟缁勬渶濂藉氨鐢紝鍥犱負(fù)鏍?wèi)鐘舵暟缁勫お瀹规槗鍐欎簡(jiǎn)銆?br />               鏈榪戝湪瀛︾嚎孌墊爲(wèi)錛屾墍浠ヤ袱縐嶇増鏈殑閮藉啓浜?jiǎn)涓嬈°?br /><br />銆愪唬鐮併戯細(xì)<br /><br />   銆愭爲(wèi)鐘舵暟緇勩戯細(xì)<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 />   銆愮嚎孌墊爲(wèi)銆戯細(xì)<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戯細(xì)鍗曡皟闃熷垪鍏ラ棬棰樸?br />
銆愪唬鐮併戯細(xì)
 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戯細(xì)棰樻剰寰堝ソ鐞嗚В錛岃繖閲屽彲浠ョ洿鎺ョ敤stl 鐨?priority queue錛屼唬鐮佽秴綰х煭銆傜淮鎶や竴涓紭鍏堥槦鍒楋紝浣塊槦鍒椾腑鍏冪礌涓暟鎬諱笉瓚呰繃k錛屾煡璇㈡椂鐩存帴杈撳嚭鍫嗛《鍏冪礌鍗沖彲銆?br />
銆愪唬鐮併戯細(xì)
 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 鍙戣〃璇勮
]]>
青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品
  • <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>
            国产精品福利在线观看网址| 国内精品视频在线播放| 国产欧美一区二区色老头| 国内精品伊人久久久久av一坑| 亚洲高清视频在线观看| 亚洲天堂网站在线观看视频| 亚洲欧美在线免费观看| 你懂的视频一区二区| 亚洲巨乳在线| 久久精品官网| 欧美性猛交xxxx乱大交蜜桃 | 香蕉成人伊视频在线观看| 狼狼综合久久久久综合网 | 欧美一区二区三区四区在线观看地址 | 亚洲精品一区二区三区不| 午夜精品偷拍| 亚洲国产精品成人久久综合一区| 中国成人亚色综合网站| 美女主播精品视频一二三四| 国产精品国产亚洲精品看不卡15| 激情五月婷婷综合| 亚洲欧美日韩高清| 亚洲福利国产| 欧美影院视频| 欧美午夜精彩| 亚洲精品之草原avav久久| 久久久久久久成人| 一区二区三区免费网站| 老司机午夜免费精品视频| 国产日韩精品视频一区二区三区| 亚洲精品国产精品乱码不99 | 久久视频在线看| 国产精品久久久久久久久久ktv| 亚洲大黄网站| 久久精品国产一区二区三区免费看| 99re66热这里只有精品3直播| 久久精品国产第一区二区三区最新章节| 欧美视频在线观看免费网址| 亚洲经典在线看| 久久综合伊人| 性色av一区二区三区在线观看| 国产精品a久久久久| 日韩午夜激情av| 欧美sm视频| 久久成人亚洲| 国产欧美一区视频| 亚洲一区在线免费| 欧美激情视频给我| 麻豆精品一区二区综合av| 国产一区二区三区高清在线观看| 亚洲男人影院| 亚洲免费激情| 欧美日韩国产一区二区三区地区 | 欧美激情综合五月色丁香小说| 在线国产精品播放| 久久亚洲国产成人| 久久se精品一区精品二区| 国产麻豆成人精品| 新片速递亚洲合集欧美合集| 99综合在线| 欧美三级小说| 亚洲一区二区三区精品视频| 亚洲理伦电影| 欧美日韩一区三区四区| 亚洲视频图片小说| 99精品久久免费看蜜臀剧情介绍| 欧美日韩精品二区第二页| 一本色道久久99精品综合| 亚洲免费精彩视频| 欧美色道久久88综合亚洲精品| 亚洲视频二区| 一区二区三区不卡视频在线观看| 欧美日韩一区二区三区四区五区 | 国产精品视频免费观看www| 亚洲一区二区免费看| 亚洲少妇中出一区| 国产精品揄拍一区二区| 久久精品欧美日韩| 久久久久久电影| 亚洲电影免费观看高清完整版在线观看 | 亚洲伦理在线免费看| 亚洲人成亚洲人成在线观看| 欧美日韩视频在线一区二区 | 国产精品亚洲综合天堂夜夜| 先锋影音国产精品| 性色av香蕉一区二区| 伊人婷婷欧美激情| 91久久精品国产| 欧美视频日韩视频在线观看| 欧美一区二区三区在线看| 欧美在线一二三| 亚洲欧洲精品一区二区三区波多野1战4 | 国产精品久久久久久久久果冻传媒| 亚洲欧美视频在线| 久久er99精品| 亚洲精品国产品国语在线app| 亚洲精品一区二区三区婷婷月 | 国产精品日韩欧美| 久久在线免费观看| 欧美xxx成人| 亚洲一区二区三区在线看| 欧美一区二区播放| 亚洲国产成人tv| 99精品久久久| 国内精品国产成人| 亚洲国产精品黑人久久久 | 欧美性片在线观看| 久久久青草婷婷精品综合日韩| 久久综合99re88久久爱| 一区二区三区久久网| 亚洲欧美日韩天堂| 亚洲国产欧美日韩精品| 在线亚洲电影| 亚洲高清二区| 亚洲午夜精品一区二区三区他趣| 国产自产女人91一区在线观看| 亚洲国产成人午夜在线一区| 国产精品露脸自拍| 欧美国产一区视频在线观看| 欧美日本一道本在线视频| 欧美一区三区三区高中清蜜桃| 玖玖综合伊人| 亚洲欧美日韩国产综合在线| 噜噜噜91成人网| 午夜精品久久久久99热蜜桃导演| 另类国产ts人妖高潮视频| 午夜宅男久久久| 免费观看国产成人| 久久精品动漫| 欧美日韩中文在线| 美女图片一区二区| 国产精品毛片一区二区三区| 欧美华人在线视频| 国产日韩欧美不卡| aⅴ色国产欧美| 亚洲电影网站| 性一交一乱一区二区洋洋av| 宅男在线国产精品| 欧美a级理论片| 久久久久久精| 国产精品私房写真福利视频| 亚洲国产成人精品久久久国产成人一区 | 一区二区毛片| 亚洲日本成人网| 久久久久亚洲综合| 午夜天堂精品久久久久| 欧美精品v日韩精品v国产精品| 久久久噜噜噜久久中文字免| 国产精品稀缺呦系列在线| 亚洲免费久久| 亚洲精品极品| 老色鬼久久亚洲一区二区| 久久精品视频在线| 国产精品乱码妇女bbbb| 亚洲精品一区二区三区福利| 亚洲国产精品成人一区二区| 午夜精品福利视频| 亚洲欧美在线观看| 欧美亚洲第一区| 亚洲精品专区| 夜夜嗨av一区二区三区| 欧美成人精品福利| 欧美激情亚洲激情| 亚洲国产精品久久久| 久久久久久久精| 久久午夜精品一区二区| 国产香蕉97碰碰久久人人| 亚洲欧美久久| 欧美在线日韩| 国产精品自在在线| 亚洲欧美日韩一区| 香蕉久久a毛片| 国产精品日韩在线播放| 亚洲午夜一区二区| 亚洲女优在线| 国产精品日日摸夜夜添夜夜av| 中国成人亚色综合网站| 亚洲欧美激情视频在线观看一区二区三区| 欧美人与禽猛交乱配| 亚洲精品小视频在线观看| 一本色道久久综合狠狠躁的推荐| 欧美精品乱码久久久久久按摩| 91久久久久久| 中日韩男男gay无套 | 性做久久久久久久免费看| 久久国产精品久久精品国产| 国产欧美日韩一区二区三区| 欧美怡红院视频| 麻豆精品网站| 亚洲肉体裸体xxxx137| 欧美高清在线精品一区| 亚洲人成网站777色婷婷| 亚洲一区二区三区精品视频| 国产精品五月天| 欧美中文字幕精品| 欧美韩日一区二区| 制服丝袜激情欧洲亚洲| 国产精品免费电影| 久久成人免费| 亚洲黄色精品|