Submission #991607

#TimeUsernameProblemLanguageResultExecution timeMemory
991607yusuf12360Monkey and Apple-trees (IZhO12_apple)C++14
100 / 100
285 ms206928 KiB
#include<bits/stdc++.h> #define ld long double #define pii pair<int, int> #define vi vector<int> #define vvi vector<vi> #define pb push_back #define fi first #define se second #define TII tuple<int, int, int> #define ts to_string #pragma gcc optimize("O3"); using namespace std; const int INF=1e9; struct node{ int l, r, sum=0, lazy=0; node *left=nullptr, *right=nullptr; node(int l, int r) : l(l), r(r) {} void extend() { if(l==r) return; int mid=l+r>>1; if(!left) left=new node(l, mid); if(!right) right=new node(mid+1, r); } void push() { if(l==r) return; extend(); if(lazy) { left->lazy=1; left->sum=left->r-left->l+1; right->lazy=1; right->sum=right->r-right->l+1; lazy=0; } } void update(int ql, int qr) { if(max(l, ql)>min(r, qr)) return; if(ql<=l && r<=qr) {lazy=1; sum=r-l+1; return;} push(); left->update(ql, qr); right->update(ql, qr); sum=left->sum+right->sum; } int get(int ql, int qr) { if(max(l, ql)>min(r, qr)) return 0; if(ql<=l && r<=qr) return sum; push(); return left->get(ql, qr)+right->get(ql, qr); } }; int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); int m, c=0; cin >> m; node *root = new node(1, INF); while(m--) { int type, ql, qr; cin >> type >> ql >> qr; if(type==1) c=root->get(ql+c, qr+c), cout << c << '\n'; else root->update(ql+c, qr+c); } return 0; }

Compilation message (stderr)

apple.cpp:11: warning: ignoring '#pragma gcc optimize' [-Wunknown-pragmas]
   11 | #pragma gcc optimize("O3");
      | 
apple.cpp: In member function 'void node::extend()':
apple.cpp:21:18: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   21 |         int mid=l+r>>1;
      |                 ~^~
#Verdict Execution timeMemoryGrader output
Fetching results...