結果
問題 | No.2395 区間二次変換一点取得 |
ユーザー | Focus_Sash |
提出日時 | 2023-07-28 22:10:01 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 1,331 ms / 2,000 ms |
コード長 | 6,719 bytes |
コンパイル時間 | 2,590 ms |
コンパイル使用メモリ | 223,288 KB |
実行使用メモリ | 7,040 KB |
最終ジャッジ日時 | 2024-10-06 19:05:53 |
合計ジャッジ時間 | 13,205 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
6,820 KB |
testcase_01 | AC | 2 ms
6,820 KB |
testcase_02 | AC | 2 ms
6,816 KB |
testcase_03 | AC | 2 ms
6,820 KB |
testcase_04 | AC | 2 ms
6,820 KB |
testcase_05 | AC | 2 ms
6,816 KB |
testcase_06 | AC | 2 ms
6,820 KB |
testcase_07 | AC | 2 ms
6,816 KB |
testcase_08 | AC | 2 ms
6,816 KB |
testcase_09 | AC | 2 ms
6,820 KB |
testcase_10 | AC | 2 ms
6,820 KB |
testcase_11 | AC | 10 ms
6,820 KB |
testcase_12 | AC | 106 ms
6,820 KB |
testcase_13 | AC | 1,300 ms
6,912 KB |
testcase_14 | AC | 1,296 ms
6,912 KB |
testcase_15 | AC | 1,249 ms
7,040 KB |
testcase_16 | AC | 1,278 ms
6,912 KB |
testcase_17 | AC | 1,261 ms
6,912 KB |
testcase_18 | AC | 1,331 ms
6,912 KB |
testcase_19 | AC | 1,316 ms
6,912 KB |
ソースコード
#include "bits/stdc++.h" using namespace std; namespace util { using ll = long long; using vl = std::vector<long long>; using pl = std::pair<long long, long long>; constexpr long long kInf = std::numeric_limits<long long>::max() / 8; constexpr long long kMax = std::numeric_limits<long long>::max(); template <typename T, typename U> inline bool UpdateMax(T &x, const U &y) { if (x < y) { x = y; return true; } return false; } template <typename T, typename U> inline bool UpdateMin(T &x, const U &y) { if (x > y) { x = y; return true; } return false; } // verified inline long long Pow(long long x, long long n) { assert(n >= 0); if (x == 0) return 0; long long res = 1LL; while (n > 0) { if (n & 1) { assert(x != 0 && std::abs(res) <= kMax / std::abs(x)); res = res * x; } if (n >>= 1) { assert(x != 0 && std::abs(x) <= kMax / std::abs(x)); x = x * x; } } return res; } // verified inline long long Mod(long long n, const long long m) { // returns the "arithmetic modulo" // for a pair of integers (n, m) with m != 0, there exists a unique pair of // integer (q, r) s.t. n = qm + r and 0 <= r < |m| returns this r assert(m != 0); if (m < 0) return Mod(n, -m); if (n >= 0) return n % m; else return (m + n % m) % m; } inline long long Quotient(long long n, long long m) { // returns the "arithmetic quotient" assert((n - Mod(n, m)) % m == 0); return (n - Mod(n, m)) / m; } inline long long DivFloor(long long n, long long m) { // returns floor(n / m) assert(m != 0); if (m < 0) { n = -n; m = -m; } if (n >= 0) return n / m; else if (n % m == 0) return -(abs(n) / m); else return -(abs(n) / m) - 1; } inline long long DivCeil(long long n, long long m) { // returns ceil(n / m) assert(m != 0); if (n % m == 0) return DivFloor(n, m); else return DivFloor(n, m) + 1; } template <typename T> inline T Sum(const std::vector<T> &vec) { return std::accumulate(vec.begin(), vec.end(), T(0)); } } // namespace util using namespace util; inline long long PowMod(long long x, long long n, const long long m) { assert(n >= 0); assert(m != 0); if (x == 0) return 0; long long res = 1; x = Mod(x, m); while (n > 0) { if (n & 1) { assert(x == 0 || std::abs(res) <= kMax / std::abs(x)); res = Mod(res * x, m); } if (n >>= 1) { assert(x == 0 || std::abs(x) <= kMax / std::abs(x)); x = Mod(x * x, m); } } return res; } #include <cassert> #include <vector> template <typename T> class Matrix { private: int row_, col_; public: std::vector<std::vector<T>> m_; Matrix(int row, int col) : row_(row), col_(col), m_() {} Matrix(int row, int col, T x) : row_(row), col_(col), m_(row, std::vector<T>(col)) { for (int i = 0; i < row_; i++) { for (int j = 0; j < col_; j++) m_[i][j] = x; } } Matrix(std::vector<std::vector<T>> &m) : row_((int)m.size()), col_((int)m[0].size()), m_(m) {} Matrix(std::initializer_list<std::vector<T>> init) : m_(init) { row_ = (int)m_.size(); col_ = (int)m_[0].size(); } bool operator==(const Matrix &x) { if (row_ != x.n || col_ != x.m) return false; for (int i = 0; i < row_; i++) { for (int j = 0; j < col_; j++) { if (m_[i][j] != x[i][j]) return false; } } return true; } Matrix &operator=(const Matrix &x) = default; Matrix operator+(const Matrix &x) { assert(row_ == x.row_ && col_ == x.col_); Matrix res(m_); for (int i = 0; i < row_; i++) { for (int j = 0; j < col_; j++) { res.m_[i][j] += x.m_[i][j]; } } return res; } Matrix operator-(const Matrix &x) { assert(row_ == x.row_ && col_ == x.col_); Matrix res(m_); for (int i = 0; i < row_; i++) { for (int j = 0; j < col_; j++) { res.m_[i][j] -= x.m_[i][j]; } } return res; } Matrix operator*(const Matrix &x) { assert(col_ == x.row_); Matrix res(row_, x.col_, T()); for (int i = 0; i < row_; i++) { for (int k = 0; k < col_; k++) { for (int j = 0; j < x.col_; j++) { res.m_[i][j] += m_[i][k] * x.m_[k][j]; } } } return res; } std::vector<T> operator*(const std::vector<T> &v) { assert(col_ == (int)v.size()); std::vector<T> res(row_, 0); for (int i = 0; i < row_; i++) { for (int j = 0; j < col_; j++) { res[i] += m_[i][j] * v[j]; } } return res; } Matrix &operator+=(const Matrix &x) { *this = *this + x; return *this; } Matrix &operator-=(const Matrix &x) { *this = *this - x; return *this; } Matrix &operator*=(const Matrix &x) { *this = *this * x; return *this; } T &operator()(long long i, long long j) { return m_[i][j]; } std::vector<T> &operator[](long long i) { return m_[i]; } Matrix pow(long long k) { assert(k >= 0); assert(row_ == col_); std::vector<std::vector<T>> x(row_, std::vector<T>(row_)); for (int i = 0; i < row_; i++) x[i][i] = 1; Matrix res(x), tmp = *this; while (k) { if (k & 1) res *= tmp; k >>= 1; tmp *= tmp; } return res; } Matrix transpose() { Matrix<T> ret(col_, row_, 0); for (int i = 0; i < col_; i++) { for (int j = 0; j < row_; j++) { ret[i][j] = (*this)[j][i]; } } return ret; } }; template <typename T> Matrix<T> DiagonalMatrix(const int n, const T d) { Matrix<T> res(n, n); for (int i = 0; i < n; i++) res.m_[i][i] = d; return res; } template <typename T> Matrix<T> IdentityMatrix(const int n) { return diag(n, T(1)); } #include <atcoder/lazysegtree> using namespace atcoder; ll op(ll x, ll y) { return x + y; } ll e() { return 0; } ll mapping(ll f, ll x) { return f + x; } ll composition(ll f, ll g) { return f + g; } ll id() { return 0; } #include <atcoder/modint> void solve() { ll n, b, q; cin >> n >> b >> q; lazy_segtree<ll, op, e, ll, mapping, composition, id> seg(n); vector<modint> init = {1, 1, 1, 1, 1}; modint::set_mod(b); Matrix<modint> M = {{1, 0, 0, 0, 1}, {0, 3, 2, 2, 0}, {0, 0, 3, 0, 0}, {0, 0, 3, 3, 0}, {0, 0, 0, 0, 1}}; while (q--) { ll l, m, r; cin >> l >> m >> r; l--; m--; r--; seg.apply(l, r + 1, 1); vector<modint> v = M.pow(seg.get(m)) * init; cout << v[0].val() << " " << v[1].val() << " " << v[2].val() << '\n'; } } int main() { std::cin.tie(nullptr); std::ios::sync_with_stdio(false); std::cout << std::fixed << std::setprecision(15); solve(); return 0; }