結果

問題 No.510 二次漸化式
ユーザー 👑 はまやんはまやんはまやんはまやん
提出日時 2017-05-02 19:58:50
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
RE  
実行時間 -
コード長 3,073 bytes
コンパイル時間 2,000 ms
コンパイル使用メモリ 180,564 KB
実行使用メモリ 71,036 KB
最終ジャッジ日時 2023-10-12 05:14:59
合計ジャッジ時間 18,359 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 RE -
testcase_01 RE -
testcase_02 RE -
testcase_03 RE -
testcase_04 RE -
testcase_05 RE -
testcase_06 RE -
testcase_07 RE -
testcase_08 RE -
testcase_09 RE -
testcase_10 RE -
testcase_11 RE -
testcase_12 RE -
testcase_13 RE -
testcase_14 RE -
testcase_15 RE -
testcase_16 TLE -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=a;i<b;i++)


#define INF 1LL<<60
typedef vector<int> Vec;
typedef vector<Vec> Mat;
int mod = 1000000007;
int add(int x, int y) { return (x += y) >= mod ? x - mod : x; }
template<class... T> int add(int x, T... y) { return add(x, add(y...)); }
int mul(int x, int y) { return 1LL * x * y % mod; }
template<class... T> int mul(int x, T... y) { return mul(x, mul(y...)); }
int sub(int x, int y) { return add(x, mod - y); }
int modpow(int a, long long b) { int ret = 1; while (b > 0) { if (b & 1) ret = 1LL * ret * a % mod; a = 1LL * a * a % mod; b >>= 1; } return ret; }
int modinv(int a) { return modpow(a, mod - 2); }
Vec mulMatVec(Mat a, Vec b) {
    int n = b.size(); Vec ret(n, 0);
    rep(i, 0, n) rep(j, 0, n) ret[i] = add(ret[i], mul(a[i][j], b[j]));
    return ret;
}
Mat mulMatMat(Mat a, Mat b) {
    int n = a.size(); Mat ret(n, Vec(n, 0));
    rep(i, 0, n) rep(j, 0, n) rep(k, 0, n) ret[i][j] = add(ret[i][j], mul(a[i][k], b[k][j]));
    return ret;
}
struct func {
    // ax+b
    Mat m;
    func(){
        m = Mat(4, Vec(4, 0));
        rep(i, 0, 4) m[i][i] = 1;
    }
};

func operator*(func x, func y) {
    func res;
    res.m = mulMatMat(x.m, y.m);
    return res;
}
//-----------------------------------------------------------------
template<class V, int NV> struct SegTree {
    V comp(V l, V r) {
        return l * r;
    };
    vector<V> val; SegTree() { val = vector<V>(NV * 2); }
    V get(int x, int y, int l = 0, int r = NV, int k = 1) { // x<=i<y
        if (r <= x || y <= l) return V();
        if (x <= l && r <= y) return val[k];
        auto A = get(x, y, l, (l + r) / 2, k * 2);
        auto B = get(x, y, (l + r) / 2, r, k * 2 + 1);
        return comp(A, B);
    }
    void update(int i, V v) { i += NV; val[i] = v; while (i>1) i >>= 1, val[i] = comp(val[i * 2], val[i * 2 + 1]); }
};
SegTree<func, 1 << 17> st;
//-----------------------------------------------------------------------------------
int N, Q;
int X[101010], Y[101010];
void make(int i) {
    func f;
    rep(y, 0, 4) rep(x, 0, 4) f.m[y][x] = 0;

    f.m[0][0] = 1;
    f.m[0][2] = X[i];
    f.m[1][1] = Y[i];
    f.m[1][3] = 1;
    f.m[2][1] = mul(2, Y[i]);
    f.m[2][2] = mul(Y[i], Y[i]);
    f.m[2][3] = 1;
    f.m[3][3] = 1;

    st.update(i, f);
}
//-----------------------------------------------------------------------------------
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);

    cin >> N >> Q;
    rep(i, 0, N) make(i);

    rep(q, 0, Q) {
        char t; cin >> t;
        if (t == 'x') {
            int i, v; cin >> i >> v;
            X[i] = v;
            make(i);
        }
        else if (t == 'y') {
            int i, v; cin >> i >> v;
            Y[i] = v;
            make(i);
        }
        else {
            int i; cin >> i;

            auto f = st.get(0, i);
            Vec v;
            v[0] = 1;
            v[1] = 1;
            v[2] = 1;
            v[3] = 1;

            v = mulMatVec(f.m, v);
            printf("%d\n", v[0]);
        }
    }
}
0