Submission #955824

#TimeUsernameProblemLanguageResultExecution timeMemory
955824ZoTHMonkey and Apple-trees (IZhO12_apple)C++14
100 / 100
323 ms157260 KiB
#include <bits/stdc++.h> using namespace std; typedef unsigned long long ull; typedef long long ll; #define N "\n" #define all(object) object.begin(), object.end() #define sz(object) (int)object.size() #define ph push_back #define pp pop_back #define ss second #define ff first inline void ZoTH(string name = "") { ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr); if (sz(name)) { freopen((name + ".in").c_str(), "r", stdin); freopen((name + ".out").c_str(), "w", stdout); } } struct node { int sum , lft , rgt ; bool lazy ; node * left , * right ; node (int s,int _lft,int _rgt,node * l=nullptr, node* r=nullptr) { sum= s ; lft = _lft; rgt = _rgt ; left = l ; right = r ; lazy=0; } void mrg() { if(!lazy) sum =(left?left->sum:0)+(right?right->sum:0); else sum = rgt-lft+1; if(left) left->lazy |=lazy; if(right) right->lazy |=lazy ; } }; void update(node * at , ll lq,ll rq) { if(lq<=at->lft&&at->rgt<=rq) { at->lazy=1; at->mrg(); } else { int m =(at->lft+at->rgt)/2; int l = at->lft ; int r= at->rgt; if(lq<=m) { if(!at->left)at->left=new node(0,l,m); at->mrg(); update(at->left,lq,rq); } if(m+1<=rq) { if(!at->right)at->right=new node(0,m+1,r); at->mrg(); update(at->right,lq,rq) ; } at->mrg(); } } int take(node*at,int lq,int rq) { if(lq<=at->lft&&at->rgt<=rq) { at->mrg(); return at->sum; } int m =(at->lft+at->rgt)/2; int l = at->lft ; int r= at->rgt; int ret =0 ; if(lq<=m) { if(!at->left)at->left=new node(0,l,m); at->mrg(); ret+=take(at->left,lq,rq) ; } if(m+1<=rq) { if(!at->right)at->right=new node(0,m+1,r); at->mrg(); ret+=take(at->right,lq,rq) ; } at->mrg(); return ret ; } void solve(int t) { // Goooo const int n = (int)1e9+2; int m ; cin>>m ; node *root = new node (0,1,n); int c=0 ; while(m--) { int x ,t, y ; cin>>t>> x >> y ; if(t==1) { c = take(root,x+c,y+c); cout << c << N ; }else{ update(root,x+c,y+c); } } // stooo } int main() { ZoTH(""); // T_BEGIN int t = 1; // cin >> t; for (int i = 1; i <= t; i++) { // cout << "Case " << i << ": "; solve(i); cout << N; } }

Compilation message (stderr)

apple.cpp: In function 'void ZoTH(std::string)':
apple.cpp:22:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   22 |         freopen((name + ".in").c_str(), "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
apple.cpp:23:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   23 |         freopen((name + ".out").c_str(), "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...