結果

問題 No.2395 区間二次変換一点取得
ユーザー milanis48663220milanis48663220
提出日時 2023-07-28 21:48:54
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 119 ms / 2,000 ms
コード長 4,045 bytes
コンパイル時間 1,446 ms
コンパイル使用メモリ 125,376 KB
実行使用メモリ 16,228 KB
最終ジャッジ日時 2024-04-16 05:41:55
合計ジャッジ時間 4,734 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 50 ms
16,220 KB
testcase_01 AC 50 ms
16,096 KB
testcase_02 AC 50 ms
16,224 KB
testcase_03 AC 51 ms
16,220 KB
testcase_04 AC 50 ms
16,224 KB
testcase_05 AC 50 ms
16,228 KB
testcase_06 AC 50 ms
16,224 KB
testcase_07 AC 50 ms
16,100 KB
testcase_08 AC 50 ms
16,220 KB
testcase_09 AC 50 ms
16,100 KB
testcase_10 AC 50 ms
16,096 KB
testcase_11 AC 51 ms
16,224 KB
testcase_12 AC 56 ms
16,228 KB
testcase_13 AC 117 ms
16,224 KB
testcase_14 AC 119 ms
16,228 KB
testcase_15 AC 118 ms
16,096 KB
testcase_16 AC 119 ms
16,096 KB
testcase_17 AC 119 ms
16,100 KB
testcase_18 AC 107 ms
16,100 KB
testcase_19 AC 109 ms
16,100 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <tuple>
#include <cmath>
#include <numeric>
#include <functional>
#include <cassert>
#include <atcoder/modint>

#define debug_value(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << #x << "=" << x << endl;
#define debug(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << x << endl;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

using namespace std;
typedef long long ll;

template<typename T>
vector<vector<T>> vec2d(int n, int m, T v){
    return vector<vector<T>>(n, vector<T>(m, v));
}

template<typename T>
vector<vector<vector<T>>> vec3d(int n, int m, int k, T v){
    return vector<vector<vector<T>>>(n, vector<vector<T>>(m, vector<T>(k, v)));
}

template<typename T>
void print_vector(vector<T> v, char delimiter=' '){
    if(v.empty()) {
        cout << endl;
        return;
    }
    for(int i = 0; i+1 < v.size(); i++) cout << v[i] << delimiter;
    cout << v.back() << endl;
}

using mint = atcoder::modint;

ostream& operator<<(ostream& os, const mint& m){
    os << m.val();
    return os;
}


//1-indexed
template <typename T>
struct bit{
    int n;
    vector<T> data;

    bit(int n_){
        n = 1;
        while(n < n_) n *= 2;
        data = vector<T>(n+1);
        for(int i = 0; i <= n; i++) data[i] = 0;
    }
    
    T sum(int i){
        T ret = 0;
        while(i > 0){
            ret += data[i];
            i -= i&-i;
        }
        return ret;
    }

    void add(int i, T x){
        while(i <= n){
            data[i] += x;
            i += i&-i;
        }
    }
};

template<typename T, int N, int M>
class Matrix {
    public:
    array<array<T, M>, N> dat;
    Matrix(T val) {
        for(int i = 0; i < N; i++){
            for(int j = 0; j < M; j++){
                dat[i][j] = val;
            }
        }
    }

    Matrix(array<array<T, M>, N> dat): dat(dat){  }
    array<T, M>& operator[](int x) {
        return dat[x];
	}
};

template<typename T, int N, int M, int K>
Matrix<T, N, K> operator*(Matrix<T, N, M> a, Matrix<T, M, K> b){
    Matrix<T, N, K> c(T(0));
    for(int i = 0; i < N; i++){
        for(int j = 0; j < K; j++){
            for(int k = 0; k < M; k++){
                c.dat[i][j] += a.dat[i][k]*b.dat[k][j];
            }
        }
    }
    return c;
}

template<typename T, int N>
Matrix<T, N, N> operator^(Matrix<T, N, N> m, long long r){
    Matrix<T, N, N> ans(T(0));
    for(int i = 0; i < N; i++) ans[i][i] = T(1);
    while (r > 0) {
        if (r&1) ans = (ans*m);
        m = (m*m);
        r >>= 1;
    }
    return ans;
}

template <typename T, int N, int M>
void print_mat(Matrix<T, N, M> a){
    for(int i = 0; i < N; i++){
        for(int j = 0; j < M; j++){
            cout << a.dat[i][j] << ' ';
        }
        cout << endl;
    }
}

template <typename T, int N, int M>
ostream& operator<<(ostream& os, const Matrix<T, N, M>& m){
    print_mat<T, N, M>(m);
    return os;
}

using Mat = Matrix<mint, 5, 5>;
using Vec = Matrix<mint, 5, 1>;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << setprecision(10) << fixed;
    int n, b, q; cin >> n >> b >> q;
    mint::set_mod(b);
    vector<Mat> v;
    Mat e(mint(0));
    Mat a(mint(0));
    for(int i = 0; i < 5; i++) e[i][i] = 1;
    a[0][0] = 1; a[0][4] = 1;
    a[1][1] = 3; a[1][2] = 2; a[1][3] = 2;
    a[2][2] = 3;
    a[3][2] = 3; a[3][3] = 3;
    a[4][4] = 1;
    v.push_back(e);
    auto x = e;
    for(int i = 0; i < 100000; i++){
        x = x*a;
        v.push_back(x);
    }
    bit<int> bt(n*2);
    Vec u(mint(1));;
    while(q--){
        int l, m, r; cin >> l >> m >> r;
        bt.add(l, 1);
        bt.add(r+1, -1);
        int x = bt.sum(m);
        auto ans = v[x]*u;
        cout << ans[0][0] << ' ' << ans[1][0] << ' ' << ans[2][0] << '\n';
    }
}
0