結果

問題 No.2520 L1 Explosion
ユーザー 👑 kakel-sankakel-san
提出日時 2023-10-31 00:10:50
言語 C#
(.NET 8.0.203)
結果
WA  
実行時間 -
コード長 4,299 bytes
コンパイル時間 8,162 ms
コンパイル使用メモリ 155,952 KB
実行使用メモリ 180,804 KB
最終ジャッジ日時 2023-10-31 00:11:21
合計ジャッジ時間 20,349 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 98 ms
33,560 KB
testcase_01 AC 100 ms
33,568 KB
testcase_02 AC 99 ms
33,560 KB
testcase_03 AC 96 ms
33,560 KB
testcase_04 WA -
testcase_05 RE -
testcase_06 AC 692 ms
35,748 KB
testcase_07 AC 254 ms
35,432 KB
testcase_08 AC 695 ms
35,812 KB
testcase_09 AC 693 ms
35,780 KB
testcase_10 AC 694 ms
35,892 KB
testcase_11 AC 723 ms
35,884 KB
testcase_12 AC 698 ms
35,900 KB
testcase_13 AC 726 ms
35,824 KB
testcase_14 AC 700 ms
35,832 KB
testcase_15 AC 126 ms
34,556 KB
testcase_16 AC 526 ms
35,692 KB
testcase_17 AC 376 ms
35,448 KB
testcase_18 AC 390 ms
35,528 KB
testcase_19 AC 329 ms
35,120 KB
testcase_20 AC 113 ms
34,404 KB
testcase_21 AC 496 ms
35,688 KB
testcase_22 AC 147 ms
34,668 KB
testcase_23 AC 129 ms
34,580 KB
testcase_24 AC 437 ms
180,804 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
  復元対象のプロジェクトを決定しています...
  /home/judge/data/code/main.csproj を復元しました (105 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) = (c[0], c[1]);
        var map = NArr(n);
        var conv = new long[n][];
        for (var i = 0; i < n; ++i) conv[i] = new long[] {
            (long)map[i][0] - map[i][1] - m + map[i][2],
            (long)map[i][0] + map[i][1] - m + map[i][2],
            (long)map[i][0] - map[i][1] + m - map[i][2],
            (long)map[i][0] + map[i][1] + m - map[i][2]
        };
        var xset = new HashSet<long>();
        var yset = new HashSet<long>();
        for (var i = 0; i < n; ++i)
        {
            xset.Add(conv[i][0]);
            yset.Add(conv[i][1]);
            xset.Add(conv[i][2]);
            yset.Add(conv[i][3]);
        }
        var xlist = new List<long>(xset);
        xlist.Sort();
        var ylist = new List<long>(yset);
        ylist.Sort();
        var xdic = new Dictionary<long, int>();
        for (var i = 0; i < xlist.Count; ++i) xdic[xlist[i]] = i;
        var ydic = new Dictionary<long, int>();
        for (var i = 0; i < ylist.Count; ++i) ydic[ylist[i]] = i;
        var inlist = new List<(long id, int yc)>();
        var outlist = new List<(long id, int yc)>();
        for (var i = 0; i < n; ++i)
        {
            inlist.Add((i, ydic[conv[i][1]]));
            outlist.Add((i, ydic[conv[i][3]]));
        }
        inlist.Sort((l, r) => l.yc.CompareTo(r.yc));
        outlist.Sort((l, r) => l.yc.CompareTo(r.yc));
        var ipos = 0;
        var opos = 0;

        var mod = 998_244_353;
        var rev2 = 499_122_177;
        var ans = new long[n + 1];
        var ft = new FenwickTree(xlist.Count + 1);
        for (var yc = 0; yc < ylist.Count; ++yc)
        {
            if (ipos < inlist.Count && inlist[ipos].yc == yc)
            {
                ft.Add(xdic[conv[inlist[ipos].id][0]], 1);
                ft.Add(xdic[conv[inlist[ipos].id][2]], -1);
                ++ipos;
            }
            if (opos < outlist.Count && outlist[opos].yc == yc)
            {
                ft.Add(xdic[conv[outlist[opos].id][0]], -1);
                ft.Add(xdic[conv[outlist[opos].id][2]], 1);
                ++opos;
            }
            if (yc + 1 == ylist.Count) continue;
            for (var xc = 0; xc + 1 < xlist.Count; ++xc)
            {
                var cnt = ft.Sum(xc);
                ans[cnt] = (ans[cnt] + (xlist[xc + 1] - xlist[xc]) % mod * ((ylist[yc + 1] - ylist[yc]) % mod)) % mod;
            }
        }
        WriteLine(string.Join("\n", ans.Skip(1).Select(ai => ai * rev2 % mod)));
    }
    class FenwickTree
    {
        int size;
        long[] tree;
        public FenwickTree(int size)
        {
            this.size = size;
            tree = new long[size + 2];
        }
        public void Add(int index, int value)
        {
            ++index;
            for (var x = index; x <= size; x += (x & -x)) tree[x] += value;
        }
        /// <summary>先頭からindexまでの和(include index)</summary>
        public long Sum(int index)
        {
            if (index < 0) return 0;
            ++index;
            var sum = 0L;
            for (var x = index; x > 0; x -= (x & -x)) sum += tree[x];
            return sum;
        }
        /// <summary>Sum(x) >= value となる最小のxを求める</summary>
        // 各要素は非負であること
        public int LowerBound(long value)
        {
            if (value < 0) return -1;
            var x = 0;
            var b = 1;
            while (b * 2 <= size) b <<= 1;
            for (var k = b; k > 0; k >>= 1)
            {
                if (x + k <= size && tree[x + k] < value)
                {
                    value -= tree[x + k];
                    x += k;
                }
            }
            return x;
        }
    }
}
0