You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

29 lines
675 B
C++

#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 50;
int pos[N], l, r;
int main() {
int Q, id;
char op[3];
scanf("%d", &Q);
for (int q = 0; q < Q; q++) {
scanf("%s%d", op, &id);
if (q == 0)
pos[id] = 0;
else
switch (*op) {
case 'L':
pos[id] = --l;
break;
case 'R':
pos[id] = ++r;
break;
case '?':
printf("%d\n", min(abs(pos[id] - l), abs(pos[id] - r)));
break;
}
}
return 0;
}