Example #1
0
        public static void Solve()
        {
            var N   = Scanner.Scan <int>();
            var S   = Scanner.Scan <string>().Select(x => 1 << (x - 'a')).ToArray();
            var Q   = Scanner.Scan <int>();
            var seg = new SegTree <int>(S, (x, y) => x | y, 0);

            for (var q = 0; q < Q; q++)
            {
                var query = Scanner.ScanEnumerable <string>().ToArray();
                if (query[0] == "1")
                {
                    var(i, c) = (int.Parse(query[1]) - 1, query[2][0] - 'a');
                    seg.Set(i, 1 << c);
                }
                else
                {
                    var(l, r) = (int.Parse(query[1]) - 1, int.Parse(query[2]));
                    var bit    = seg.Prod(l, r);
                    var answer = 0;
                    for (var i = 0; i < 26; i++)
                    {
                        if ((bit >> i & 1) == 1)
                        {
                            answer++;
                        }
                    }
                    Console.WriteLine(answer);
                }
            }
        }
Example #2
0
        public static void Solve()
        {
            var(N, Q) = Scanner.Scan <int, int>();
            var A   = Scanner.ScanEnumerable <int>().ToArray();
            var seg = new SegTree <int>(A, (a, b) => Math.Max(a, b), -1);

            for (var i = 0; i < Q; i++)
            {
                var(T, X, V) = Scanner.Scan <int, int, int>();
                X--;
                if (T == 1)
                {
                    seg.Set(X, V);
                }
                else if (T == 2)
                {
                    Console.WriteLine(seg.Prod(X, V));
                }
                else if (T == 3)
                {
                    Console.WriteLine(seg.MaxRight(X, v => v < V) + 1);
                }
            }
        }