diff --git a/.verify-helper/timestamps.remote.json b/.verify-helper/timestamps.remote.json index 44e525a..b391790 100644 --- a/.verify-helper/timestamps.remote.json +++ b/.verify-helper/timestamps.remote.json @@ -8,9 +8,9 @@ "test/aoj-cgl-3-c.test.cpp": "2023-09-07 23:01:33 +0900", "test/aoj-cgl-4-a.test.cpp": "2023-09-07 23:01:33 +0900", "test/aoj-cgl-5-a.test.cpp": "2023-09-07 23:01:33 +0900", -"test/aoj-dsl-2-a.test.cpp": "2023-08-01 18:34:30 +0900", +"test/aoj-dsl-2-a.test.cpp": "2024-03-06 15:05:55 +0900", "test/aoj-dsl-2-a.test.py": "2023-09-07 14:26:13 +0900", -"test/aoj-dsl-2-b.test.cpp": "2023-08-01 18:34:30 +0900", +"test/aoj-dsl-2-b.test.cpp": "2024-03-06 15:05:55 +0900", "test/aoj-dsl-2-b.test.py": "2023-09-07 14:26:13 +0900", "test/aoj-dsl-2-f.test.cpp": "2023-08-01 17:59:54 +0900", "test/aoj-dsl-2-g.test.cpp": "2023-08-01 17:59:54 +0900", @@ -20,11 +20,13 @@ "test/aoj-grl-5-b.test.cpp": "2023-06-16 15:41:49 +0900", "test/atcoder-abc177-f.1.test.cpp": "2023-08-01 17:59:54 +0900", "test/atcoder-abc177-f.2.test.cpp": "2023-08-01 17:59:54 +0900", +"test/atcoder-abc185-f.test.cpp": "2024-03-06 15:05:55 +0900", +"test/atcoder-abc254-f.test.cpp": "2024-03-06 15:05:55 +0900", "test/atcoder-abc282-d.test.cpp": "2023-11-30 23:29:28 +0900", "test/atcoder-abc300-b.test.cpp": "2023-10-12 08:50:40 +0900", "test/atcoder-abc331-f.test.cpp": "2024-02-12 01:35:20 +0900", "test/atcoder-edpc-g.test.cpp": "2023-11-30 23:29:28 +0900", -"test/atcoder-past202012-n.test.cpp": "2023-08-01 18:34:30 +0900", +"test/atcoder-past202012-n.test.cpp": "2024-03-06 15:05:55 +0900", "test/atcoder-past202012-n.test.py": "2023-09-07 14:26:13 +0900", "test/yosupo-binomial-coefficient.test.cpp": "2023-09-16 00:25:06 +0900", "test/yosupo-convolution-mod-1000000007.test.cpp": "2023-09-16 00:07:15 +0900", @@ -36,14 +38,14 @@ "test/yosupo-exp-of-fps.test.cpp": "2024-01-20 00:58:37 +0900", "test/yosupo-inv-of-fps.test.cpp": "2024-01-20 00:58:37 +0900", "test/yosupo-lca.1.test.cpp": "2023-06-16 15:41:49 +0900", -"test/yosupo-lca.2.test.cpp": "2023-08-01 18:34:30 +0900", +"test/yosupo-lca.2.test.cpp": "2024-03-06 15:05:55 +0900", "test/yosupo-line-add-get-min.test.cpp": "2023-06-19 07:11:52 +0900", "test/yosupo-log-of-fps.test.cpp": "2024-01-20 00:58:37 +0900", "test/yosupo-partition-function_1.test.cpp": "2024-01-20 00:58:37 +0900", "test/yosupo-partition-function_2.test.cpp": "2024-01-20 00:58:37 +0900", "test/yosupo-point-add-rectangle-sum.test.cpp": "2023-06-25 14:14:02 +0900", -"test/yosupo-point-set-range-composite.1.test.cpp": "2023-08-29 23:08:45 +0900", -"test/yosupo-point-set-range-composite.2.test.cpp": "2023-08-29 23:08:45 +0900", +"test/yosupo-point-set-range-composite.1.test.cpp": "2024-03-06 15:05:55 +0900", +"test/yosupo-point-set-range-composite.2.test.cpp": "2024-03-06 15:05:55 +0900", "test/yosupo-point-set-range-composite.test.py": "2023-09-07 14:26:13 +0900", "test/yosupo-polynomial-taylor-shift.test.cpp": "2024-01-20 00:58:37 +0900", "test/yosupo-pow-of-fps.test.cpp": "2024-01-20 00:58:37 +0900", diff --git a/.vscode/settings.json b/.vscode/settings.json deleted file mode 100644 index e268551..0000000 --- a/.vscode/settings.json +++ /dev/null @@ -1,13 +0,0 @@ -{ - "files.associations": { - "array": "cpp", - "deque": "cpp", - "list": "cpp", - "string": "cpp", - "unordered_map": "cpp", - "vector": "cpp", - "string_view": "cpp", - "initializer_list": "cpp", - "valarray": "cpp" - } -} \ No newline at end of file diff --git a/cpp/segtree.hpp b/cpp/segtree.hpp index 406af71..530b153 100644 --- a/cpp/segtree.hpp +++ b/cpp/segtree.hpp @@ -8,6 +8,7 @@ #include #include #include +#include #include #include @@ -299,6 +300,10 @@ namespace segtree { struct Min { const S operator() (const S& a, const S& b) const { return std::min(a, b); } }; + template >* = nullptr> + struct Gcd { + constexpr S operator()(const S& a, const S& b) const { return std::gcd(a, b); } + }; template >* = nullptr> struct MaxLimit { constexpr S operator() () const { return std::numeric_limits::max(); } @@ -311,6 +316,14 @@ namespace segtree { struct Zero { S operator() () const { return S(0); } }; + template + struct One { + S operator()() const { return S(1); } + }; + template + struct None { + S operator()() const { return S{}; } + }; } /** * @brief RangeMaxQuery @@ -332,4 +345,25 @@ using RMinQ = StaticSegTree, segtree::MaxLimit>; * @tparam S 型 */ template -using RSumQ = StaticSegTree, segtree::Zero>; +using RSumQ = StaticSegTree, segtree::None>; +/** + * @brief RangeProdQuery + * + * @tparam S 型 + */ +template +using RProdQ = StaticSegTree, segtree::One>; +/** + * @brief RangeXorQuery + * + * @tparam S 型 + */ +template +using RXorQ = StaticSegTree, segtree::Zero>; +/** + * @brief RangeGcdQuery + * + * @tparam S 型 + */ +template +using RGcdQ = StaticSegTree, segtree::Zero>; diff --git a/test/atcoder-abc185-f.test.cpp b/test/atcoder-abc185-f.test.cpp new file mode 100644 index 0000000..cd132ec --- /dev/null +++ b/test/atcoder-abc185-f.test.cpp @@ -0,0 +1,26 @@ +#define PROBLEM "https://atcoder.jp/contests/abc185/tasks/abc185_f" + +#include + +#include "../cpp/segtree.hpp" + +int main(void) { + int N, Q; + std::cin >> N >> Q; + std::vector A(N); + for (int& a : A) { + std::cin >> a; + } + RXorQ seg(A); + while (Q--) { + int T, X, Y; + std::cin >> T >> X >> Y; + if (T == 1) { + seg.apply(X - 1, Y); + } else { + int ans; + ans = seg.prod(X - 1, Y); + std::cout << ans << std::endl; + } + } +} diff --git a/test/atcoder-abc254-f.test.cpp b/test/atcoder-abc254-f.test.cpp new file mode 100644 index 0000000..4a49b0e --- /dev/null +++ b/test/atcoder-abc254-f.test.cpp @@ -0,0 +1,32 @@ +#define PROBLEM "https://atcoder.jp/contests/abc254/tasks/abc254_f" + +#include + +#include "../cpp/segtree.hpp" + +int main(void) { + int N, Q; + std::cin >> N >> Q; + std::vector A(N), B(N), dA, dB; + for (int& a : A) { + std::cin >> a; + } + for (int& b : B) { + std::cin >> b; + } + dA.reserve(N - 1); + dB.reserve(N - 1); + for (int i = 0; i < N - 1; i++) { + dA.push_back(A[i + 1] - A[i]); + dB.push_back(B[i + 1] - B[i]); + } + RGcdQ seg1(dA), seg2(dB); + while (Q--) { + int h1, h2, w1, w2; + std::cin >> h1 >> h2 >> w1 >> w2; + int g = A[h1 - 1] + B[w1 - 1]; + g = std::gcd(g, seg1.prod(h1 - 1, h2 - 1)); + g = std::gcd(g, seg2.prod(w1 - 1, w2 - 1)); + std::cout << g << std::endl; + } +}