Advertisement
bibaboba12345

Untitled

Mar 31st, 2023
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.90 KB | None | 0 0
  1. // clang-format off
  2. #define _CRT_SECURE_NO_WARNINGS
  3. #include <iostream>
  4. #include <iomanip>
  5. #include <bitset>
  6. #include <vector>
  7. #include <algorithm>
  8. #include <random>
  9. #include <map>
  10. #include <string>
  11. #include <set>
  12. #include <deque>
  13. #include <string>
  14. #include <cassert>
  15.  
  16. #pragma GCC optimize("Ofast")
  17.  
  18. using namespace std;
  19. const int N = 3e3 + 7, MOD = 998244353, A = 26;
  20. const long double EPS = 1e-10, PI = acos(-1);
  21. int n, m,q;
  22.  
  23. int a[N];
  24. int cnt_less[N][N];
  25.  
  26. int Get_Less(int l, int r, int x) {
  27. if (l == 0) {
  28. return cnt_less[x][r];
  29. }
  30. return cnt_less[x][r] - cnt_less[x][l - 1];
  31. }
  32.  
  33. signed main() {
  34. #ifdef _DEBUG
  35. freopen("input.txt", "r", stdin);
  36. #else
  37. std::ios::sync_with_stdio(false);
  38. cin.tie(0);
  39. #endif
  40. cin >> n;
  41. for (int i = 0; i < n; i++) {
  42. cin >> a[i];
  43. }
  44. for (int i = 0; i < n; i++) {
  45. if (i == 0){
  46. for (int j = 0; j <= a[i]; j++) {
  47. cnt_less[j][i] = 0;
  48. }
  49. for (int j = a[i] + 1; j <= n; j++) {
  50. cnt_less[j][i] = 1;
  51. }
  52. }
  53. else {
  54. for (int j = 0; j <= n; j++) {
  55. cnt_less[j][i] = cnt_less[j][i - 1];
  56. if (a[i] < j) {
  57. cnt_less[j][i]++;
  58. }
  59. }
  60. }
  61. }
  62. long long ANSW = 0;
  63. for (int i = 0; i < n; i++) {
  64. for (int j = i + 1; j < n; j++) {
  65. //cout << i + 1 << " " << j + 1 << " ";
  66. if (i + 1 == 2 && j + 1 == 4) {
  67. cout << "";
  68. }
  69. int d = j - i;
  70. int nw_i = Get_Less(0, i, a[i]);
  71. d = max(d, j - nw_i);
  72. int nw_j = j + Get_Less(j, n - 1, a[j]);
  73. d = max(d, nw_j - i);
  74. d = max(d, abs(a[i] - a[j]));
  75. ANSW += d;
  76. //cout << d << "\n";
  77. }
  78. }
  79. cout << ANSW;
  80.  
  81. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement