Submission #938971

#TimeUsernameProblemLanguageResultExecution timeMemory
938971vjudge1Monkey and Apple-trees (IZhO12_apple)C++17
0 / 100
255 ms262144 KiB
#include<bits/stdc++.h> using namespace std; struct node{ int sum, l, r, lazy, ll, lr; node(): sum(0), lazy(0), l(-1), r(-1){} }; node tr[1000000]; int temp=1; void create(int now){ int mid=(tr[now].ll+tr[now].lr)>>1; if (tr[now].l==-1){ tr[now].l=temp; tr[temp].ll=tr[now].ll; tr[temp].lr=mid; temp++; } if (tr[now].r==-1){ tr[now].r=temp; tr[temp].ll=mid+1; tr[temp].lr=tr[now].lr; temp++; } } void push(int now){ create(now); if (tr[now].lazy){ tr[now].sum=tr[now].lr-tr[now].ll+1; tr[tr[now].l].lazy=1; tr[tr[now].r].lazy=1; tr[now].lazy=0; } } void update(int now, int ql, int qr){ int l=tr[now].ll, r=tr[now].lr; push(now); if (ql<=l and r<=qr){ tr[now].lazy=1; push(now); } else{ int mid=(tr[now].ll+tr[now].lr)>>1; int cl=tr[now].l, cr=tr[now].r; if (ql<=mid) update(cl, ql, qr); if (qr>mid) update(cr, ql, qr); push(cl); push(cr); tr[now].sum=tr[cl].sum+tr[cr].sum; } } int get(int now, int ql, int qr){ int l=tr[now].ll, r=tr[now].lr; push(now); if (ql<=l and r<=qr){ return tr[now].sum; } else{ int mid=(tr[now].ll+tr[now].lr)>>1; int cl=tr[now].l, cr=tr[now].r; push(cl); push(cr); int a=0, b=0; if (ql<=mid) a=get(cl, ql, qr); if (qr>mid) b=get(cr, ql, qr); return a+b; } } int main(){ int m; cin>>m; tr[0].sum=0; tr[0].ll=1; tr[0].lr=1e9; int c=0; while(m--){ int d, x, y; cin>>d>>x>>y; if (d==1){ c=get(0, x+c, y+c); cout<<c<<endl; } else{ update(0, x+c, y+c); } } return 0; }

Compilation message (stderr)

apple.cpp: In constructor 'node::node()':
apple.cpp:5:17: warning: 'node::lazy' will be initialized after [-Wreorder]
    5 |  int sum, l, r, lazy, ll, lr;
      |                 ^~~~
apple.cpp:5:11: warning:   'int node::l' [-Wreorder]
    5 |  int sum, l, r, lazy, ll, lr;
      |           ^
apple.cpp:6:2: warning:   when initialized here [-Wreorder]
    6 |  node(): sum(0), lazy(0), l(-1), r(-1){}
      |  ^~~~
#Verdict Execution timeMemoryGrader output
Fetching results...