Submission #1297311

#TimeUsernameProblemLanguageResultExecution timeMemory
1297311saitamapunchesMonkey and Apple-trees (IZhO12_apple)C++20
100 / 100
369 ms205572 KiB
#include <bits/stdc++.h> using namespace std; #define ll long long int #define ld long double #define LLMAX LLONG_MAX #define LLMIN LLONG_MIN #include <algorithm> // sqrtl() __gcd() #include <numeric> #include <cmath> #include <iomanip>//to do setprecision(3) //pow(2LL,n) //float< double< long double //10^9+7=1e9+7 //stoi, stoll(for long long) /* You can do it!! because you have done it before. Dont worry today might not be your day. Start Fresh, Dry Run, Do Maths if you get stuck */ int max_n=1e9+10; struct Sparse_Seg_Tree{ struct Node{ ll sum=0,lazy=-1;// lazy=-1 means dont update range Node *left=NULL,*right=NULL; }; Node* root=new Node(); void apply(Node* node,int ss,int se,int x){ if(x==-1) return; ll len=se-ss+1; node->sum=len*x; node->lazy=x; } void push(Node* node,int ss,int se){ if(ss!=se){ int m=ss+(se-ss)/2; if(node->left==NULL) node->left=new Node(); if(node->right==NULL) node->right=new Node(); apply(node->left,ss,m,node->lazy); apply(node->right,m+1,se,node->lazy); } node->lazy=-1; } void update(Node* node,int ss,int se,int qs,int qe,int x){// pointers are passed by reference if(qe<ss or qs>se) return; if(qs<=ss and qe>=se){ apply(node,ss,se,x); return; } push(node,ss,se); int m=ss+(se-ss)/2; update(node->left,ss,m,qs,qe,x); update(node->right,m+1,se,qs,qe,x); node->sum=node->left->sum+node->right->sum; } ll query(Node *node,int ss,int se,int qs,int qe){ if(qe<ss or qs>se) return 0ll; if(qs<=ss and qe>=se){ return node->sum; } push(node,ss,se); int m=ss+(se-ss)/2; return query(node->left,ss,m,qs,qe)+query(node->right,m+1,se,qs,qe); } ll query(int qs,int qe){ return query(root,0,max_n,qs,qe); } void update(int qs,int qe,int x){ update(root,0,max_n,qs,qe,x); } }; void solve() { Sparse_Seg_Tree obj; int n,c=0;cin>>n; for(int i=0;i<n;i++){ int op,l,r;cin>>op>>l>>r; l+=c;r+=c; if(op==1){ c=obj.query(l,r); cout<<c<<endl; }else obj.update(l,r,1); } } void fast() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); } int main() { // #ifndef ONLINE_JUDGE // freopen("input.txt", "r", stdin); // freopen("output.txt", "w", stdout); // #endif fast(); int t=1; while (t--) { // cout << t; solve(); } //int x=10,a=3; //double d =ceil((1.0*x)/a); //cout <<fixed<< setprecision(22) << d; //fixed keeps the data in numeric and not scientefic i.e (1e) } /* ⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀ ⠀⠀⠀⠀⣠⣶⡾⠏⠉⠙⠳⢦⡀⠀⠀⠀⢠⠞⠉⠙⠲⡀⠀ ⠀⠀⠀⣴⠿⠏⠀⠀⠀⠀⠀⠀⢳⡀⠀ ⡏⠀⠀⠀⠀⠀⢷ ⠀⠀⢠⣟⣋⡀⢀⣀⣀⡀⠀⣀⡀⣧⠀⢸⠀⠀⠀⠀⠀ ⡇ ⠀⠀⢸⣯⡭ ⠸⣛⣟⠆⡴⣻⡲⣿⠀⣸⠀⠀OK⠀ ⡇ ⠀⠀⣟⣿⡭⠀⠀⠀⠀⠀⢱⠀⠀⣿⠀ ⢹⠀⠀⠀⠀⠀ ⡇ ⠀⠀⠙⢿⣯⠄⠀⠀⠀⢀⡀⠀⠀⡿⠀⠀⡇⠀⠀⠀ ⠀⡼ ⠀⠀⠀⠀⠹⣶⠆⠀⠀⠀⠀⠀⡴⠃⠀⠀ ⠘⠤⣄⣠⠞⠀ ⠀⠀⠀⠀⠀⢸⣷⡦⢤⡤⢤⣞⣁⠀⠀⠀ ⠀⠀⠀⠀⠀⠀⠀ ⠀⠀⢀⣤⣴⣿⣏⠁⠀⠀⠸⣏⢯⣷⣖⣦⡀⠀⠀⠀⠀⠀⠀ ⢀⣾⣽⣿⣿⣿⣿⠛⢲⣶⣾⢉⡷⣿⣿⠵⣿⠀⠀⠀⠀⠀⠀ ⣼⣿⠍⠉⣿⡭⠉⠙⢺⣇⣼⡏⠀⠀⠀⣄⢸⠀⠀⠀⠀⠀⠀ ⣿⣿⣧⣀⣿.........⣀⣰⣏⣘⣆⣀⠀⠀ */
#Verdict Execution timeMemoryGrader output
Fetching results...