Advertisement
umnov

Untitled

Jun 21st, 2018
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.88 KB | None | 0 0
  1. #include <iostream>
  2. #include <ctime>
  3. #include <iomanip>
  4. #include <vector>
  5. #include <map>
  6. #include <algorithm>
  7. #include <string>
  8. #include <cmath>
  9. #include <set>
  10. #include <unordered_set>
  11. #include <stack>
  12. #include <cassert>
  13. #include <queue>
  14. #include <deque>
  15.  
  16. using namespace std;
  17.  
  18. typedef long long ll;
  19. typedef long double ld;
  20.  
  21.  
  22. //#define int long long
  23. const int inf=1e9+1329;
  24.  
  25. const int len=3;
  26.  
  27. int n;
  28. int ind=1;
  29. vector<int> blocks;
  30. vector<int> a;
  31.  
  32. vector<pair<int, int>> colors(1);
  33.  
  34.  
  35.  
  36. void update(int cur,int &to_update){
  37. to_update=max(cur,to_update);
  38. }
  39.  
  40. void update_block(int cur){
  41. int l=cur*len;
  42. for(int i=l;i<l+len;i++){
  43. update(a[i], blocks[cur]);
  44. }
  45. }
  46.  
  47. void precalc(){
  48. while (n%len!=0) {
  49. n++;
  50. a.push_back(0);
  51. }
  52. blocks.assign(n/len, 0);
  53. for(int i=0;i<n;i++){
  54. update(a[i], blocks[i/len]);
  55. }
  56. }
  57.  
  58. int get_max(int l,int r){
  59. //полуинтервалы
  60. int ans=0;
  61. for(int i=l;i<r;){
  62. if(i%len==0 && i+len<r){
  63. update(blocks[i/len], ans);
  64. i+=len;
  65. }
  66. else{
  67. update(a[i], ans);
  68. i++;
  69. }
  70. }
  71. return ans;
  72. }
  73.  
  74. void modify(int l,int r,int val){
  75. //полуинтервал
  76. for(int i=l;i<r;){
  77. if(i%len==0 && i+len<r){
  78. blocks[i/len]=val;
  79. i+=len;
  80. }
  81. else{
  82. a[i]=val;
  83. i++;
  84. }
  85. }
  86. if(l%len!=0){
  87. update_block(l/len);
  88. }
  89. if((r-1)%len!=0){
  90. update_block((r-1)/len);
  91. }
  92. }
  93.  
  94. /*void query_merge(int l,int r){
  95. auto mx=get_max(l, r);
  96. if(mx!=0){
  97. cout << "0\n";
  98. return;
  99. }
  100. cout << "1\n";
  101. colors.push_back({l,r-1}); //включительно!!!!!!
  102. modify(l, r, ind);
  103. ind++;
  104. }
  105.  
  106. void query_split(int pos){
  107. int cur_color=get_max(pos, pos+1);
  108. if(cur_color==0){
  109. cout << "0 0\n";
  110. return;
  111. }
  112. int l=colors[cur_color].first;
  113. int r=colors[cur_color].second;
  114. if(l==-1 && r==-1){
  115. cout << "0 0\n";
  116. return;
  117. }
  118. cout << l+1 << " " << r+1 << "\n";
  119. modify(l, r+1, 0);
  120. colors[cur_color]={-1,-1};
  121. }*/
  122.  
  123. signed main() {
  124. ios_base::sync_with_stdio(false);
  125. cin.tie(0);
  126.  
  127. #ifndef ONLINE_JUDGE
  128. freopen("input.txt", "r", stdin);
  129. freopen("output.txt", "w", stdout);
  130. #endif
  131.  
  132.  
  133. cin >> n;
  134.  
  135. a.resize(n,0);
  136.  
  137. precalc();
  138.  
  139. /*int q;
  140. cin >> q;
  141. while (q--) {
  142. int tp;
  143. cin >> tp;
  144. if(tp==1){
  145. int l,r;
  146. cin >> l >> r;
  147. l--;
  148. query_merge(l, r);
  149. }
  150. else{
  151. int pos;
  152. cin >> pos;
  153. pos--;
  154. query_split(pos);
  155. }
  156. }*/
  157. modify(0, 5, 1);
  158. cout << get_max(1, 2) << endl;
  159. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement