题目链接:http://codeforces.com/contest/1066/problem/C
c++代码:
#include <iostream>
#include <cstring>
using namespace std;
const int maxn=1e6;
int b[maxn];
int main() {
int q;
cin >> q;
int pos=2*1e5;
int left,right;
left=right=pos;
int cnt=0;
while(q--) {
char c;
int t;
cin >> c >> t;
// memset(f,0,sizeof(f));
if(cnt>0) {
if(c=='L') {
left--;
//a[left]=t;
b[t]=left;
}
else if(c=='R') {
right++;
//a[right]=t;
b[t]=right;
}
else {
//int tmp=b[t];
int ans=min(b[t]-left,right-b[t]);
cout << ans <<endl;
}
}
else {
if(c=='L'||c=='R') {
//a[pos]=t;
b[t]=pos;
}
}
cnt++;
}
return 0;
}