示例#1
0
        // verification-helper: PROBLEM https://judge.yosupo.jp/problem/bipartitematching
        static void Solve(ConsoleReader cr, Utf8ConsoleWriter cw)
        {
            int l  = cr;
            int r  = cr;
            int m  = cr;
            var mf = new MfGraphInt(l + r + 2);

            for (int i = 0; i < m; i++)
            {
                int a = cr;
                int b = cr;
                mf.AddEdge(a, l + b, 1);
            }
            for (int i = 0; i < l; i++)
            {
                mf.AddEdge(l + r, i, 1);
            }
            for (int i = 0; i < r; i++)
            {
                mf.AddEdge(l + i, l + r + 1, 1);
            }
            cw.WriteLine(mf.Flow(l + r, l + r + 1));
            foreach (var e in mf.Edges())
            {
                int ll = e.From;
                int rr = e.To;
                if (e.Flow == 1 && ll < l && rr < l + r)
                {
                    cw.WriteLineJoin(e.From, e.To - l);
                }
            }
        }
示例#2
0
        // verification-helper: PROBLEM https://judge.yosupo.jp/problem/sum_of_floor_of_linear
        static void Solve(ConsoleReader cr, Utf8ConsoleWriter cw)
        {
            int T = cr;

            for (int i = 0; i < T; i++)
            {
                cw.WriteLine(MathLib.FloorSum(cr, cr, cr, cr));
            }
        }
        // verification-helper: PROBLEM https://judge.yosupo.jp/problem/convolution_mod
        static void Solve(ConsoleReader cr, Utf8ConsoleWriter cw)
        {
            int n = cr;
            int m = cr;

            int[] a = cr.Repeat(n);
            int[] b = cr.Repeat(m);
            cw.WriteLineJoin(MathLib.Convolution <Mod998244353>(a, b));
        }
示例#4
0
        // verification-helper: PROBLEM https://judge.yosupo.jp/problem/number_of_substrings
        static void Solve(ConsoleReader cr, Utf8ConsoleWriter cw)
        {
            string s      = cr;
            var    sa     = StringLib.SuffixArray(s);
            var    answer = 1L * s.Length * (s.Length + 1) / 2;

            foreach (var x in StringLib.LCPArray(s, sa))
            {
                answer -= x;
            }
            cw.WriteLine(answer);
        }
