Submission #31733

#TimeUsernameProblemLanguageResultExecution timeMemory
31733trathMonkey and Apple-trees (IZhO12_apple)C++14
0 / 100
0 ms2016 KiB
#include <bits/stdc++.h> using namespace std; #define F first #define S second #define mp make_pair #define pb push_back #define int long long #define ieps (int) 1e6 #define eps (int) 1e9 #define pii pair<int,int> int n , xp , yp; struct node{ bool flag = 0; int soma = 0; struct node *left , *right; node() : left(NULL) , right(NULL) {} void pullnewleft(){ if(!left){ left = new node(); } } void pullnewright(){ if(!right){ right = new node(); } } }; node *st = new node(); void update(int x , int y , node *curr , int l = 1 , int r = (int) 1e9){ if(curr->flag) return; if(x == l && y == r){ curr->flag = true; curr->soma = y - x + 1; return; } int mid = (l+r)/2; if(y <= mid){ curr->pullnewleft(); update(x , y , curr-> left , l ,mid); } else if(x > mid){ curr->pullnewright(); update(x , y, curr->right , mid + 1 , r); } else{ curr->pullnewright(); curr->pullnewleft(); update(x , mid , curr->left , l , mid); update(mid + 1 , y , curr->right , mid + 1 , r); } curr->flag = min(curr->left->flag , curr->right->flag); curr->soma = (curr->flag ? r - l + 1 : curr->left->soma + curr->right->soma); } int getsum(int x , int y , node *curr , int l = 1 , int r= (int) 1e9){ if(curr->flag) return y-x + 1; if(x == l && y == r){ return curr->soma; } int mid = (l+r)/2; if(y <= mid){ if(!(curr->left)) return curr->flag ? y - x + 1 : 0; return getsum(x , y , curr->left , l , mid ); } else if(x > mid){ if(!(curr -> right)) return curr->flag ? y - x + 1 : 0; return getsum(x , y , curr->right , mid + 1 , r); } else{ int t = 0; if(curr->left) t+= getsum(x , mid , curr->left , l ,mid); if(curr->right) t+= getsum(mid + 1 , y , curr->right , mid + 1 , r); if(!curr->left && !curr->right) return curr->flag ? y - x + 1 : 0; return t; } } int c = 0LL; int32_t main(){ int q; scanf("%lld" , &q); while(q--){ scanf("%lld%lld%lld" , &n ,&xp , &yp); if(n == 1){ c = getsum(xp + c , yp + c , st); printf("%lld\n" , c); } else{ update(xp + c , yp + c , st); } } }

Compilation message (stderr)

apple.cpp: In function 'int32_t main()':
apple.cpp:84:20: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%lld" , &q);
                    ^
apple.cpp:86:39: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%lld%lld%lld" , &n ,&xp , &yp);
                                       ^
#Verdict Execution timeMemoryGrader output
Fetching results...