結果

問題 No.3492 区間冪乗加算一点取得
コンテスト
ユーザー kuromath
提出日時 2026-04-03 22:24:37
言語 C++23
(gcc 15.2.0 + boost 1.89.0)
コンパイル:
g++-15 -O2 -lm -std=c++23 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 913 ms / 4,000 ms
コード長 7,738 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 4,523 ms
コンパイル使用メモリ 386,948 KB
実行使用メモリ 36,480 KB
最終ジャッジ日時 2026-04-03 22:24:58
合計ジャッジ時間 14,928 ms
ジャッジサーバーID
(参考情報)
judge4_0 / judge2_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 27
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <bits/stdc++.h>
#include <atcoder/all>
//#pragma GCC target("avx2")
//#pragma GCC optimize("O3")
//#pragma GCC optimize("unroll-loops")
using namespace std;
using namespace atcoder;

inline void scan(int &a) { cin >> a; }
inline void scan(unsigned int &a) { cin >> a; }
inline void scan(long long &a) { cin >> a; }
inline void scan(unsigned long long &a) { cin >> a; }
inline void scan(atcoder::modint &a) { long long x; scan(x); a = x; }
inline void scan(float &a) { cin >> a; }
inline void scan(double &a) { cin >> a; }
inline void scan(long double &a) { cin >> a; }
inline void scan(char &a) { cin >> a; }
inline void scan(string &a) { cin >> a; }
inline void scan(vector<bool> &vec) { for (int i = 0; i < int(vec.size()); i++) { int a; scan(a); vec[i] = a; } }

template<typename T> inline void scan(vector<T> &vec);
template<typename T, size_t size> inline void scan(array<T, size> &vec);
template<typename T> inline void scan(deque<T> &deq);
template<typename T, typename U> inline void scan(pair<T, U> &p);

template<typename T> inline void scan(vector<T> &vec) {
    for (auto &i : vec) scan(i);
}

template<typename T, size_t size> inline void scan(array<T, size> &vec) {
    for (auto &i : vec) scan(i);
}

template<typename T> inline void scan(deque<T> &deq) {
    for (auto &i : deq) scan(i);
}

template<typename T, typename U> inline void scan(pair<T, U> &p) {
    scan(p.first);
    scan(p.second);
}

template<typename T> inline void scan(T &a) { cin >> a; }

inline void read() {}
template<typename Head, typename... Tail> inline void read(Head &head, Tail &...tail) {
    scan(head);
    read(tail...);
}

inline void write(const int &a) { cout << a; }
inline void write(const unsigned int &a) { cout << a; }
inline void write(const long long &a) { cout << a; }
inline void write(const unsigned long long &a) { cout << a; }
inline void write(const float &a) { cout << a; }
inline void write(const double &a) { cout << a; }
inline void write(const long double &a) { cout << a; }
inline void write(const char &a) { cout << a; }
inline void write(const string &a) { cout << a; }

template<typename T> inline void write(const vector<T> &vec);
template<typename T, size_t size> inline void write(const array<T, size> &vec);
template<typename T> inline void write(const deque<T> &deq);
template<typename T, typename U> inline void write(const pair<T, U> &p);

template<typename T> inline void write(const vector<T> &vec) {
    int n = vec.size();
    for (int i = 0; i < n; i++) {
        if (i) write(' ');
        write(vec[i]);
    }
}

template<typename T, size_t size> inline void write(const array<T, size> &vec) {
    int n = vec.size();
    for (int i = 0; i < n; i++) {
        if (i) write(' ');
        write(vec[i]);
    }
}

template<typename T> inline void write(const deque<T> &deq) {
    int n = deq.size();
    for (int i = 0; i < n; i++) {
        if (i) write(' ');
        write(deq[i]);
    }
}

template<typename T, typename U> inline void write(const pair<T, U> &p) {
    write(p.first);
    write(' ');
    write(p.second);
}

template<typename T> inline void write(const T &a) { cout << a; }

inline void print() { cout << '\n'; }
template<typename T> inline void print(const T &a) { write(a); cout << '\n'; }
template<typename Head, typename... Tail> inline void print(const Head &head, const Tail &...tail) {
    write(head);
    write(' ');
    print(tail...);
}

using ll = long long;
using ld = long double;
using ull = unsigned long long;
template<typename T> using pq = priority_queue<T>;
template<typename T> using pq_g = priority_queue<T, vector<T>, greater<T>>;
using mint = modint;

