結果
| 問題 |
No.2520 L1 Explosion
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2023-10-31 00:10:50 |
| 言語 | C# (.NET 8.0.404) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 4,299 bytes |
| コンパイル時間 | 8,035 ms |
| コンパイル使用メモリ | 166,812 KB |
| 実行使用メモリ | 187,932 KB |
| 最終ジャッジ日時 | 2024-09-25 17:26:11 |
| 合計ジャッジ時間 | 15,772 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 20 WA * 1 RE * 1 |
コンパイルメッセージ
復元対象のプロジェクトを決定しています... /home/judge/data/code/main.csproj を復元しました (94 ms)。 MSBuild のバージョン 17.9.6+a4ecab324 (.NET) main -> /home/judge/data/code/bin/Release/net8.0/main.dll main -> /home/judge/data/code/bin/Release/net8.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();
}
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;
}
}
}