結果
問題 | No.2520 L1 Explosion |
ユーザー |
👑 |
提出日時 | 2023-10-31 00:33:46 |
言語 | C# (.NET 8.0.203) |
結果 |
AC
|
実行時間 | 712 ms / 2,000 ms |
コード長 | 5,028 bytes |
コンパイル時間 | 8,095 ms |
コンパイル使用メモリ | 155,044 KB |
実行使用メモリ | 180,052 KB |
最終ジャッジ日時 | 2023-10-31 00:34:05 |
合計ジャッジ時間 | 18,149 ms |
ジャッジサーバーID (参考情報) |
judge11 / judge12 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 99 ms
33,448 KB |
testcase_01 | AC | 101 ms
33,468 KB |
testcase_02 | AC | 100 ms
33,460 KB |
testcase_03 | AC | 97 ms
33,448 KB |
testcase_04 | AC | 99 ms
33,468 KB |
testcase_05 | AC | 100 ms
33,468 KB |
testcase_06 | AC | 696 ms
35,840 KB |
testcase_07 | AC | 253 ms
35,528 KB |
testcase_08 | AC | 694 ms
35,872 KB |
testcase_09 | AC | 689 ms
35,852 KB |
testcase_10 | AC | 702 ms
35,964 KB |
testcase_11 | AC | 693 ms
35,968 KB |
testcase_12 | AC | 698 ms
35,964 KB |
testcase_13 | AC | 712 ms
35,900 KB |
testcase_14 | AC | 694 ms
35,908 KB |
testcase_15 | AC | 125 ms
34,664 KB |
testcase_16 | AC | 531 ms
35,768 KB |
testcase_17 | AC | 371 ms
35,532 KB |
testcase_18 | AC | 381 ms
35,612 KB |
testcase_19 | AC | 333 ms
35,204 KB |
testcase_20 | AC | 111 ms
34,524 KB |
testcase_21 | AC | 491 ms
35,768 KB |
testcase_22 | AC | 148 ms
34,740 KB |
testcase_23 | AC | 131 ms
34,688 KB |
testcase_24 | AC | 446 ms
180,052 KB |
コンパイルメッセージ
復元対象のプロジェクトを決定しています... /home/judge/data/code/main.csproj を復元しました (101 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/
ソースコード
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(); // Test(); } static void Test() { var r = new Random(); var count = 0; var max = 10; while (true) { var n = 2; var m = r.Next(max) + 2; var map = new int[n][]; for (var i = 0; i < n; ++i) map[i] = new int[] { r.Next(-max, max), r.Next(-max, max), r.Next(1, m) }; WriteLine($"{n} {m}"); WriteLine(string.Join("\n", map.Select(mi => string.Join(" ", mi)))); var s = Exp(n, m, map); ++count; if (count % 1000 == 0) WriteLine(count); } } static void Solve() { var c = NList; var (n, m) = (c[0], c[1]); var map = NArr(n); WriteLine(Exp(n, m, map)); } static string Exp(int n, int m, int[][] map) { 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) { while (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; } while (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; } } return 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; } } }