fork(1) download
  1. #include<iostream>
  2. #include<cmath>
  3. using namespace std;
  4.  
  5. #define MOD 1000000007
  6.  
  7. long long a[1000000];
  8. long long c[1000000];
  9. long long y[1000000];
  10. long long z[1000000];
  11. long long result;
  12. long long d[31];
  13. long long res;
  14. int n, q, e, f;
  15.  
  16. int main() {
  17. cin >> n >> q;
  18. for (int i = 1; i <= n; i++) {
  19. cin >> a[i];
  20. }
  21. c[0] = 1;
  22. c[q + 1] = 1;
  23. for (int i = 1; i <= q; i++) {
  24. cin >> c[i];
  25. }
  26. for (int h = 2; h <= n; h++) {
  27. e = a[h - 1];
  28. f = a[h];
  29.  
  30. d[0] = e;
  31. for (int i = 1; i < 31; i++) {
  32. d[i] = (long long)(d[i - 1] * d[i - 1]) % MOD;
  33. }
  34. res = 1;
  35. for (int i = 0; i < 31; i++) {
  36. if (f % 2 == 1) {
  37. res *= d[i];
  38. res %= MOD;
  39. }
  40. f /= 2;
  41. }
  42. y[h] = res;
  43. }
  44. z[1] = 0;
  45. for (int i = 2; i <= n; i++) {
  46. z[i] = z[i - 1] + y[i];
  47. }
  48. result = 0;
  49. for (int i = 1; i <= q + 1; i++) {
  50. result += abs(z[c[i]] - z[c[i - 1]]);
  51. result %= MOD;
  52. }
  53. cout << result << endl;
  54. return 0;
  55. }
Success #stdin #stdout 0s 34712KB
stdin
3 2
23 12 9
2 3
stdout
876796540