#define rep(i, n) for (int i = 0; i < (n); i++)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define UNIQUE(v) (v).erase(unique((v).begin(), (v).end()), (v).end())
#define dbg(x) cerr << #x << " = " << x << endl;
#define NP next_permutation
#define endl '\n'
#define INT(...) int __VA_ARGS__; read(__VA_ARGS__);
#define LL(...) long long __VA_ARGS__; read(__VA_ARGS__);
#define ULL(...) unsigned long long __VA_ARGS__; read(__VA_ARGS__);
#define MINT(...) atcoder::modint __VA_ARGS__; read(__VA_ARGS__);
#define STR(...) string __VA_ARGS__; read(__VA_ARGS__);
#define CHAR(...) char __VA_ARGS__; read(__VA_ARGS__);
#define LD(...) long double __VA_ARGS__; read(__VA_ARGS__);
#define VEC(type, name, size) vector<type> name(size); read(name);
#define VV(type, name, h, w) vector<vector<type>> name(h, vector<type>(w)); read(name);

inline void Yes(bool a = true) { cout << (a ? "Yes" : "No") << endl; }
inline void No(bool a = true) { cout << (a ? "No" : "Yes") << endl; }
inline void Takahashi(bool a = true) { cout << (a ? "Takahashi" : "Aoki") << endl; }
inline void Alice(bool a = true) { cout << (a ? "Alice" : "Bob") << endl; }
inline void Possible(bool a = true) { cout << (a ? "Possible" : "Impossible") << endl; }

constexpr int INF = 2e9;
constexpr ll LINF = 2e18;
constexpr ld pi = 3.14159265358979323846;
constexpr ld eps = 1e-9;
constexpr int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
constexpr int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};

ll modPow(ll a, ll n, ll mod = LINF) { ll ret = 1; ll x = a % mod; while (n) { if (n & 1) ret = ret * x % mod; x = x * x % mod; n >>= 1; } return ret; }
int popcount(int x) { return __builtin_popcount(x); }
ll popcount(ll x) { return __builtin_popcountll(x); }
ll isqrt(ll x) { ll n = sqrtl(x); while ((n + 1) * (n + 1) <= x) n++; while (n * n > x) n--; return n; }
template<typename T> T floor(T a, T b) { return a / b - (a % b && (a ^ b) < 0); }
template<typename T> T ceil(T a, T b) { return floor(a + b - 1, b); }
template<typename T> T bmod(T a, T b) { return a - b * floor(a, b); }
template<typename T> pair<T, T> divmod(T a, T b) { return {floor(a, b), a - b * floor(a, b)}; }
template<typename T> auto MIN(const vector<T> &a) { return *min_element(all(a)); }
template<typename T> auto MAX(const vector<T> &a) { return *max_element(all(a)); }
template<typename T> auto SUM(const vector<T> &a) { return accumulate(all(a), T(0)); }
template<typename T> bool chmin(T &a, const T &b) { if (a > b) { a = b; return true; } return false; }
template<typename T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }

void cincout() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(15);
}

struct S {
    mint sum;
    int siz;
};

S op(S a, S b) { return {a.sum + b.sum, a.siz + b.siz}; }
S e() { return {0, 0}; }
using F = mint;
S mapping(F f, S x) { return {x.sum + x.siz * f, x.siz}; }
F composition(F f, F g) { return f + g; }
F id() { return 0; }

vector<vector<mint>> Combination_table(const int n) {
    vector<vector<mint>> Com(n + 1, vector<mint>(n + 1));
    Com[0][0] = 1;
    for (int i = 1; i <= n; i++) {
        Com[i][0] = 1;
        for (int j = 1; j <= n; j++) {
            Com[i][j] = (Com[i - 1][j] + Com[i - 1][j - 1]);
        }
    }
    return Com;
}


void solve() {
    INT(N, B, Q);
    modint::set_mod(B);
    using lseg = atcoder::lazy_segtree<S, op, e, F, mapping, composition, id>;
    vector<lseg> seg(101, lseg(N));
    for (int i = 0; i <= 100; i++) for (int j = 0; j < N; j++) seg[i].set(j, {0, 1});
    auto Com = Combination_table(100);
    while (Q--) {
        LL(L, M, R, C, D);
        L--;
        M--;
        for (int k = 0; k <= D; k++) {
            seg[k].apply(L, R, Com[D][k] * mint(C).pow(D - k));
            // dbg(seg[k].get(0).sum.val());
        }
        mint ans = 0;
        for (int k = 0; k <= 100; k++) ans += seg[k].get(M).sum * mint(M + 1).pow(k);
        print(ans.val());
    }   
};

int main() {
    cincout();
    int t = 1;
    // cin >> t;
    while (t--) solve();
    return 0;
}
0