Submission #93462

#TimeUsernameProblemLanguageResultExecution timeMemory
93462Aydarov03Monkey and Apple-trees (IZhO12_apple)C++11
0 / 100
130 ms156920 KiB
#include <bits/stdc++.h> using namespace std; const int N = 1e5+5; vector <int> ans; struct st { int l , r , val; bool add; st() { l = r = val = add = 0; } }tree[N * 100]; int cnt = 1; void push( int v , int tl , int tr ) { if(tree[v].add){ cout << tl << " - " << tr << endl; if(tl != tr){ if(!tree[v].l) tree[v].l = ++ cnt; if(!tree[v].r) tree[v].r = ++ cnt; tree[ tree[v].l ].add = tree[ tree[v].r ].add = 1; } tree[v].val = tr - tl + 1; } } void upd( int l , int r , int v = 1 , int tl = 1 , int tr = 1e9 ) { push( v , tl , tr ); if( tl > r || l > tr )return; if(l <= tl && tr <= r) { cout << "add - " << tl << " " << tr << endl; tree[v].add = 1; push( v , tl , tr ); return; } int tm = (tl + tr) >> 1; upd( l , r , tree[v].l , tl , tm ); upd( l , r , tree[v].r , tm+1 , tr ); tree[v].val = tree[ tree[v].l ].val + tree[ tree[v].r ].val; } int get( int l , int r , int v = 1 , int tl = 1 , int tr = 1e9) { push( v , tl , tr ); if( tl > r || tr < l ) return 0; if( l <= tl && tr <= r ) { return tree[v].val; } int tm = (tl + tr) >> 1; return get( l , r , tree[v].l , tl , tm ) + get( l , r , tree[v].r , tm+1 , tr ); } main() { upd(5, 8); //upd(1, 5); cout << get(1, 2) << endl; int t , c = 0; cin >> t; while( t-- ) { int tp , l , r; scanf("%d%d%d" , &tp , &l , &r ); l += c , r += c; if( tp == 1 ) { cout << ( c = get( l , r ) ) << endl; } if( tp == 2 ) upd(l , r); } }

Compilation message (stderr)

apple.cpp:70:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
 main()
      ^
apple.cpp: In function 'int main()':
apple.cpp:83:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d%d%d" , &tp , &l , &r );
   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...