rt
本蒟蒻 TLE 4个点,加 O2 会 WA 一个点 (95) 分
以下是代码
#include<bits/stdc++.h>
#define ll long long
const int MOD = 1e9 + 7;
using namespace std;
int a, b, c, d, o, w, len1, len2; string n, m, n1, m1;
struct node{
ll p[5][5];
ll* operator[] (int x) {
return p[x];
}
} unit, stan, ans1, ans2;
node operator* (node x, node y) {
node q;
for(int i = 1; i <= 2; ++i) {
for(int j = 1; j <= 2; ++j) {
q[i][j] = 0;
for(int k = 1; k <= 2; ++k) {
q[i][j] += 1ll * x[i][k] * y[k][j] % MOD;
q[i][j] %= MOD;
}
}
} return q;
}
int main() {
cin >> n >> m; scanf("%d%d%d%d", &a, &b, &c, &d);
len1 = n.length() - 1, len2 = m.length() - 1;
o = len2; n1 = n; w = len1; m1 = m;
ans1[1][1] = 1; ans1[2][2] = 1; stan[1][1] = a;
stan[1][2] = b, stan[2][1] = 0, stan[2][2] = 1;
while(m1[o] == '0' && o > -1) m1[o] = '9', --o; m1[o]--;
while(n1[w] == '0' && w > -1) n1[w] = '9', --o; n1[w]--;
o = len2; w = len1;
while(o > -1) {
node t = stan;
for(int i = 1; i <= m1[o] - '0'; ++i) ans1 = t * ans1;
for(int i = 1; i <= 9; ++i) stan = t * stan; --o;
}
for(int i = 1; i <= 2; ++i) stan[i][1] = ans1[i][1], stan[i][2] = ans1[i][2];
ans2[1][1] = 1; ans2[2][2] = 1; (stan[1][1] *= c) %= MOD;
(((stan[1][2] *= c) %= MOD) += d) %= MOD;
while(w > -1) {
node t = stan;
for(int i = 1; i <= n1[w] - '0'; ++i) ans2 = ans2 * t;
for(int i = 1; i <= 9; ++i) stan = stan * t; --w;
}
node ans; ans[1][1] = 1; ans[2][1] = 1;
ans = ans1 * ans2 * ans;
printf("%d\n", ans[1][1] % MOD);
return 0;
}
望大佬帮助