CF1066C
题目描述
You have got a shelf and want to put some books on it.You are given q q q queries of three types:L id id id — put a book having index id id id on the shelf to the left from the leftmost existing book;R id id id — put a book having index id id id on the shelf to the right from the rightmost existing book;? id id id — calculate the minimum number of books you need to pop from the left or from the right in such a way that the book with index id id id will be leftmost or rightmost.You can assume that the first book you will put can have any position (it does not matter) and queries of type 3 3 3 are always valid (it is guaranteed that the book in each such query is already placed). You can also assume that you don’t put the same book on the shelf twice, so id id id s don’t repeat in queries of first two types.Your problem is to answer all the queries of type 3 3 3 in order they appear in the input.Note that after answering the query of type 3 3 3 all the books remain on the shelf and the relative order of books does not change.If you are Python programmer, consider using PyPy instead of Python when you submit your code.输入格式The first line of the input contains one integer q q q ( 1≤q≤2⋅105 1 \le q \le 2 \cdot 10^5 1≤q≤2⋅105 ) — the number of queries.Then q q q lines follow. The i i i -th line contains the i i i -th query in format as in the problem statement. It is guaranteed that queries are always valid (for query type 3 3 3 , it is guaranteed that the book in each such query is already placed, and for other types, it is guaranteed that the book was not placed before).It is guaranteed that there is at least one query of type 3 3 3 in the input.In each query the constraint 1≤id≤2⋅105 1 \le id \le 2 \cdot 10^5 1≤id≤2⋅105 is met.
输出格式Print answers to queries of the type 3 3 3 in order they appear in the input.
题意翻译题意描述您需要维护一个数据结构,支持以下三种操作:LLL ididid:在现在序列的左边插一个编号为ididid的物品RRR ididid:在现在序列的右边插一个编号为ididid的物品??? ididid:查询该点左面有几个元素,右面有几个元素,并取min输出输入输出格式:输入格式:第一行,一个整数qqq,表示操作数下面qqq行,每行2个数,表示一个操作输出格式对于每个“?”操作,输出一行一个整数,表示答案输入输出
样例输入 #