結果
| 問題 |
No.510 二次漸化式
|
| コンテスト | |
| ユーザー |
はまやんはまやん
|
| 提出日時 | 2017-05-02 19:58:50 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
RE
|
| 実行時間 | - |
| コード長 | 3,073 bytes |
| コンパイル時間 | 1,963 ms |
| コンパイル使用メモリ | 182,620 KB |
| 実行使用メモリ | 141,324 KB |
| 最終ジャッジ日時 | 2024-09-14 04:45:07 |
| 合計ジャッジ時間 | 17,242 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | RE * 2 |
| other | RE * 14 TLE * 1 -- * 19 |
ソースコード
#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]);
}
}
}
はまやんはまやん