fork download
  1. #include <bits/stdc++.h>
  2.  
  3. #define fast_io ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0)
  4. #define pb push_back
  5. #define mp make_pair
  6. #define all(v) (v).begin(), (v).end()
  7. #define rall(v) (v).rbegin(), (v).rend()
  8. #define forn(i, n) for(int (i) = 0; (i) < n; ++(i))
  9. #define fornr(i, from, to) for(int (i) = from; (i) <= to; ++(i))
  10. #define endl '\n'
  11.  
  12. using namespace std;
  13. using ll = long long;
  14. using ull = unsigned long long;
  15. using pii = pair < int, int >;
  16. using pll = pair < ll, ll >;
  17. using vi = vector < int >;
  18. using vii = vector < vi >;
  19.  
  20. template < typename T >
  21. std::ostream& operator<<(std::ostream& os, const std::vector < T > &vec)
  22. {
  23. forn(i, vec.size())
  24. os << vec[i] << ' ';
  25. return os;
  26. }
  27.  
  28.  
  29. ///////////
  30. //// ////
  31. ///////////
  32.  
  33. int main()
  34. {
  35. ios_base::sync_with_stdio(false);
  36. int64_t n;
  37. cin >> n;
  38.  
  39. vector < pair < int, int > > seq;
  40. seq.reserve(n);
  41.  
  42. int64_t ans = 0;
  43. int64_t cnt = 0;
  44. for(int i = 0; i < n; ++i)
  45. {
  46. int q;
  47. cin >> q;
  48.  
  49. vector < int > v(q);
  50. for(int &i : v)
  51. cin >> i;
  52.  
  53. int mn = 0;
  54. int mx = 0;
  55.  
  56. for(int j = 1; j < q; ++j)
  57. {
  58. if(v[j] < v[mn])
  59. mn = j;
  60. if(v[j] > v[mx])
  61. mx = j;
  62. }
  63.  
  64. bool ok = 1;
  65. for(int j = 1; j < q; ++j)
  66. if(!(v[j-1] >= v[j]))
  67. {
  68. ok = 0;
  69. break;
  70. }
  71.  
  72. if(ok)
  73. seq.push_back(make_pair(v[mn], v[mx]));
  74. else
  75. ++cnt;
  76.  
  77. }
  78. ans += cnt*cnt;
  79. ans += seq.size()*2*cnt;
  80.  
  81. sort(all(seq), [](pii &l, pii &r){
  82. return l.second < r.second;
  83. });
  84.  
  85.  
  86. for(int i = 0; i < seq.size(); ++i)
  87. {
  88. int l = -1, r = seq.size()-1;
  89. while(r - l > 1)
  90. {
  91. int mid = l + r >> 1;
  92.  
  93. if(seq[i].first < seq[mid].second)
  94. r = mid;
  95. else
  96. l = mid;
  97. }
  98. int to_add = seq.size()-r;
  99. bool b = 0;
  100. if(i >= r && seq[i].first == seq[i].second) --to_add, b = 1;
  101. ans += to_add;
  102. }
  103. cout << ans;
  104. return 0;
  105. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
Main.java:1: error: illegal character: '#'
    #include <bits/stdc++.h>
    ^
Main.java:1: error: class, interface, or enum expected
    #include <bits/stdc++.h>
             ^
Main.java:3: error: illegal character: '#'
    #define fast_io ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0)
    ^
Main.java:4: error: illegal character: '#'
    #define pb push_back
    ^
Main.java:5: error: illegal character: '#'
    #define mp make_pair
    ^
Main.java:6: error: illegal character: '#'
    #define all(v) (v).begin(), (v).end()
    ^
Main.java:7: error: illegal character: '#'
    #define rall(v) (v).rbegin(), (v).rend()
    ^
Main.java:8: error: illegal character: '#'
    #define forn(i, n) for(int (i) = 0; (i) < n; ++(i))
    ^
Main.java:8: error: class, interface, or enum expected
    #define forn(i, n) for(int (i) = 0; (i) < n; ++(i))
                                        ^
Main.java:8: error: class, interface, or enum expected
    #define forn(i, n) for(int (i) = 0; (i) < n; ++(i))
                                                 ^
Main.java:9: error: illegal character: '#'
    #define fornr(i, from, to) for(int (i) = from; (i) <= to; ++(i))
    ^
Main.java:9: error: class, interface, or enum expected
    #define fornr(i, from, to) for(int (i) = from; (i) <= to; ++(i))
                                                   ^
Main.java:9: error: class, interface, or enum expected
    #define fornr(i, from, to) for(int (i) = from; (i) <= to; ++(i))
                                                              ^
Main.java:10: error: illegal character: '#'
    #define endl '\n'
    ^
Main.java:13: error: class, interface, or enum expected
    using ll = long long;
    ^
Main.java:14: error: class, interface, or enum expected
    using ull = unsigned long long;
    ^
Main.java:15: error: class, interface, or enum expected
    using pii = pair < int, int >;
    ^
Main.java:16: error: class, interface, or enum expected
    using pll = pair < ll, ll >;
    ^
Main.java:17: error: class, interface, or enum expected
    using vi = vector < int >;
    ^
Main.java:18: error: class, interface, or enum expected
    using vii = vector < vi >;
    ^
Main.java:20: error: class, interface, or enum expected
    template < typename T >
    ^
Main.java:25: error: class, interface, or enum expected
        return os;
        ^
Main.java:26: error: class, interface, or enum expected
    }
    ^
Main.java:36: error: class, interface, or enum expected
        int64_t n;
        ^
Main.java:37: error: class, interface, or enum expected
        cin >> n;
        ^
Main.java:39: error: class, interface, or enum expected
        vector < pair < int, int > > seq;
        ^
Main.java:40: error: class, interface, or enum expected
        seq.reserve(n);
        ^
Main.java:42: error: class, interface, or enum expected
        int64_t ans = 0;
        ^
Main.java:43: error: class, interface, or enum expected
        int64_t cnt = 0;
        ^
Main.java:44: error: class, interface, or enum expected
        for(int i = 0; i < n; ++i)
        ^
Main.java:44: error: class, interface, or enum expected
        for(int i = 0; i < n; ++i)
                       ^
Main.java:44: error: class, interface, or enum expected
        for(int i = 0; i < n; ++i)
                              ^
Main.java:47: error: class, interface, or enum expected
            cin >> q;
            ^
Main.java:49: error: class, interface, or enum expected
            vector < int > v(q);
            ^
Main.java:50: error: class, interface, or enum expected
            for(int &i : v)
            ^
Main.java:53: error: class, interface, or enum expected
            int mn = 0;
            ^
Main.java:54: error: class, interface, or enum expected
            int mx = 0;
            ^
Main.java:56: error: class, interface, or enum expected
            for(int j = 1; j < q; ++j)
            ^
Main.java:56: error: class, interface, or enum expected
            for(int j = 1; j < q; ++j)
                           ^
Main.java:56: error: class, interface, or enum expected
            for(int j = 1; j < q; ++j)
                                  ^
Main.java:60: error: class, interface, or enum expected
                if(v[j] > v[mx])
                ^
Main.java:62: error: class, interface, or enum expected
            }
            ^
Main.java:65: error: class, interface, or enum expected
            for(int j = 1; j < q; ++j)
            ^
Main.java:65: error: class, interface, or enum expected
            for(int j = 1; j < q; ++j)
                           ^
Main.java:65: error: class, interface, or enum expected
            for(int j = 1; j < q; ++j)
                                  ^
Main.java:69: error: class, interface, or enum expected
                    break;
                    ^
Main.java:70: error: class, interface, or enum expected
                }
                ^
Main.java:74: error: class, interface, or enum expected
            else
            ^
Main.java:77: error: class, interface, or enum expected
        }
        ^
Main.java:79: error: class, interface, or enum expected
        ans += seq.size()*2*cnt;
        ^
Main.java:81: error: class, interface, or enum expected
        sort(all(seq), [](pii &l, pii &r){
        ^
Main.java:83: error: class, interface, or enum expected
        });
        ^
Main.java:86: error: class, interface, or enum expected
        for(int i = 0; i < seq.size(); ++i)
        ^
Main.java:86: error: class, interface, or enum expected
        for(int i = 0; i < seq.size(); ++i)
                       ^
Main.java:86: error: class, interface, or enum expected
        for(int i = 0; i < seq.size(); ++i)
                                       ^
Main.java:89: error: class, interface, or enum expected
            while(r - l > 1)
            ^
Main.java:93: error: class, interface, or enum expected
                if(seq[i].first < seq[mid].second)
                ^
Main.java:95: error: class, interface, or enum expected
                else
                ^
Main.java:97: error: class, interface, or enum expected
            }
            ^
Main.java:99: error: class, interface, or enum expected
            bool b = 0;
            ^
Main.java:100: error: class, interface, or enum expected
            if(i >= r && seq[i].first == seq[i].second) --to_add, b = 1;
            ^
Main.java:101: error: class, interface, or enum expected
            ans += to_add;
            ^
Main.java:102: error: class, interface, or enum expected
        }
        ^
Main.java:104: error: class, interface, or enum expected
        return 0;
        ^
Main.java:105: error: class, interface, or enum expected
    }
    ^
65 errors
stdout
Standard output is empty