Submission #1100152

#TimeUsernameProblemLanguageResultExecution timeMemory
1100152spycoderytMonkey and Apple-trees (IZhO12_apple)C++17
0 / 100
1 ms348 KiB
#include <bits/stdc++.h> #define int long long using namespace std; class tree{ // keeps the god struct node{ node* l = nullptr; node* r = nullptr; int val=0,lz=0; }; typedef node* pnode; public: pnode rt = nullptr; void upd(pnode t,int l,int r) { if(t->lz) { if(!t->l) t->l = new node(); if(!t->r) t->r = new node(); t->l->lz=1; t->r->lz=1; t->val+=(r-l+1); t->lz=0; } } int query(pnode& t,int l,int r,int ll,int rr) { if(l>r || r < ll || l > rr)return 0; if(!t) t = new node(); upd(t,l,r); if(l>=ll && r<=rr) return t->val; int mid = l + (r-l)/2; return query(t->l,l,mid,ll,rr) + query(t->r,mid+1,r,ll,rr); } void upd(pnode& t,int l,int r,int ll,int rr) { if(l>r || r < ll || l > rr)return; if(!t) t = new node(); upd(t,l,r); if(l>=ll && r<=rr) { t->lz = 1; upd(t,l,r); return; } int mid = l + (r-l)/2; upd(t->l,l,mid,ll,rr); upd(t->r,mid+1,r,ll,rr); t->val = (t->l?t->l->val:0) + (t->r?t->r->val:0); } }t; int32_t main() { int q,a,b,c,val=0;cin>>q; while(q--) { cin>>a>>b>>c; if(a==1) { val = t.query(t.rt,1,1e9,b+val,c+val); cout << val << "\n"; } else { t.upd(t.rt,1,1e9,b+val,c+val); } } } /* 4 2 2 3 1 1 3 2 2 3 1 -1 3 3 2 5 8 2 7 10 1 1 10 2 2 1 10 1 1 100 */
#Verdict Execution timeMemoryGrader output
Fetching results...