From c70afeec97e702effa7f617b5897754d1548ad01 Mon Sep 17 00:00:00 2001 From: kzrnm Date: Sun, 3 Dec 2023 20:27:12 +0900 Subject: [PATCH 1/2] Create Segtree from Span --- .../DataStructure/LazySegtree.cs | 24 +++++++++++++++++-- .../DataStructure/Segtree.cs | 22 +++++++++++++++-- 2 files changed, 42 insertions(+), 4 deletions(-) diff --git a/Source/ac-library-csharp/DataStructure/LazySegtree.cs b/Source/ac-library-csharp/DataStructure/LazySegtree.cs index 1c5440a..763f440 100644 --- a/Source/ac-library-csharp/DataStructure/LazySegtree.cs +++ b/Source/ac-library-csharp/DataStructure/LazySegtree.cs @@ -64,9 +64,29 @@ public LazySegtree(int n) /// 計算量: O() /// /// 初期配列 - public LazySegtree(TValue[] v) : this(v.Length) + public LazySegtree(TValue[] v) : this((ReadOnlySpan)v) { } + + /// + /// 長さ n=.Length の数列 a を持つ クラスの新しいインスタンスを作ります。初期値は です。 + /// + /// + /// 制約: 0≤≤10^8 + /// 計算量: O() + /// + /// 初期配列 + public LazySegtree(Span v) : this((ReadOnlySpan)v) { } + + /// + /// 長さ n=.Length の数列 a を持つ クラスの新しいインスタンスを作ります。初期値は です。 + /// + /// + /// 制約: 0≤≤10^8 + /// 計算量: O() + /// + /// 初期配列 + public LazySegtree(ReadOnlySpan 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); diff --git a/Source/ac-library-csharp/DataStructure/Segtree.cs b/Source/ac-library-csharp/DataStructure/Segtree.cs index 1063cf0..bac6710 100644 --- a/Source/ac-library-csharp/DataStructure/Segtree.cs +++ b/Source/ac-library-csharp/DataStructure/Segtree.cs @@ -61,9 +61,27 @@ public Segtree(int n) /// 計算量: O() /// /// 初期配列 - public Segtree(TValue[] v) : this(v.Length) + public Segtree(TValue[] v) : this((ReadOnlySpan)v) { } + /// + /// 長さ n=.Length の数列 a を持つ クラスの新しいインスタンスを作ります。初期値は です。 + /// + /// + /// 制約: 0≤≤10^8 + /// 計算量: O() + /// + /// 初期配列 + public Segtree(Span v) : this((ReadOnlySpan)v) { } + /// + /// 長さ n=.Length の数列 a を持つ クラスの新しいインスタンスを作ります。初期値は です。 + /// + /// + /// 制約: 0≤≤10^8 + /// 計算量: O() + /// + /// 初期配列 + public Segtree(ReadOnlySpan 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); From bb73844851d80aeca05cdaf68e555a4030f620b9 Mon Sep 17 00:00:00 2001 From: kzrnm Date: Sun, 3 Dec 2023 20:27:51 +0900 Subject: [PATCH 2/2] v3.8.0 --- CHANGELOG.md | 4 ++++ Directory.Build.props | 4 ++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f3caaa3..e8ed9d1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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` from Span + ## [3.7.0] - 2023-11-29 ### Added - Add PriorityQueue.TryPeek(out T) diff --git a/Directory.Build.props b/Directory.Build.props index 478e189..d1ea572 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -7,8 +7,8 @@ https://github.com/kzrnm/ac-library-csharp https://github.com/kzrnm/ac-library-csharp/blob/main/CHANGELOG.md - 3.7.0 - 3.7.0.101 + 3.8.0 + 3.8.0.101 $(GIT_COMMIT) True