1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66
| #include <iostream> #define maxn 200010 #define maxm 11 #define ll long long using namespace std;
const int p = 1000000007; inline int add(int x, int y) { return (x += y) >= p ? x - p : x; } inline int mul(int x, int y) { return 1ll * x * y % p; } inline int add(initializer_list<int> lst) { int s = 0; for (auto t : lst) s = add(s, t); return s; } inline int mul(initializer_list<int> lst) { int s = 1; for (auto t : lst) s = mul(s, t); return s; } int pow_mod(int x, int n) { int s = 1; for (; n; n >>= 1, x = mul(x, x)) if (n & 1) s = mul(s, x); return s; } const int inv2 = pow_mod(2, p - 2);
int n, m, a[maxn]; int s[maxn][maxm], pre[maxn];
int f[maxn][maxm], C[maxm][maxm]; void init(int n) { for (int i = 0; i <= n; ++i) { f[i][0] = 1; for (int j = 1; j <= 10; ++j) f[i][j] = mul(f[i][j - 1], i); } for (int i = 1; i <= n; ++i) for (int j = 0; j <= 10; ++j) f[i][j] = add(f[i][j], f[i - 1][j]);
for (int i = 0; i <= 10; ++i) C[i][0] = 1; for (int i = 1; i <= 10; ++i) for (int j = 1; j <= i; ++j) C[i][j] = C[i - 1][j] + C[i - 1][j - 1];
for (int i = 1; i <= n; ++i) { s[i][0] = 1; for (int j = 1; j <= 10; ++j) s[i][j] = mul(s[i][j - 1], a[i]); } for (int i = 1; i <= n; ++i) for (int j = 1; j <= 10; ++j) s[i][j] = add(s[i][j], s[i - 1][j]); }
int main() { ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
cin >> n >> m; for (int i = 1; i <= n; ++i) cin >> a[i], pre[i] = add(pre[i - 1], a[i]); init(n); while (m--) { int l, r, d, a, len; cin >> l >> r >> d; len = r - l + 1; bool ok = true; a = mul(add({ pre[r], p - pre[l - 1], p - mul({ d, len, len - 1, inv2 }) }), pow_mod(len, p - 2)); for (int i = 1, invd = pow_mod(d, p - 2), Dk = d; i <= 10; ++i, Dk = mul(Dk, d)) { int res = 0, ak = 1, dk = Dk; for (int j = 0; j <= i; ++j) { res = add(res, mul({ C[i][j], ak, dk, f[len - 1][i - j] })); ak = mul(ak, a); dk = mul(dk, invd); } if (res != add(s[r][i], p - s[l - 1][i])) { ok = false; break; } } cout << (ok ? "Yes" : "No") << "\n"; } return 0; }
|