結果

問題 No.1703 Much Matching
ユーザー 👑 kakel-sankakel-san
提出日時 2023-12-30 19:56:56
言語 C#
(.NET 8.0.203)
結果
WA  
実行時間 -
コード長 4,032 bytes
コンパイル時間 12,687 ms
コンパイル使用メモリ 157,560 KB
実行使用メモリ 180,388 KB
最終ジャッジ日時 2023-12-30 19:57:21
合計ジャッジ時間 23,426 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 77 ms
32,676 KB
testcase_01 AC 76 ms
32,676 KB
testcase_02 AC 77 ms
32,676 KB
testcase_03 AC 79 ms
33,060 KB
testcase_04 WA -
testcase_05 AC 79 ms
33,316 KB
testcase_06 WA -
testcase_07 AC 89 ms
36,132 KB
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 AC 261 ms
61,432 KB
testcase_18 WA -
testcase_19 AC 485 ms
72,416 KB
testcase_20 WA -
testcase_21 AC 549 ms
75,488 KB
testcase_22 WA -
testcase_23 AC 210 ms
61,104 KB
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 AC 313 ms
65,068 KB
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 AC 1,049 ms
93,916 KB
testcase_37 AC 83 ms
180,388 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
  復元対象のプロジェクトを決定しています...
  /home/judge/data/code/main.csproj を復元しました (109 ms)。
MSBuild のバージョン 17.7.3+8ec440e68 (.NET)
  main -> /home/judge/data/code/bin/Release/net7.0/main.dll
  main -> /home/judge/data/code/bin/Release/net7.0/publish/

ソースコード

diff #

using System;
using static System.Console;
using System.Linq;
using System.Collections.Generic;

class Program
{
    static int NN => int.Parse(ReadLine());
    static int[] NList => ReadLine().Split().Select(int.Parse).ToArray();
    static int[][] NArr(long n) => Enumerable.Repeat(0, (int)n).Select(_ => NList).ToArray();
    public static void Main()
    {
        Solve();
    }
    static void Solve()
    {
        var c = NList;
        var (n, m, q) = (c[0], c[1], c[2]);
        var map = NArr(q);
        var ex = new bool[n, m];
        foreach (var pair in map) ex[pair[0] - 1, pair[1] - 1] = true;
        var seg = new SegmentTree<int>(m, new SegOp());
        for (var i = 0; i < n; ++i) for (var j = 0; j < m; ++j) if (ex[i, j])
        {
            if (j == 0) seg[j] = 1;
            else seg[j] = seg.Prod(0, j) + 1;
        }
        WriteLine(seg.Prod(0, m));
    }
    struct SegOp : ISegmentTreeOperator<int>
    {
        public int Identity => 0;
        public int Operate(int x, int y)
        {
            return Math.Max(x, y);
        }
    }
    interface ISegmentTreeOperator<T>
    {
        T Identity { get; }
        T Operate(T x, T y);
    }
    class SegmentTree<T>
    {
        int size;
        int log;
        T[] d;
        ISegmentTreeOperator<T> op;
        void Update(int k)
        {
            d[k] = op.Operate(d[2 * k], d[2 * k + 1]);
        }
        public SegmentTree(int n, ISegmentTreeOperator<T> op)
        {
            this.op = op;
            size = 1;
            while (size < n) size <<= 1;
            log = CountRZero(size);
            d = new T[2 * size];
            for (var i = 0; i < d.Length; ++i) d[i] = op.Identity;
        }
        public SegmentTree(T[] v, ISegmentTreeOperator<T> op)
        {
            this.op = op;
            size = 1;
            while (size < v.Length) size <<= 1;
            log = CountRZero(size);
            d = new T[2 * size];
            for (var i = 0; i < size; ++i) d[i] = op.Identity;
            for (var i = 0; i < v.Length; ++i) d[size + i] = v[i];
            for (var i = size - 1; i >= 1; --i) Update(i);
        }
        int CountRZero(int n)
        {
            var ans = 0;
            while (n % 2 == 0)
            {
                ++ans;
                n >>= 1;
            }
            return ans;
        }
        public T this[int p]
        {
            get { return d[p + size]; }
            set
            {
                p += size;
                d[p] = value;
                for (var i = 1; i <= log; ++i) Update(p >> i);
            }
        }
        public T Prod(int l, int r)
        {
            var sml = op.Identity;
            var smr = op.Identity;
            l += size;
            r += size;
            while (l < r)
            {
                if ((l & 1) != 0) sml = op.Operate(sml, d[l++]);
                if ((r & 1) != 0) smr = op.Operate(d[--r], smr);
                l >>= 1;
                r >>= 1;
            }
            return op.Operate(sml, smr);
        }
        T AllProd() => d[1];
        int MinLeft(int r, Predicate<T> f)
        {
            if (r == 0) return 0;
            r += size;
            T sm = op.Identity;
            do
            {
                r--;
                while (r > 1 && (r % 2) != 0) r >>= 1;
                if (!f(op.Operate(d[r], sm)))
                {
                    while (r < size)
                    {
                        r = 2 * r + 1;
                        if (f(op.Operate(d[r], sm)))
                        {
                            sm = op.Operate(d[r], sm);
                            r--;
                        }
                    }
                    return r + 1 - size;
                }
                sm = op.Operate(d[r], sm);
            }
            while ((r & -r) != r);
            return 0;
        }
    }
}
0