static void Main() { var n = int.Parse(Console.ReadLine()); var qs = Array.ConvertAll(new bool[n], _ => Console.ReadLine().Split()); var keys = qs.Select(q => q[1]).Concat(qs.Where(q => q[0] == "3").Select(q => q[2])).Distinct().ToArray(); Array.Sort(keys, StringComparer.Ordinal); var keymap = Enumerable.Range(0, keys.Length).ToDictionary(i => keys[i], i => i); var map = new AvlMap <int, string>(); Console.SetOut(new System.IO.StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }); foreach (var q in qs) { var key = keymap[q[1]]; if (q[0] == "0") { map[key] = q[2]; } else if (q[0] == "1") { Console.WriteLine(map.GetValueOrDefault(key, "0")); } else if (q[0] == "2") { map.Remove(key); } else { foreach (var p in map.GetItems(x => x >= key, x => x <= keymap[q[2]])) { Console.WriteLine($"{keys[p.Key]} {p.Value}"); } } } Console.Out.Flush(); }
static void Main() { var n = int.Parse(Console.ReadLine()); var c = StringComparer.Ordinal; var map = new AvlMap <string, string>(c.Compare); Console.SetOut(new System.IO.StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }); while (n-- > 0) { var q = Console.ReadLine().Split(); if (q[0] == "0") { map[q[1]] = q[2]; } else if (q[0] == "1") { Console.WriteLine(map.GetValueOrDefault(q[1], "0")); } else if (q[0] == "2") { map.Remove(q[1]); } else { foreach (var p in map.GetItems(x => c.Compare(x, q[1]) >= 0, x => c.Compare(x, q[2]) <= 0)) { Console.WriteLine($"{p.Key} {p.Value}"); } } } Console.Out.Flush(); }