Advertisement
umnov

Untitled

Jun 21st, 2018
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.90 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. signed main() {
  95.     ios_base::sync_with_stdio(false);
  96.     cin.tie(0);
  97.    
  98. #ifndef ONLINE_JUDGE
  99.     freopen("input.txt", "r", stdin);
  100.     freopen("output.txt", "w", stdout);
  101. #endif
  102.    
  103.    
  104.     cin >> n;
  105.    
  106.     a.resize(n,0);
  107.    
  108.     precalc();
  109.     modify(0, 5, 1);
  110.     cout << get_max(1, 2) << endl;
  111. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement