#define _USE_MATH_DEFINES #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; const int MOD = 1000000007; // 行列の積 template vector > matrixProduct(const vector >& x, const vector >& y) { int a = x.size(); int b = x[0].size(); int c = y[0].size(); vector > z(a, vector(c, 0)); for(int i=0; i > T1; typedef vector > T2; // データの初期値、以下の条件を満たすこと // uniteData(v, INIT_DATA) == v static const T1 INIT_DATA; // 前回の値がprevである要素に対して、 // パラメータxを用いた更新処理を適用した後の計算結果を返す T1 updateData(T1 prev, T2 x){ return x; } // 2つの区間の計算結果v1,v2に対して、 // その2つの区間を統合した区間における計算結果を返す T1 uniteData(T1 v1, T1 v2){ return matrixProduct(v2, v1); } int n; vector data; void updateTree(int a, int k, int l, int r, T2 x){ if(a == l && a == r){ data[k] = updateData(data[k], x); } else if(l <= a && a <= r){ updateTree(a, k*2+1, l, (l+r)/2, x); updateTree(a, k*2+2, (l+r+1)/2, r, x); data[k] = uniteData(data[k*2+1], data[k*2+2]); } } T1 getValue(int a, int b, int k, int l, int r){ if(a <= l && r <= b){ return data[k]; } else if(a <= r && l <= b){ T1 v1 = getValue(a, b, k*2+1, l, (l+r)/2); T1 v2 = getValue(a, b, k*2+2, (l+r+1)/2, r); return uniteData(v1, v2); } else{ return INIT_DATA; } } public: SegmentTree(int n0){ n = 1; while(n < n0) n *= 2; data.assign(2*n-1, INIT_DATA); } SegmentTree(const vector& v) : SegmentTree((int)v.size()){ for(unsigned i=0; i=0; --k) data[k] = uniteData(data[k*2+1], data[k*2+2]); } // a番目の要素にパラメータxによる更新処理を適用 void update(int a, T2 x){ updateTree(a, 0, 0, n-1, x); } // 区間[a,b]の計算結果を返す T1 get(int a, int b){ return getValue(a, b, 0, 0, n-1); } }; const vector > SegmentTree::INIT_DATA = { { 1, 0, 0, 0 }, { 0, 0, 0, 1 }, { 0, 0, 0, 1 }, { 0, 0, 0, 1 }, }; int main() { int n, q; cin >> n >> q; vector x(n, 0); vector y(n, 0); SegmentTree st(n+1); while(--q >= 0){ char c; int i; cin >> c >> i; if(c == 'a'){ vector > mat = st.get(0, i); long long ans = accumulate(mat[0].begin(), mat[0].end(), 0LL); ans %= MOD; cout << ans << endl; continue; } int v; cin >> v; if(c == 'x') x[i] = v; else y[i] = v; vector > mat = { { 1, 0, x[i], 0 }, { 0, y[i], 0, 1 }, { 0, 2*y[i]%MOD, y[i]*y[i]%MOD, 1 }, { 0, 0, 0, 1 }, }; st.update(i+1, mat); } return 0; }