description: In the year 2420 humans have finally built a colony on Mars thanks to the work of Elon Tusk. There are 10^9+7 cities arranged in a circle in this colony and none of them are connected yet. Elon Tusk wants to connect some of those cities using only roads of the same size in order to lower the production cost of those roads. Because of that he gave a list on N cites where some cites can appear more than once and Q queries that you need to answer. For the query you need to determine if it is possible to connect all the cities from L_{i} to R_{i} on that list using only roads of length D_{i}. 
  
  Input
  
  The first line contains two integers N and Q (1 ≤ N, Q ≤ 2⋅10^5 ) — the length of the array of cities and the number of queries you need to answer. 
  
  The second lines contains N integers representing the array of cites. Next Q lines contain three integers L, R and D (1 ≤ L_{i}, R_{i} ≤ N, 0 ≤ D_{i} ≤ 10^9+6) — the range of cities that needs to be connected and the length of the road that you can use. 
  
  Output
  
  The output contains Q lines. If it is possible to connect all the cities from the i-th query can be connected with roads of length D_{i} the i-th line should contain the word "Yes", otherwise it should contain the word "No". 
  
  Examples
  
  Input
  
  
  9 8
  17 0 12 6 10 8 2 4 5
  2 3 12
  2 3 6
  2 4 6
  4 6 2
  2 8 2
  1 2 17
  1 8 2
  9 9 14
  
  
  Output
  
  
  Yes
  No
  Yes
  Yes
  Yes
  Yes
  No
  Yes
  
  
  Input
  
  
  4 1
  7 21 14 0
  1 4 1000000000
  
  
  Output
  
  
  Yes
  
  Note
  
  In the 5^{th} query of the first test case we can connect cities in this order 0-2-4-6-8-10-12 this way distance between any two connected cities is 2. In the second test case we can connect cities in this order 21-14-7-0 this way distance between any two connected cities is 10^9 module 10^9+7. 
solution: #include <bits/stdc++.h>
  using namespace std;
  const int M = 1e9 + 7;
  int n, q, x, s[200004][3];
  int c[200004][3];
  int mypow(int x, int t) {
    int ans = 1;
    for (; t; t >>= 1, x = (long long)x * x % M)
      if (t & 1) ans = (long long)ans * x % M;
    return ans;
  }
  bool answer(int N, int D, int s0, int s1, int s2) {
    int s = (long long)(s0 - (long long)c[N - 1][0] * D % M + M) % M *
            mypow(N, M - 2) % M;
    int tmp = (((long long)s * s % M * N % M +
                (long long)s * c[N - 1][0] * 2 % M * D % M) %
                   M +
               (long long)c[N - 1][1] * D % M * D % M) %
              M;
    if (tmp != s1) return 0;
    tmp = ((((long long)s * s % M * s % M * N % M +
             (long long)s * s * 3 % M * c[N - 1][0] % M * D % M % M) %
                M +
            (long long)s * c[N - 1][1] * 3 % M * D % M * D % M) %
               M +
           (long long)c[N - 1][2] * D % M * D % M * D % M) %
          M;
    return tmp == s2;
  }
  int main() {
    scanf("%d%d", &n, &q);
    for (int i = 1; i <= n; i++) {
      scanf("%d", &x);
      s[i][0] = (x + s[i - 1][0]) % M;
      s[i][1] = ((long long)x * x % M + s[i - 1][1]) % M;
      s[i][2] = ((long long)x * x % M * x % M + s[i - 1][2]) % M;
      c[i][0] = (i + c[i - 1][0]) % M;
      c[i][1] = ((long long)i * i % M + c[i - 1][1]) % M;
      c[i][2] = ((long long)i * i % M * i % M + c[i - 1][2]) % M;
    }
    while (q--) {
      int l, r, d;
      scanf("%d%d%d", &l, &r, &d);
      int N = r - l + 1;
      puts(answer(N, d, (s[r][0] - s[l - 1][0] + M) % M,
                  (s[r][1] - s[l - 1][1] + M) % M,
                  (s[r][2] - s[l - 1][2] + M) % M)
               ? "Yes"
               : "No");
    }
  }
  