樣例輸入 #1 複製 8
l 1r 2
r 3?
2l 4?1
l 5?
1輸出 #1 複製 112
輸入 #2 複製 10
l 100
r 100000
r 123
l 101
?123
l 10
r 115
?100
r 110
?115
輸出 #2 複製 021
說明/提示
let's take a look
at the first example and let』s consider queries:
the shelf will look like [1] [1] [1] ;
the shelf will look like [1,2] [1, 2] [1,2] ;
the shelf will look like [1,2,3] [1, 2, 3] [1,2,3] ;
the shelf looks like [1,2,3] [1, \textbf, 3] [1,2,3] so the answer is 1 1 1 ;
the shelf will look like [4,1,2,3] [4, 1, 2, 3] [4,1,2,3] ;
the shelf looks like [4,1,2,3] [4, \textbf, 2, 3] [4,1,2,3] so the answer is 1 1 1 ;
the shelf will look like [5,4,1,2,3] [5, 4, 1, 2, 3] [5,4,1,2,3] ;
the shelf looks like [5,4,1,2,3] [5, 4, \textbf, 2, 3] [5,4,1,2,3] so the answer is 2 2 2 .
let』s take a look at the second example and let』s consider queries:
the shelf will look like [100] [100] [100] ;
the shelf will look like [100,100000] [100, 100000] [100,100000] ;
the shelf will look like [100,100000,123] [100, 100000, 123] [100,100000,123] ;
the shelf will look like [101,100,100000,123] [101, 100, 100000, 123] [101,100,100000,123] ;
the shelf looks like [101,100,100000,123] [101, 100, 100000, \textbf] [101,100,100000,123] so the answer is 0 0 0 ;
the shelf will look like [10,101,100,100000,123] [10, 101, 100, 100000, 123] [10,101,100,100000,123] ;
the shelf will look like [10,101,100,100000,123,115] [10, 101, 100, 100000, 123, 115] [10,101,100,100000,123,115] ;
the shelf looks like [10,101,100,100000,123,115] [10, 101, \textbf, 100000, 123, 115] [10,101,100,100000,123,115] so the answer is 2 2 2 ;
the shelf will look like [10,101,100,100000,123,115,110] [10, 101, 100, 100000, 123, 115, 110] [10,101,100,100000,123,115,110] ;
the shelf looks like [10,101,100,100000,123,115,110] [10, 101, 100, 100000, 123, \textbf, 110] [10,101,100,100000,123,115,110] so the answer is 1 1 1 .
選自洛谷優秀題解
開乙個容器進行模擬即可,注意容器設定初始大小不然容易re。設定兩個指標l,r。把容器當作桶,每乙個桶都有乙個編號表示位置,左邊進入那麼就是編號為l,右邊一樣。然後l–或者r++,l=r=0的初始值,第乙個元素為0,然後同時l–,r++
**見下
#include
using namespace std;
intmain()
else
if(s==
"r")
if(s==
"?")}}
return0;
}
雙端佇列(deque)
區別於資料結構的雙端佇列,這裡的是stl的!雙端佇列 deque容器類 include與vector 類似,支援隨機訪問和快速插入刪除,它在容器中某一位置上的操作所花費的是線性時間。與 vector不同的是,deque還支援從開始端插入資料 push front 此外deque 不支援與vector...
雙端佇列deque
雙端佇列deque容器是一種優化了的 在序列兩端對元素進行新增和刪除操作的基本序列容器。它也允許適度快速地進行隨機訪問 就像vector一樣,它也有乙個operator操作符,然而,它沒有vector的那種把所有的東西都儲存在一塊連續的記憶體塊中的約束。deque的典型實現是利用多個連續的儲存塊 同...
deque雙端佇列
deque 1 生成構造 constructing deques include include int main std deque fifth myints,myints sizeof myints sizeof int fifth std deque first 3 deque with 3 ...