結果
| 問題 |
No.3327 うるせぇ、ポリオミノぶつけんぞ
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2025-11-01 16:08:05 |
| 言語 | C# (.NET 8.0.404) |
| 結果 |
AC
|
| 実行時間 | 531 ms / 3,000 ms |
| コード長 | 3,513 bytes |
| コンパイル時間 | 8,190 ms |
| コンパイル使用メモリ | 169,200 KB |
| 実行使用メモリ | 234,820 KB |
| 最終ジャッジ日時 | 2025-11-01 16:08:26 |
| 合計ジャッジ時間 | 17,946 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 24 |
コンパイルメッセージ
復元対象のプロジェクトを決定しています... /home/judge/data/code/main.csproj を復元しました (110 ミリ秒)。 main -> /home/judge/data/code/bin/Release/net8.0/main.dll main -> /home/judge/data/code/bin/Release/net8.0/publish/
ソースコード
#nullable enable
#region
var (_input, _iter) = (Array.Empty<string>(), 0);
T I<T>() where T : IParsable<T>
{
while (_iter >= _input.Length) (_input, _iter) = (Console.ReadLine()!.Split(' '), 0);
return T.Parse(_input[_iter++], null);
}
#endregion
static T[] Range<T>(int n, Func<T> F) => Enumerable.Range(0, n).Select(_ => F()).ToArray();
var n = I<int>();
var q = I<int>();
var az = Range(n, I<int>);
var qz = Range(q, () => (I<int>(), I<int>()));
var data = SegmentTree.Build(az, new Op());
var ans = new List<int>();
foreach (var (c, x) in qz)
{
if (c == 1)
{
var pass = n;
var fail = -1;
while (Math.Abs(pass - fail) > 1)
{
var mid = (pass + fail) / 2;
if (data.Product(0, mid + 1) > x) pass = mid;
else fail = mid;
}
if (pass >= n) ans.Add(-1);
else
{
ans.Add(pass + 1);
data.Set(pass, -1);
}
}
else
{
var pass = -1;
var fail = n;
while (Math.Abs(pass - fail) > 1)
{
var mid = (pass + fail) / 2;
if (data.Product(mid, n) > x) pass = mid;
else fail = mid;
}
if (pass < 0) ans.Add(-1);
else
{
ans.Add(pass + 1);
data.Set(pass, -1);
}
}
}
Console.WriteLine(string.Join(Environment.NewLine, ans));
readonly struct Op : ISegmentTreeOperator<int>
{
public int IdentityElement => int.MinValue;
public int Operation(int x, int y) => int.Max(x, y);
}
class SegmentTree
{
public static SegmentTree<TMonoid, TOperator> Build<TMonoid, TOperator>(TMonoid[] initial, TOperator op)
where TOperator : struct, ISegmentTreeOperator<TMonoid> => new(initial, op);
}
interface ISegmentTreeOperator<TMonoid>
{
TMonoid IdentityElement { get; }
TMonoid Operation(TMonoid x, TMonoid y);
}
partial class SegmentTree<TMonoid, TOperator> where TOperator : struct, ISegmentTreeOperator<TMonoid>
{
public int BaseSize { get; init; }
protected int Height { get; init; }
protected TOperator Op { get; init; }
protected TMonoid[] Values { get; init; }
public SegmentTree(TMonoid[] initial, TOperator op = default)
{
Op = op;
(BaseSize, Height) = (1, 0);
while (BaseSize < initial.Length) (BaseSize, Height) = (BaseSize << 1, Height + 1);
var size = BaseSize << 1;
Values = new TMonoid[size];
var values = Values;
for (var i = 0; i < size; i++) values[i] = op.IdentityElement;
for (var i = 0; i < initial.Length; i++) values[i + BaseSize] = initial[i];
for (var i = BaseSize - 1; i > 0; i--) Update(values, i);
}
public TMonoid Product(int l, int r)
{
(l, r) = (l + BaseSize, r + BaseSize);
var (resL, resR) = (Op.IdentityElement, Op.IdentityElement);
var values = Values;
while (l < r)
{
if ((l & 1) == 1) resL = Op.Operation(resL, values[l++]);
if ((r & 1) == 1) resR = Op.Operation(values[--r], resR);
(l, r) = (l >> 1, r >> 1);
}
return Op.Operation(resL, resR);
}
public void Set(int index, TMonoid value)
{
var j = index + BaseSize;
var values = Values;
values[j] = value;
for (var i = 1; i <= Height; i++) Update(values, j >> i);
}
protected void Update(TMonoid[] values, int k) { values[k] = Op.Operation(values[k << 1], values[(k << 1) + 1]); }
}