fork download
  1. #include <iostream>
  2. #include <fstream>
  3. #include <cstdio>
  4. #include <iomanip>
  5. #include <utility>
  6. #include <cstdlib>
  7. #include <algorithm>
  8. using namespace std;
  9. const int N = 500500;
  10. const int mod = 1000000000;
  11. int n, a[N];
  12. long long ans = 0;
  13. int main ()
  14. {
  15.  
  16. scanf("%d", &n);
  17.  
  18. for (int i = 1; i <= n; ++ i) {
  19. scanf("%d", &a[i]);
  20. }
  21.  
  22. for (int i = 1; i <= n; ++ i) {
  23. int mn = a[i], mx = a[i];
  24. for (int j = i; j <= n; ++ j) {
  25. mn = min(mn, a[j]);
  26. mx = max(mx, a[j]);
  27. long long p = (mn * 1ll * mx) % mod;
  28. p = (p * (j - i + 1)) % mod;
  29. ans += p;
  30. if (ans >= mod) ans -= mod;
  31. }
  32. }
  33.  
  34. cout << ans;
  35.  
  36. return 0;
  37. }
Success #stdin #stdout 0s 5296KB
stdin
Standard input is empty
stdout
Standard output is empty