C. Books Queries

链接

[http://codeforces.com/contest/1066/problem/C]

题意

开始空队列,可以进行前插和后插,还可以查询使某个数的为最左或最右需要去掉的最少数字

分析

模拟即可用l,r标记最左和最有的位置,

代码

#include<bits/stdc++.h>
using namespace std;

int main(){
	
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
    int q,r=0,l=1,n;
    int a[200010];
    char ch;
    //freopen("in.txt","r",stdin);
    cin>>q;
    while(q--){
    	cin>>ch>>n;
    	if(ch=='R'){
    		++r;
    		a[n]=r;
		}
		if(ch=='L'){
			--l;
			a[n]=l;
		}
		if(ch=='?'){
			cout<<min(a[n]-l,r-a[n])<<endl;
		}
	}
	return 0;
}
posted @ 2018-10-13 19:45  ChunhaoMo  阅读(333)  评论(0)    收藏  举报