#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; // Binary Indexed Tree template class BinaryIndexedTree { private: int n; vector data; public: BinaryIndexedTree(int n){ // コンストラクタ this->n = n; data.assign(n+1, 0); } void add(int k, T x){ // k番目の要素にxを加算する ++ k; while(k <= n){ data[k] += x; k += k & -k; } } T sum(int k){ // 区間[0,k]の総和を返す ++ k; T ret = 0; while(k > 0){ ret += data[k]; k -= k & -k; } return ret; } T sum(int a, int b){ // 区間[a,b]の総和を返す return sum(b) - sum(a-1); } }; int main() { int n, q; cin >> n >> q; BinaryIndexedTree bit(2*n); for(int t=0; t> x >> y >> z; if(x == 'R'){ int a = (2 * n - 1 - y + t) % (2 * n); bit.add(a, z); } else if(x == 'L'){ int a = (y + t) % (2 * n); bit.add(a, z); } else{ long long ret = 0; int a = (y + t) % (2 * n); int b = (z - 1 + t) % (2 * n); if(a <= b) ret += bit.sum(a, b); else ret += bit.sum(0, b) + bit.sum(a, 2*n-1); b = (2 * n - 1 - y + t) % (2 * n); a = (2 * n - z + t) % (2 * n); if(a <= b) ret += bit.sum(a, b); else ret += bit.sum(0, b) + bit.sum(a, 2*n-1); cout << ret << endl; } } return 0; }