Advertisement
KinDeR___

Untitled

Apr 19th, 2024
15
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.24 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2.  
  3.  
  4. #pragma GCC optimize("conserve-stack")
  5. #pragma GCC optimize("unroll-loops")
  6. #pragma GCC optimize("Ofast")
  7. #pragma GCC optimize("-O3")
  8.  
  9.  
  10. #define all(x) x.begin(),x.end()
  11. #define rall(x) x.rbegin(),x.rend()
  12. #define ll long long
  13. #define ld long double
  14. #define pii pair<int,int>
  15. #define fi first
  16. #define se second
  17. #define isz(x) int(x.size())
  18. #define ull unsigned long long
  19. #define vld vector<ld>
  20. #define vull vector<ull>
  21. #define vvull vector<vull>
  22. #define vb vector<bool>
  23. #define vvb vector<vb>
  24. #define vvvb vector<vvb>
  25. #define vvvvb vector<vvvb>
  26. #define vvvvvb vector<vvvvb>
  27. #define vi vector<int>
  28. #define vll vector<ll>
  29. #define vch vector<char>
  30. #define vvch vector<vch>
  31. #define vvvch vector<vvch>
  32. #define vvi vector<vector<int>>
  33. #define vvvi vector<vvi>
  34. #define vvvvi vector<vvvi>
  35. #define vvvvvi vector<vvvvi>
  36. #define vvll vector<vector<ll>>
  37. #define vvvll vector<vvll>
  38. #define vvvvll vector<vvvll>
  39. #define vvvvvll vector<vvvvll>
  40. #define vpii vector<pair<int,int>>
  41. #define vvpii vector<vpii>
  42. #define vvvpii vector<vvpii>
  43. #define vvvvpii vector<vvvpii>
  44. #define forn(i,n) for(int i=0;i<(int)n;++i)
  45. #define pb push_back
  46.  
  47.  
  48. using namespace std;
  49.  
  50.  
  51. const double EPS = 1e-9;
  52. const int UNDEF = -1;
  53. const int MOD = 1e9 + 7;
  54. const int INF = 1e9;
  55.  
  56. vpii tree;
  57.  
  58. const pii E = {-2 * INF, -2 * INF};
  59.  
  60. pii get(int x, int lx, int rx, int l, int r){
  61. if(l <= lx && rx <= r){
  62. return tree[x];
  63. }
  64.  
  65. if(r <= lx || rx <= l){
  66. return E;
  67. }
  68.  
  69. int mid = (lx + rx) / 2;
  70.  
  71. pii left = get(2 * x + 1, lx, mid, l, r);
  72. pii right = get(2 * x + 2, mid, rx, l, r);
  73.  
  74. if(left.fi < right.fi){
  75. return right;
  76. } else if(left.fi > right.fi){
  77. return left;
  78. } else {
  79. return {left.fi, (0LL + left.se + right.se) % MOD};
  80. }
  81. }
  82.  
  83. void update(int x, int lx, int rx, int i, pii v){
  84. if(lx + 1 == rx){
  85. if(tree[x].fi == v.fi){
  86. tree[x] = {v.fi, (0LL + tree[x].se + v.se) % MOD};
  87. } else{
  88. tree[x] = v;
  89. }
  90.  
  91. return;
  92. }
  93.  
  94. int mid = (lx + rx) / 2;
  95.  
  96. if(i < mid){
  97. update(2 * x + 1, lx, mid, i, v);
  98. } else {
  99. update(2 * x + 2, mid, rx, i, v);
  100. }
  101.  
  102. pii left = tree[2 * x + 1];
  103. pii right = tree[2 * x + 2];
  104.  
  105. if(left.fi < right.fi){
  106. tree[x] = right;
  107. } else if(left.fi > right.fi){
  108. tree[x] = left;
  109. } else {
  110. tree[x] = {left.fi, (0LL + left.se + right.se) % MOD};
  111. }
  112. }
  113.  
  114. void solve(){
  115. int n; cin >> n;
  116.  
  117. vi a(n);
  118. forn(i,n) cin >> a[i];
  119.  
  120.  
  121. vi b(a);
  122. sort(all(b));
  123. b.erase(unique(all(b)), b.end());
  124.  
  125. tree.assign(4 * isz(b), E);
  126.  
  127. forn(i,n){
  128. int j = lower_bound(all(b), a[i]) - b.begin();
  129.  
  130. pii x = get(0, 0, isz(b), 0, j);
  131.  
  132. if(x == E){
  133. x = {0, 1};
  134. }
  135.  
  136. update(0, 0, isz(b), j, {x.fi + 1, x.se});
  137. }
  138.  
  139. cout << get(0, 0, isz(b), 0, isz(b)).se;
  140. }
  141.  
  142. int main() {
  143. ios::sync_with_stdio(false);
  144. cin.tie(nullptr);
  145.  
  146. freopen("input.txt", "r", stdin);
  147. freopen("output.txt", "w", stdout);
  148.  
  149. int t = 1;
  150. //cin >> t;
  151.  
  152. while (t--) {
  153. solve();
  154. }
  155.  
  156. return 0;
  157. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement