didedoshka

omg debug doesn't work...

Oct 31st, 2020
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.53 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <algorithm>
  4. #include <queue>
  5. #include <cmath>
  6. #include <set>
  7. #include <stack>
  8. #include <bitset>
  9. #include <map>
  10. #include <ctime>
  11. #include <numeric>
  12.  
  13.  
  14. #ifndef M_PI
  15. #define M_PI 3.141592653589
  16. #endif
  17. #define int long long
  18. #define double long double
  19.  
  20. #ifdef TIME
  21. #define start cin.tie(NULL); cout.tie(NULL); cout.setf(ios::fixed); cout.precision(10); ios_base::sync_with_stdio(false);int32_t START = clock()
  22. #define finish cout << "\ntime: " << (clock() - START) / (CLOCKS_PER_SEC * 1.0); return 0
  23. #endif
  24.  
  25. #ifndef TIME
  26. #define start cin.tie(NULL); cout.tie(NULL); cout.setf(ios::fixed); cout.precision(10); ios_base::sync_with_stdio(false)
  27. #define finish return 0
  28. #endif
  29.  
  30. using namespace std;
  31.  
  32.  
  33. //vector input
  34. template<typename T>
  35. istream &operator>>(istream &is, vector<T> &vec) {
  36.     for (auto &i : vec) {
  37.         cin >> i;
  38.     }
  39.     return is;
  40. }
  41.  
  42. //pair output
  43. template<typename E>
  44. ostream &operator<<(ostream &os, pair<E, E> &t) {
  45.     os << t.first << ' ' << t.second;
  46.     return os;
  47. }
  48.  
  49. //"map" pair output
  50. template<typename E>
  51. ostream &operator<<(ostream &os, pair<const E, E> &t) {
  52.     os << t.first << ' ' << t.second;
  53.     return os;
  54. }
  55.  
  56. //vector output
  57. template<typename T>
  58. ostream &operator<<(ostream &os, vector<T> &vec) {
  59.     for (T i : vec) {
  60.         os << i << ' ';
  61.     }
  62.     return os;
  63. }
  64.  
  65. //2 dimensional vector output
  66. template<typename T>
  67. ostream &operator<<(ostream &os, vector<vector<T> > &vec) {
  68.     for (vector<T> i : vec) {
  69.         os << i << '\n';
  70.     }
  71.     return os;
  72. }
  73.  
  74. struct segtree {
  75.     struct node {
  76.         int mx;
  77.         int cnt;
  78.  
  79.         node() {
  80.             mx = 0;
  81.             cnt = 1;
  82.         }
  83.  
  84.         node(int m, int c) {
  85.             mx = m;
  86.             cnt = c;
  87.         }
  88.  
  89.         node operator+(node &b) const {
  90.             if (mx > b.mx) {
  91.                 return {mx, cnt};
  92.             } else if (mx == b.mx) {
  93.                 return {mx, cnt + b.cnt};
  94.             } else {
  95.                 return {b.mx, b.cnt};
  96.             }
  97.         }
  98.     };
  99.  
  100.     int n;
  101.     vector<node> tree;
  102.  
  103.     segtree(int nn) {
  104.         tree.resize(2 * nn);
  105.         n = nn;
  106.     }
  107.  
  108.     void set(int i, int x, int am) {
  109.         i += n;
  110.         node to_be_added = node(x, am);
  111.         tree[i] = tree[i] + to_be_added;
  112.         i /= 2;
  113.         while (i != 0) {
  114.             tree[i] = tree[2 * i] + tree[2 * i + 1];
  115.             i /= 2;
  116.         }
  117.     }
  118.  
  119.     pair<int, int> get(int l, int r) {
  120.         l += n;
  121.         r += n;
  122.         node ans;
  123.         while (l <= r) {
  124.             if (l % 2 == 1) {
  125.                 ans = ans + tree[l];
  126.                 l += 1;
  127.             }
  128.             if (r % 2 == 0) {
  129.                 ans = ans + tree[r];
  130.                 r -= 1;
  131.             }
  132.             l /= 2;
  133.             r /= 2;
  134.         }
  135.         return {ans.mx, ans.cnt};
  136.     }
  137. };
  138.  
  139. int32_t main() {
  140.     start;
  141.  
  142.     int n;
  143.     cin >> n;
  144.     vector<int> a(n);
  145.     cin >> a;
  146.     vector<int> coords = a;
  147.  
  148.     sort(coords.begin(), coords.end());
  149.     coords.resize(distance(coords.begin(), unique(coords.begin(), coords.end())));
  150.  
  151.     for (int i = 0; i < n; ++i) {
  152.         a[i] = distance(coords.begin(), lower_bound(coords.begin(), coords.end(), a[i]));
  153.     }
  154.  
  155.     cout << a << '\n';
  156.  
  157.     segtree sgt(coords.size());
  158.  
  159.     for (int i = 0; i < n; ++i) {
  160.         auto [ans, amount] = sgt.get(0, a[i] - 1);
  161.         sgt.set(i, ans + 1, amount);
  162.     }
  163.  
  164.     cout << sgt.get(0, coords.size() - 1).second << '\n';
  165.  
  166.     finish;
  167. }
Advertisement
Add Comment
Please, Sign In to add comment