Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create Segtree<T> from Span #113

Merged
merged 2 commits into from
Dec 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [3.8.0] - 2023-12-03
### Added
- Create `Segtree<T>` from Span

## [3.7.0] - 2023-11-29
### Added
- Add PriorityQueue.TryPeek(out T)
Expand Down
4 changes: 2 additions & 2 deletions Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
<RepositoryUrl>https://github.com/kzrnm/ac-library-csharp</RepositoryUrl>
<PackageReleaseNotes>https://github.com/kzrnm/ac-library-csharp/blob/main/CHANGELOG.md</PackageReleaseNotes>

<Version>3.7.0</Version>
<AssemblyVersion>3.7.0.101</AssemblyVersion>
<Version>3.8.0</Version>
<AssemblyVersion>3.8.0.101</AssemblyVersion>
<RepositoryCommit Condition="'$(GIT_COMMIT)' != ''">$(GIT_COMMIT)</RepositoryCommit>

<SignAssembly>True</SignAssembly>
Expand Down
24 changes: 22 additions & 2 deletions Source/ac-library-csharp/DataStructure/LazySegtree.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,29 @@ public LazySegtree(int n)
/// <para>計算量: O(<paramref name="n"/>)</para>
/// </remarks>
/// <param name="v">初期配列</param>
public LazySegtree(TValue[] v) : this(v.Length)
public LazySegtree(TValue[] v) : this((ReadOnlySpan<TValue>)v) { }

/// <summary>
/// 長さ n=<paramref name="v"/>.Length の数列 a を持つ <see cref="LazySegtree{TValue, F, TOp}"/> クラスの新しいインスタンスを作ります。初期値は <paramref name="v"/> です。
/// </summary>
/// <remarks>
/// <para>制約: 0≤<paramref name="n"/>≤10^8</para>
/// <para>計算量: O(<paramref name="n"/>)</para>
/// </remarks>
/// <param name="v">初期配列</param>
public LazySegtree(Span<TValue> v) : this((ReadOnlySpan<TValue>)v) { }

/// <summary>
/// 長さ n=<paramref name="v"/>.Length の数列 a を持つ <see cref="LazySegtree{TValue, F, TOp}"/> クラスの新しいインスタンスを作ります。初期値は <paramref name="v"/> です。
/// </summary>
/// <remarks>
/// <para>制約: 0≤<paramref name="n"/>≤10^8</para>
/// <para>計算量: O(<paramref name="n"/>)</para>
/// </remarks>
/// <param name="v">初期配列</param>
public LazySegtree(ReadOnlySpan<TValue> v) : this(v.Length)
{
for (int i = 0; i < v.Length; i++) d[size + i] = v[i];
v.CopyTo(d.AsSpan(size));
for (int i = size - 1; i >= 1; i--)
{
Update(i);
Expand Down
22 changes: 20 additions & 2 deletions Source/ac-library-csharp/DataStructure/Segtree.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,27 @@ public Segtree(int n)
/// <para>計算量: O(<paramref name="n"/>)</para>
/// </remarks>
/// <param name="v">初期配列</param>
public Segtree(TValue[] v) : this(v.Length)
public Segtree(TValue[] v) : this((ReadOnlySpan<TValue>)v) { }
/// <summary>
/// 長さ n=<paramref name="v"/>.Length の数列 a を持つ <see cref="Segtree{TValue, TOp}"/> クラスの新しいインスタンスを作ります。初期値は <paramref name="v"/> です。
/// </summary>
/// <remarks>
/// <para>制約: 0≤<paramref name="n"/>≤10^8</para>
/// <para>計算量: O(<paramref name="n"/>)</para>
/// </remarks>
/// <param name="v">初期配列</param>
public Segtree(Span<TValue> v) : this((ReadOnlySpan<TValue>)v) { }
/// <summary>
/// 長さ n=<paramref name="v"/>.Length の数列 a を持つ <see cref="Segtree{TValue, TOp}"/> クラスの新しいインスタンスを作ります。初期値は <paramref name="v"/> です。
/// </summary>
/// <remarks>
/// <para>制約: 0≤<paramref name="n"/>≤10^8</para>
/// <para>計算量: O(<paramref name="n"/>)</para>
/// </remarks>
/// <param name="v">初期配列</param>
public Segtree(ReadOnlySpan<TValue> v) : this(v.Length)
{
for (int i = 0; i < v.Length; i++) d[size + i] = v[i];
v.CopyTo(d.AsSpan(size));
for (int i = size - 1; i >= 1; i--)
{
Update(i);
Expand Down
Loading