這題其實(shí)是一個(gè)樹狀數(shù)組的思維轉(zhuǎn)換題,一般來(lái)說我們是該一個(gè)點(diǎn),求一段和(對(duì)于一維的)。但是如果出現(xiàn)下面情況,你會(huì)如何處理?(借用TC里介紹樹狀數(shù)組的那個(gè)大哥的,鏈接在我上一篇樹狀數(shù)組文章里)
There is an array of n cards. Each card is putted face down on table. You have two queries:
  1. T i j (turn cards from index i to index j, include i-th and j-th card - card which was face down will be face up; card which was face up will be face down)
  2. Q i (answer 0 if i-th card is face down else answer 1)
這里是更新一段,但是只求一點(diǎn),和我們一般的思路不一樣,但是不打緊,我們可以改變思維,我們可以這樣想(引用)
This has solution for each query (and 1 and 2) has time complexity O(log n). In array f (of length n + 1)we will 
store each query T (i , j) - we set f[i]++ and f[j + 1]--. For each card k between i and j (include i and j)
sum f[1] + f[2] + ... + f[k] will be increased for 1, for all others will be same as before
(look at the image 2.0 for clarification), so our solution will be described sum
(which is same as cumulative frequency) module 2.












看了這之后,是不是發(fā)現(xiàn)原來(lái)還可以這樣啊,呵呵,這就是思維轉(zhuǎn)換了,如果你已經(jīng)知道這中思路了,那么這篇文章基本不用看了,因?yàn)槟阋呀?jīng)會(huì)
好了,接下來(lái)我們說說POJ這題吧,你是不是發(fā)現(xiàn)這題和上面那個(gè)英文描述的題很像呢,只不過這個(gè)是二維的,恩,確實(shí),其實(shí)上面那個(gè)就是
POJ_2155的一維版本,好了這樣說,你應(yīng)該懂了吧。下面看看代碼吧(建議先自己想哦),再提供篇集訓(xùn)論文
CODE