Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cmath>
- #include <vector>
- #include <queue>
- #include <algorithm>
- #include <string>
- #include <stack>
- #include <set>
- #include <map>
- #define pii pair <int,int>
- #define vec vector
- using namespace std;
- using ll = long long;
- using ld = long double;
- using db = double;
- void cv(vector <int> &v){
- for (auto x: v) cout<<x<<' ';
- cout<<"\n";
- }
- void cvl(vector <ll> &v){
- for (auto x: v) cout<<x<<' ';
- cout<<"\n";
- }
- void cvv(vector <vector <int> > &v){
- for (auto x: v) cv(x);
- cout<<"\n";
- }
- void cvb(vector <bool> v){
- for (bool x: v) cout<<x<<' ';
- cout<<"\n";
- }
- void cvs(vector <string> v){
- for (auto a: v){
- cout<<a<<"\n";
- }
- }
- void cvp(vector <pii> a){
- for (auto p: a){
- cout<<p.first<<' '<<p.second<<"\n";
- }
- cout<<"\n";
- }
- bool sh = 1;
- int n,N;
- struct nd{
- int mxl;
- int Li, Ll;
- int Ri, Rl;
- };
- void see(nd k){
- cout<<k.mxl<<" "<<k.Li<<" "<<k.Ll<<" "<<k.Ri<<" "<<k.Rl<<"\n";
- }
- struct tree{
- vector <nd> v;
- void bld(){
- cin>>n;
- N = log2(n);
- if (pow(2, N) < n){
- N++;
- }
- N = pow(2, N);
- v.assign(2*N - 1, {0, N + 10, 0, -10, 0});
- for (int i = N - 1; i < N - 1 + n; ++i){
- int x; cin>>x;
- int id = i - (N - 1);
- if (x == 0){
- nd k = {1, id, 1, id, 1};
- v[i] = k;
- }
- }
- if (sh){
- cout<<"go\n";
- }
- for (int i = N - 2; i >= 0; --i){
- int un = -1;
- v[i].Li = min(v[i*2 + 1].Li, v[i*2 + 2].Li);
- v[i].Ll = v[2 * i + 1].Ll;
- if (v[i].Ll == 0){
- v[i].Ll = v[2 * i + 2].Ll;
- }
- v[i].Ri = max(v[i*2 + 1].Ri, v[i*2 + 2].Ri);
- v[i].Rl = v[2 * i + 2].Rl;
- if (v[i].Rl == 0){
- v[i].Rl = v[2 * i + 1].Rl;
- }
- v[i].mxl = max(v[i * 2 + 1].mxl, v[i * 2 + 2].mxl);
- if (v[i * 2 + 1].Ri + 1 == v[i * 2 + 2].Li){
- un = v[i * 2 + 1].Rl + v[i * 2 + 2].Ll;
- //v[i].mxl = max(un, v[i].mxl);
- if (un > v[i].mxl){
- v[i].mxl = un;
- if (sh){
- cout<<"un\n";
- cout<<"id = "<<i<<"\n";
- see(v[i * 2 + 1]);
- see(v[i * 2 + 2]);
- }
- }
- //учесть - если объединили с краев
- if ( v[2*i + 1].Li + v[2 * i + 1].Ll - 1 == v[2 * i + 1].Ri){//слева только одна п-ть 0й
- v[i].Ll = v[2 * i + 1].Rl + v[2 * i + 2].Ll;
- }
- if ( v[2*i + 2].Li + v[2 * i + 2].Ll - 1 == v[2 * i + 2].Ri){//слева только одна п-ть 0й
- v[i].Rl = v[2 * i + 1].Rl + v[2 * i + 2].Ll;
- }
- }
- }
- if (sh){
- cout<<"v\n";
- for (int i = 0; i < 2*N - 1; ++i){
- cout<<"id = "<<i<<"\n";
- see(v[i]);
- }
- }
- }
- };
- int main()
- {
- /*ios::sync_with_stdio(0);
- cin.tie(0);
- cout.tie(0);*/
- int m;
- tree T;
- T.bld();
- if (!sh) cin>>m;
- for (int i = 0; i < m; ++i){
- //запрос
- }
- }
- /*
- 7
- 1 0 0 0 0 1 0
- */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement