Advertisement
Korotkodul

ДО

Aug 13th, 2022 (edited)
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.44 KB | None | 0 0
  1. #include <iostream>
  2. #include <cmath>
  3. #include <vector>
  4. #include <queue>
  5. #include <algorithm>
  6. #include <string>
  7. #include <stack>
  8. #include <set>
  9. #include <map>
  10. #define pii pair <int,int>
  11. #define vec vector
  12. using namespace std;
  13. using ll = long long;
  14. using ld = long double;
  15. using db = double;
  16. void cv(vector <int> &v){
  17.     for (auto x: v) cout<<x<<' ';
  18.     cout<<"\n";
  19. }
  20.  
  21. void cvl(vector <ll> &v){
  22.     for (auto x: v) cout<<x<<' ';
  23.     cout<<"\n";
  24. }
  25.  
  26.  
  27. void cvv(vector <vector <int> > &v){
  28.     for (auto x: v) cv(x);
  29.     cout<<"\n";
  30. }
  31.  
  32. void cvb(vector <bool> v){
  33.     for (bool x: v) cout<<x<<' ';
  34.     cout<<"\n";
  35. }
  36.  
  37. void cvs(vector <string>  v){
  38.     for (auto a: v){
  39.         cout<<a<<"\n";
  40.     }
  41. }
  42.  
  43. void cvp(vector <pii> a){
  44.     for (auto p: a){
  45.         cout<<p.first<<' '<<p.second<<"\n";
  46.     }
  47.     cout<<"\n";
  48. }
  49.  
  50. bool sh = 1;
  51.  
  52. int n,N;
  53.  
  54. struct nd{
  55.     int mxl;
  56.     int Li, Ll;
  57.     int Ri, Rl;
  58. };
  59.  
  60. void see(nd k){
  61.     cout<<k.mxl<<" "<<k.Li<<" "<<k.Ll<<" "<<k.Ri<<" "<<k.Rl<<"\n";
  62. }
  63.  
  64. struct tree{
  65.     vector <nd> v;
  66.     void bld(){
  67.         cin>>n;
  68.         N = log2(n);
  69.         if (pow(2, N) < n){
  70.             N++;
  71.         }
  72.         N = pow(2, N);
  73.         v.assign(2*N - 1, {0, N + 10, 0, -10, 0});
  74.         for (int i = N - 1; i < N - 1 + n; ++i){
  75.             int x; cin>>x;
  76.             int id = i - (N - 1);
  77.             if (x == 0){
  78.                 nd k = {1, id, 1, id, 1};
  79.                 v[i] = k;
  80.             }
  81.         }
  82.  
  83.         if (sh){
  84.             cout<<"go\n";
  85.         }
  86.  
  87.         for (int i = N - 2; i >= 0; --i){
  88.             int un = -1;
  89.             v[i].Li = min(v[i*2 + 1].Li, v[i*2 + 2].Li);
  90.             v[i].Ll = v[2 * i + 1].Ll;
  91.             if (v[i].Ll == 0){
  92.                 v[i].Ll = v[2 * i + 2].Ll;
  93.             }
  94.             v[i].Ri = max(v[i*2 + 1].Ri, v[i*2 + 2].Ri);
  95.             v[i].Rl = v[2 * i + 2].Rl;
  96.             if (v[i].Rl == 0){
  97.                 v[i].Rl = v[2 * i + 1].Rl;
  98.             }
  99.             v[i].mxl = max(v[i * 2 + 1].mxl, v[i * 2 + 2].mxl);
  100.  
  101.             if (v[i * 2 + 1].Ri + 1 == v[i * 2 + 2].Li){
  102.                 un = v[i * 2 + 1].Rl + v[i * 2 + 2].Ll;
  103.                 //v[i].mxl = max(un, v[i].mxl);
  104.                 if (un > v[i].mxl){
  105.  
  106.                     v[i].mxl = un;
  107.                     if (sh){
  108.                         cout<<"un\n";
  109.                         cout<<"id = "<<i<<"\n";
  110.                         see(v[i * 2 + 1]);
  111.                         see(v[i * 2 + 2]);
  112.                     }
  113.                 }
  114.  
  115.                 //учесть - если объединили с краев
  116.                 if ( v[2*i + 1].Li + v[2 * i + 1].Ll - 1 == v[2 * i + 1].Ri){//слева только одна п-ть 0й
  117.                      v[i].Ll =  v[2 * i + 1].Rl + v[2 * i + 2].Ll;
  118.                 }
  119.                 if ( v[2*i + 2].Li + v[2 * i + 2].Ll - 1 == v[2 * i + 2].Ri){//слева только одна п-ть 0й
  120.                      v[i].Rl =  v[2 * i + 1].Rl + v[2 * i + 2].Ll;
  121.                 }
  122.  
  123.             }
  124.         }
  125.  
  126.         if (sh){
  127.             cout<<"v\n";
  128.             for (int i = 0; i < 2*N - 1; ++i){
  129.                 cout<<"id = "<<i<<"\n";
  130.                 see(v[i]);
  131.             }
  132.         }
  133.     }
  134.  
  135.  
  136.  
  137.  
  138. };
  139.  
  140.  
  141. int main()
  142. {
  143.     /*ios::sync_with_stdio(0);
  144.     cin.tie(0);
  145.     cout.tie(0);*/
  146.     int m;
  147.     tree T;
  148.     T.bld();
  149.     if (!sh) cin>>m;
  150.     for (int i = 0; i < m; ++i){
  151.         //запрос
  152.     }
  153. }
  154.  
  155. /*
  156.  
  157. 7
  158. 1 0 0 0 0 1 0
  159. */
  160.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement