fork download
  1. struct segment_tree
  2. {
  3. struct NODE{
  4. int st , EN, value;// start , end
  5.  
  6. void init(int L,int R){
  7. st = L, EN = R;
  8. if(L == R) value = a[L];
  9. }
  10. }g[3*N];
  11.  
  12. void fill_CN(NODE &CN, NODE &LN, NODE &RN) // fill_current_node
  13. {
  14. CN.value = LN.value + RN.value;
  15. }
  16.  
  17. void build(int CN,int L,int R)
  18. {
  19. g[CN].init(L,R);
  20.  
  21. if(L ==R ) return;
  22. int mid = (L+R)>>1;
  23. int LN = CN << 1;
  24.  
  25. build(LN,L,mid);
  26. build(LN|1,mid+1,R);
  27.  
  28. fill_CN (g[CN], g[LN] , g[LN|1]);
  29. }
  30.  
  31. void update(int CN, int pos,int val)
  32. {
  33. if(g[CN].st == g[CN].EN)
  34. {
  35. g[CN].value = val;
  36. return;
  37. }
  38.  
  39. int mid = (g[CN].st + g[CN].EN)>>1;
  40.  
  41. int LN = CN << 1 ;
  42. if(mid >= pos) update(LN, pos,val);
  43. else update(LN|1,pos,val);
  44.  
  45. fill_CN(g[CN], g[LN],g[LN|1]);
  46. }
  47.  
  48. int query(int CN, int L,int R)
  49. {
  50. int x = g[CN].st;
  51. int y = g[CN].EN;
  52. if(y < L || x > R) return 0;
  53.  
  54. if(L <= x && R >= y ) return g[CN].value;
  55.  
  56. int LN = CN<<1;
  57.  
  58. int ans = query(LN,L,R);
  59. ans += query(LN|1,L,R);
  60. return ans;
  61. }
  62.  
  63. } s_tree;
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp:10:10: error: ‘N’ was not declared in this scope
     }g[3*N];
          ^
prog.cpp: In member function ‘void segment_tree::NODE::init(int, int)’:
prog.cpp:8:31: error: ‘a’ was not declared in this scope
            if(L == R) value = a[L];
                               ^
prog.cpp: In member function ‘void segment_tree::build(int, int, int)’:
prog.cpp:19:9: error: ‘g’ was not declared in this scope
         g[CN].init(L,R);
         ^
prog.cpp: In member function ‘void segment_tree::update(int, int, int)’:
prog.cpp:33:12: error: ‘g’ was not declared in this scope
         if(g[CN].st == g[CN].EN)
            ^
prog.cpp:39:20: error: ‘g’ was not declared in this scope
         int mid = (g[CN].st + g[CN].EN)>>1;
                    ^
prog.cpp: In member function ‘int segment_tree::query(int, int, int)’:
prog.cpp:50:17: error: ‘g’ was not declared in this scope
         int x = g[CN].st;
                 ^
stdout
Standard output is empty