#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; } template inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); } template inline T sqr(T x) { return x*x; } typedef pair P; typedef long long ll; typedef unsigned long long ull; #define rep(i,n) for(int (i) = 0;(i) < (n);(i)++) #define clr(a) memset((a), 0 ,sizeof(a)) #define mclr(a) memset((a), -1 ,sizeof(a)) #define all(a) (a).begin(),(a).end() #define rall(a) (a).rbegin(), (a).rend() #define sz(a) (sizeof(a)) #define Fill(a,v) fill((int*)a,(int*)(a+(sz(a)/sz(*(a)))),v) bool cheak(int x, int y, int xMax, int yMax){ return x >= 0 && y >= 0 && xMax > x && yMax > y; } const int dx[4] = { -1, 0, 1, 0 }, dy[4] = { 0, 1, 0, -1 }; const int mod = 1000000007; const int INF = 2147483647; struct BIT{ int n; ll bit[10000000]; void init(){ this->n = 10000000; for (int x = 1; x < n; ++x){ if (x + (x & -x) < n && x < n) bit[x + (x & -x)] += bit[x]; } } void add(int a, ll w){ a += 100000; for (int x = a; x <= n; x += x & -x) bit[x] += w; } ll sum(int a){ a += 100000; ll ret = 0; for (int x = a; x > 0; x -= x & -x)ret += bit[x]; return ret; } }; BIT r, l; int main() { int n , q; cin >> n >> q; r.init(), l.init(); rep(t, q){ char x; int y,z; cin >> x >> y >> z; if (x == 'L'){ l.add(y+1+t,z); }else if (x == 'R'){ r.add(y+1-t,z); } if(x == 'C'){ ll sum = r.sum(z-t)-r.sum(y-t)+l.sum(z+t)-l.sum(y+t); if (z == n)sum += l.sum(n+1+t)-l.sum(n+t); if (y+1== 1)sum += r.sum(0-t); cout << sum << endl; } ll ls = l.sum(1 + t); ll rs = r.sum(n - t) - r.sum(n - t - 1); l.add(1 + t, -ls); r.add(n - t, -rs); l.add(n + t + 1, rs); r.add(1 - t - 1, ls); /* for (int i = 1; i < n + 1; i++){ z = i; y = i - 1; int sum = r.sum(z - t) - r.sum(y - t) + l.sum(z + t) - l.sum(y + t); if (z == n)sum += l.sum(n + 1 + t) - l.sum(n + t); if (y == 0)sum += r.sum(0 - t); cout << i - 1 << " " << sum << endl; } */ } return 0; }