fork download
  1. #include <stdio.h>
  2.  
  3. #define swap(x, y) (x ^= y, y ^= x, x ^= y)
  4.  
  5. const int MOD = 1000000007;
  6.  
  7. int n, ar[100010], lim[100010];
  8.  
  9. int bigmod(int x, unsigned long long int n){
  10. if (!n) return 1;
  11. if (n == 1) return (x);
  12. unsigned long long int res = bigmod(x, n / 2);
  13. res = (res * res) % MOD;
  14. if (n % 2) res = (res * x) % MOD;
  15. return (res);
  16. }
  17.  
  18. int main(){
  19. int i, j;
  20.  
  21. while (scanf("%d", &n) != EOF){
  22. for (i = 0; i < n; i++){
  23. scanf("%d", &ar[i]);
  24. lim[i] = n;
  25. }
  26.  
  27. unsigned long long int res = 1;
  28. for (i = 0; i < n; i++){
  29. if (lim[i] > i){
  30. int c, d, x, y, counter = 0;
  31. for (j = i; j < lim[i]; j++){
  32. if (i == j) x = y = ar[j], c = d = j;
  33. if (ar[j] < x) x = ar[j], c = j;
  34. if (ar[j] > y) y = ar[j], d = j;
  35. if (i != j) res = (res * (y - x)) % MOD;
  36. counter++;
  37. }
  38.  
  39. if (counter < 2) continue;
  40. if (c > d) swap(c, d);
  41.  
  42. unsigned long long int p = 0, q = 0, z = 0;
  43. p = (lim[i] - d);
  44. q = (c - i);
  45. z = (p * q);
  46. res = (res * (bigmod(y - x, z))) % MOD;
  47. for (j = i + 1; j <= c; j++) lim[j] = d;
  48. }
  49. }
  50.  
  51. printf("%llu\n", res);
  52. }
  53. return 0;
  54. }
Success #stdin #stdout 0.01s 2456KB
stdin
Standard input is empty
stdout
Standard output is empty