using System; using System.Collections.Generic; using System.Text; using System.Linq; class Program { public void Proc() { Reader.IsDebug = false; int[] inpt = Reader.GetInt(); int areaLength = inpt[0]; int queryCount = inpt[1]; Dictionary leftDic = new Dictionary(); Dictionary rightDic = new Dictionary(); for(int i=0; i subL = new Dictionary(); Dictionary subR = new Dictionary(); List keys = new List(leftDic.Keys); keys.ForEach((a)=>{ if(a == 0) { subR.Add(0, leftDic[a]); } else { subL.Add(a-1, leftDic[a]); } }); keys = new List(rightDic.Keys); keys.ForEach((a)=>{ if(a == areaLength - 1) { if(subL.ContainsKey(a)) { subL[a]+=rightDic[a]; } else { subL.Add(a, rightDic[a]); } } else if(subR.ContainsKey(a+1)) { subR[a+1] += rightDic[a]; } else { subR.Add(a+1, rightDic[a]); } }); string[] tmp = Reader.ReadLine().Split(' '); int num1 = int.Parse(tmp[1]); int num2 = int.Parse(tmp[2]); if(tmp[0].Equals("R")) { if(subR.ContainsKey(num1)) { subR[num1] += num2; } else { subR.Add(num1, num2); } } else if(tmp[0].Equals("L")) { if(subL.ContainsKey(num1)) { subL[num1] += num2; } else { subL.Add(num1, num2); } } rightDic = subR; leftDic = subL; if(tmp[0].Equals("C")) { HashSet hs = new HashSet(rightDic.Keys); hs = new HashSet(hs.Concat(leftDic.Keys)); long ans = 0; hs.Where(a=> a>=num1 && a < num2).ToList().ForEach((b)=>{ if(rightDic.ContainsKey(b)) { ans += rightDic[b]; } if(leftDic.ContainsKey(b)) { ans += leftDic[b]; } }); Console.WriteLine(ans); } } } public class Reader { public static bool IsDebug = true; private static String PlainInput = @" "; private static System.IO.StringReader Sr = null; public static string ReadLine() { if (IsDebug) { if (Sr == null) { Sr = new System.IO.StringReader(PlainInput.Trim()); } return Sr.ReadLine(); } else { return Console.ReadLine(); } } public static int[] GetInt(char delimiter = ' ', bool trim = false) { string inptStr = ReadLine(); if (trim) { inptStr = inptStr.Trim(); } string[] inpt = inptStr.Split(delimiter); int[] ret = new int[inpt.Length]; for (int i = 0; i < inpt.Length; i++) { ret[i] = int.Parse(inpt[i]); } return ret; } } static void Main() { Program prg = new Program(); prg.Proc(); } }