#include #include #include #include #include #define N_MAX 2000 #define Q_MAX 2000 using namespace std; typedef unsigned long long ULL; typedef long long LL; typedef struct { int pos; int num; char way; }Fish; int main() { int N, Q; char x[Q_MAX]; int y[Q_MAX], z[Q_MAX]; cin >> N >> Q; for (int i = 0; i < Q; ++i) cin >> x[i] >> y[i] >> z[i]; vector fish; for (int i = 0; i < Q; ++i) { for (auto it = fish.begin(); it != fish.end(); ++it) { if ((*it).way == 'L') { if ((*it).pos == 0) (*it).way = 'R'; else --((*it).pos); } else { if ((*it).pos == N-1) (*it).way = 'L'; else ++((*it).pos); } } LL count = 0; switch (x[i]) { case 'L': fish.push_back(Fish{ y[i], z[i], 'L' }); break; case 'R': fish.push_back(Fish{ y[i], z[i], 'R' }); break; case 'C': for (auto it = fish.begin(); it != fish.end(); ++it) { if ((*it).pos >= y[i] && (*it).pos < z[i]) count += (*it).num; } cout << count << endl; break; } } return 0; }