当前你的浏览器版本过低,网站已在兼容模式下运行,兼容模式仅提供最小功能支持,网站样式可能显示不正常。
请尽快升级浏览器以体验网站在线编辑、在线运行等功能。

建议使用的浏览器:

谷歌Chrome 火狐Firefox Opera浏览器 微软Edge浏览器 QQ浏览器 360浏览器 傲游浏览器

7072:Boring data structure problem

题目描述
"Why don't you write some background story for this boring data structure problem?"
"Because it's too boring..."

There's a queue(not the original queue one may refer to as a data structure, here a double-ended queue, to be more precise) that is initially empty. Then, there are infinite elements numbered $1,2,\dots$, entering the queue in the order of their numbers(i.e., the first element to enter the queue is numbered $1$, the second, $2$ et cetera). If an element leaves the queue, it will not enter the queue anymore.

Now there are $q$ operations, each in one of the following forms:
  • Let the next element enter the left end of the queue.

  • Let the next element enter the right end of the queue.

  • Let the element numbered $x$ leave the queue.

  • Ask the number of the element in the middle of the queue. (If there are $m$ elements in the queue currently, you should output the number of the element that is the $\lceil \frac{m+1}{2} \rceil$th from the left).
输入解释
The first line of each test case contains one number $q(1\leq q \leq 10^7)$, denoting the number of operations.

Then $q$ lines follow, each in one of the following forms:
  • $L$, denoting the next element enters the left end of the queue

  • $R$, denoting the next element enters the right end of the queue

  • $G$ $x$, denoting the element numbered $x$ leaves the queue (It is guaranteed that the element numbered $x$ is in the queue when this operation is applied)

  • $Q$ denoting a query that asks the number of the element in the middle of the queue(It is guaranteed that the queue is not empty when this operation is applied)

It is guaranteed that the number of operations of the third and the fourth type is both less than $1.5\cdot 10^6$.
输出解释
For each operation of the fourth kind, output a number in a line, denoting the answer to the query.
输入样例
9
L
L
L
Q
R
Q
G 1
R
Q
输出样例
2
1
4

该题目是Virtual Judge题目,来自 杭电HDUOJ

源链接: HDU-7072

最后修改于 2021-10-23T19:11:19+00:00 由爬虫自动更新

共提交 0

通过率 --%
时间上限 内存上限
12000/6000MS(Java/Others) 262144/262144K(Java/Others)