1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
| #include <iostream> #include <cstring> #include <algorithm> using namespace std; const int N = 200010; int n; int p[N]; int main() { cin >> n; int l = 0, r = -1; while (n--) { char c; int x; cin >> c >> x; if (c == 'L') p[x] = --l; else if (c == 'R') p[x] = ++r; else cout << min(r - p[x], p[x] - l) << endl; } return 0; }
|