Submission #468338

# Submission time Handle Problem Language Result Execution time Memory
468338 2021-08-27T18:07:35 Z jenishmonpara Monkey and Apple-trees (IZhO12_apple) C++14
0 / 100
426 ms 262148 KB
#include <bits/stdc++.h>
using namespace std;
long double PI = acos(-1);
long double DEL = 1e-12;
long long M =  1e9 + 7;
const long long N = 3e5 + 10;
#pragma GCC optimize ("unroll-loops")
#pragma GCC optimize("Ofast")
#pragma GCC optimize ("O3")
#pragma GCC target ("avx")
#define ftt cin>>tc;for(int cas=1;cas<=tc;++cas)
#define all(a) a.begin(),a.end()
#define sq(a) ((a)*(a))
#define double long double
#define dbg cout<<"\nhi\n";
#define int long long
#define nl cout<<"\n"
#define sp <<" "<<
#define mid ((l+r)>>1)
#define X real()
#define Y imag()


//*********************************** CHECK CONSTRAINTS ***********************************
int cnt, sum, mx, mn, ans, a[N], b[N];
int n, m, d, i, j, k, l, p, q, r, t, w, x, y, z, tc;
string s;



//************************************* CODE STARTS ****************************************

struct node{
        int lson,rson,s,lz;
        node():lson(-1),rson(-1),lz(0),s(0){}
};

vector<node> seg;

void push(int i,int l,int r){
        if(seg[i].lz == 0){
                return;
        }
        seg[i].s = r - l + 1;
        seg[i].lz = 0;
        if(l != r){
                if(seg[i].lson == -1){
                        seg[i].lson = seg.size();
                        seg.emplace_back();
//                        seg[seg[i].lson].s = mid - l + 1;
                }
                if(seg[i].rson == -1){
                        seg[i].rson = seg.size();
                        seg.emplace_back();
//                        seg[seg[i].rson].s = r - mid;
                }
                seg[seg[i].lson].lz = 1;
                seg[seg[i].rson].lz = 1;

        }
//        cout<<"_______" sp i sp l sp r;nl;
}

int query(int i,int l,int r,int a,int b){
        push(i,l,r);

        if(l > b or r < a or seg[i].s == 0){
                return 0;
        }
        if(a <= l and r <= b){
                return seg[i].s;
        }
        if(seg[i].lson == -1){
                return 0;
        }
        
        return query(seg[i].lson,l,mid,a,b) + query(seg[i].rson,mid+1,r,a,b);

}

void update(int i,int l,int r,int a,int b){
        push(i,l,r);

        if(l > b or r < a){
                return;
        }

        if(a <= l and r <= b){
                seg[i].lz = 1;
                push(i,l,r);
                return;
        }
        if(seg[i].lson == -1){
                seg[i].lson = seg.size();
                seg.emplace_back();
        }
        if(seg[i].rson == -1){
                seg[i].rson = seg.size();
                seg.emplace_back();
        }
        update(seg[i].lson,l,mid,a,b);
        update(seg[i].rson,mid+1,r,a,b);
        push(seg[i].lson,l,mid);
        push(seg[i].rson,mid+1,r);
        seg[i].s = seg[seg[i].lson].s + seg[seg[i].rson].s;
//        cout<<i sp l sp r sp seg[i].s sp seg[seg[i].lson].s sp seg[seg[i].rson].s sp seg[i].rson;nl;
}


int32_t main()
{
        ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

        seg.emplace_back();
        seg.emplace_back();
        int c = 0;
        ftt{
                cin>>t>>l>>r;
                if(t == 2){
                        update(1,0,2e9,l+c,r+c);
                }
                else{
                        c = query(1,0,2e9,l+c,r+c);
                        cout<<c;nl;
                }
        }
}




Compilation message

apple.cpp: In constructor 'node::node()':
apple.cpp:35:25: warning: 'node::lz' will be initialized after [-Wreorder]
   35 |         int lson,rson,s,lz;
      |                         ^~
apple.cpp:35:23: warning:   'long long int node::s' [-Wreorder]
   35 |         int lson,rson,s,lz;
      |                       ^
apple.cpp:36:9: warning:   when initialized here [-Wreorder]
   36 |         node():lson(-1),rson(-1),lz(0),s(0){}
      |         ^~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 21 ms 8768 KB Output is correct
5 Correct 25 ms 8848 KB Output is correct
6 Correct 25 ms 8784 KB Output is correct
7 Correct 25 ms 8832 KB Output is correct
8 Correct 188 ms 66848 KB Output is correct
9 Correct 398 ms 133548 KB Output is correct
10 Correct 392 ms 133136 KB Output is correct
11 Correct 416 ms 133008 KB Output is correct
12 Correct 426 ms 133040 KB Output is correct
13 Runtime error 419 ms 262148 KB Execution killed with signal 9
14 Halted 0 ms 0 KB -