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

seg-improve #103

Merged
merged 14 commits into from
Mar 6, 2024
12 changes: 6 additions & 6 deletions .verify-helper/timestamps.remote.json
Original file line number Diff line number Diff line change
Expand Up @@ -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-02-12 11:32:30 +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-02-12 11:32:30 +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",
Expand All @@ -23,7 +23,7 @@
"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-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-02-12 11:32:30 +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",
Expand All @@ -35,14 +35,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-02-12 11:32:30 +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-02-12 11:32:30 +0900",
"test/yosupo-point-set-range-composite.2.test.cpp": "2024-02-12 11:32:30 +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",
Expand Down
13 changes: 0 additions & 13 deletions .vscode/settings.json

This file was deleted.

27 changes: 27 additions & 0 deletions cpp/segtree.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include <cassert>
#include <functional>
#include <limits>
#include <numeric>
#include <ostream>
#include <vector>

Expand Down Expand Up @@ -299,6 +300,10 @@ namespace segtree {
struct Min {
const S operator() (const S& a, const S& b) const { return std::min(a, b); }
};
template <typename S, std::enable_if_t<std::is_integral_v<S>>* = nullptr>
struct Gcd {
constexpr S operator()(const S& a, const S& b) const { return std::gcd(a, b); }
};
template <typename S, std::enable_if_t<std::is_scalar_v<S>>* = nullptr>
struct MaxLimit {
constexpr S operator() () const { return std::numeric_limits<S>::max(); }
Expand All @@ -311,6 +316,14 @@ namespace segtree {
struct Zero {
S operator() () const { return S(0); }
};
template <typename S>
struct One {
S operator()() const { return S(1); }
};
template <typename S>
struct None {
S operator()() const { return S{}; }
};
}
/**
* @brief RangeMaxQuery
Expand All @@ -333,3 +346,17 @@ using RMinQ = StaticSegTree<S, segtree::Min<S>, segtree::MaxLimit<S>>;
*/
template <typename S>
using RSumQ = StaticSegTree<S, std::plus<S>, segtree::Zero<S>>;
/**
* @brief RangeProdQuery
*
* @tparam S 型
*/
template <typename S>
using RProdQ = StaticSegTree<S, std::multiplies<S>, segtree::One<S>>;
/**
* @brief RangeGcdQuery
*
* @tparam S 型
*/
template <typename S>
using RGcdQ = StaticSegTree<S, segtree::Gcd<S>, segtree::Zero<S>>;
32 changes: 32 additions & 0 deletions test/atcoder-abc254-f.text.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#define PROBLEM "https://atcoder.jp/contests/abc254/tasks/abc254_f"

#include <iostream>

#include "../cpp/segtree.hpp"

int main(void) {
int N, Q;
std::cin >> N >> Q;
std::vector<int> 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<int> 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;
}
}
Loading