示例#5
0
        // verification-helper: PROBLEM https://judge.yosupo.jp/problem/two_sat
        static void Solve(ConsoleReader cr, Utf8ConsoleWriter cw)
        {
            _ = cr.Ascii();
            _ = cr.Ascii();
            int n      = cr;
            int m      = cr;
            var twoSat = new TwoSat(n);

            for (int i = 0; i < m; i++)
            {
                int a = cr;
                int b = cr;
                _ = cr.Int();

                int  a1 = Math.Abs(a) - 1;
                bool a2 = a >= 0;
                int  b1 = Math.Abs(b) - 1;
                bool b2 = b >= 0;
                twoSat.AddClause(a1, a2, b1, b2);
            }
            if (twoSat.Satisfiable())
            {
                cw.WriteLine("s SATISFIABLE");
                cw.Write("v ");
                var res    = new int[n + 1];
                var answer = twoSat.Answer();
                for (int i = 0; i < n; i++)
                {
                    if (answer[i])
                    {
                        res[i] = i + 1;
                    }
                    else
                    {
                        res[i] = -(i + 1);
                    }
                }
                cw.WriteLineJoin(res);
            }
            else
            {
                cw.WriteLine("s UNSATISFIABLE");
            }
        }
        // verification-helper: PROBLEM https://judge.yosupo.jp/problem/range_affine_range_sum
        static void Solve(ConsoleReader cr, Utf8ConsoleWriter cw)
        {
            int N   = cr;
            int Q   = cr;
            var seg = new LazySegtree <(uint v, uint len), (uint b, uint c), LazySegtreeSolverOp>(cr.Repeat(N).Select(cr => ((uint)cr.Int(), 1U)));

            for (int q = 0; q < Q; q++)
            {
                int t = cr;
                int l = cr;
                int r = cr;
                if (t == 0)
                {
                    uint b = (uint)cr.Int();
                    uint c = (uint)cr.Int();
                    seg.Apply(l, r, (b, c));
                }
                else
                {
                    cw.WriteLine(seg[l..r].v);
示例#7
0
        // verification-helper: PROBLEM https://judge.yosupo.jp/problem/unionfind
        static void Solve(ConsoleReader cr, Utf8ConsoleWriter cw)
        {
            int n = cr;
            int q = cr;

            var dsu = new DSU(n);

            for (int i = 0; i < q; i++)
            {
                int t = cr;
                int u = cr;
                int v = cr;
                if (t == 0)
                {
                    dsu.Merge(u, v);
                }
                else
                {
                    cw.WriteLine(dsu.Same(u, v) ? 1 : 0);
                }
            }
        }
示例#8
0
        // verification-helper: PROBLEM https://judge.yosupo.jp/problem/point_add_range_sum
        static void Solve(ConsoleReader cr, Utf8ConsoleWriter cw)
        {
            int N = cr;
            int Q = cr;

            int[] a  = cr.Repeat(N);
            var   fw = new LongFenwickTree(N);

            for (int i = 0; i < a.Length; i++)
            {
                fw.Add(i, a[i]);
            }
            for (int i = 0; i < Q; i++)
            {
                int t = cr;
                int l = cr;
                int r = cr;
                if (t == 0)
                {
                    fw.Add(l, r);
                }
                else
                {
                    cw.WriteLine(fw[l..r]);
示例#9
0
        // verification-helper: PROBLEM https://judge.yosupo.jp/problem/scc
        static void Solve(ConsoleReader cr, Utf8ConsoleWriter cw)
        {
            int n = cr;
            int m = cr;

            var g = new SccGraph(n);

            for (int i = 0; i < m; i++)
            {
                int u = cr;
                int v = cr;
                g.AddEdge(u, v);
            }

            var scc = g.SCC();

            cw.WriteLine(scc.Length);
            foreach (var v in scc)
            {
                cw.Write(v.Length);
                cw.Write(' ');
                cw.WriteLineJoin(v);
            }
        }
示例#10
0
        // verification-helper: PROBLEM https://judge.yosupo.jp/problem/point_set_range_composite
        static void Solve(ConsoleReader cr, Utf8ConsoleWriter cw)
        {
            int n = cr;
            int q = cr;

            var seg = new Segtree <(StaticModInt <Mod998244353> a, StaticModInt <Mod998244353> b), SegtreeSolverOp>(
                cr.Repeat(n).Select(cr => (StaticModInt <Mod998244353> .Raw(cr), StaticModInt <Mod998244353> .Raw(cr))));

            for (int i = 0; i < q; i++)
            {
                int t = cr;
                if (t == 0)
                {
                    int p = cr;
                    int c = cr;
                    int d = cr;
                    seg[p] = (StaticModInt <Mod998244353> .Raw(c), StaticModInt <Mod998244353> .Raw(d));
                }
                else
                {
                    int l = cr;
                    int r = cr;
                    int x = cr;
                    var(a, b) = seg[l..r];
示例#11
0
 static void Main()
 {
     using var cw = new Utf8ConsoleWriter(); Solve(new ConsoleReader(), cw);
 }
示例#12
0
        // verification-helper: PROBLEM https://judge.yosupo.jp/problem/zalgorithm
        static void Solve(ConsoleReader cr, Utf8ConsoleWriter cw)
        {
            string s = cr;

            cw.WriteLineJoin(StringLib.ZAlgorithm(s));
        }
示例#13
0
        // verification-helper: PROBLEM https://judge.yosupo.jp/problem/suffixarray
        static void Solve(ConsoleReader cr, Utf8ConsoleWriter cw)
        {
            string s = cr;

            cw.WriteLineJoin(StringLib.SuffixArray(s));
        }