fork(27) download
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3.  
  4.  
  5. /// range sum query
  6.  
  7.  
  8. struct node;
  9. node *newNode();
  10.  
  11.  
  12. struct node {
  13. int lv, rv, sum;
  14. node *left, *right;
  15.  
  16.  
  17. node() : left(NULL), right(NULL), sum(0) {}
  18.  
  19.  
  20. inline void init(int l, int r) {
  21. lv = l;
  22. rv = r;
  23. }
  24.  
  25.  
  26. inline void extend() {
  27. if (!left) {
  28. int m = (lv + rv) / 2;
  29. left = newNode();
  30. right = newNode();
  31. left->init(lv, m);
  32. right->init(m + 1, rv);
  33. }
  34. }
  35.  
  36.  
  37. int getSum(int l, int r) {
  38. if (r < lv || rv < l) {
  39. return 0;
  40. }
  41.  
  42. if (l <= lv && rv <= r) {
  43. return sum;
  44. }
  45.  
  46. extend();
  47. return left->getSum(l, r) + right->getSum(l, r);
  48. }
  49.  
  50.  
  51. void update(int p, int newVal) {
  52. if (lv == rv) {
  53. sum = newVal;
  54. return;
  55. }
  56.  
  57. extend();
  58. (p <= left->rv ? left : right)->update(p, newVal);
  59. sum = left->sum + right->sum;
  60. }
  61. };
  62.  
  63.  
  64. node *newNode() {
  65. static int bufSize = 1e7;
  66. static node buf[(int) 1e7];
  67. assert(bufSize);
  68. return &buf[--bufSize];
  69. }
  70.  
  71.  
  72. main() {
  73. node *rmq = newNode();
  74. rmq->init(0, 1e9);
  75. /// do smth
  76. }
  77.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
Main.java:1: error: illegal character: '#'
#include<bits/stdc++.h>
^
Main.java:1: error: class, interface, or enum expected
#include<bits/stdc++.h>
        ^
Main.java:8: error: class, interface, or enum expected
struct node;
^
Main.java:9: error: class, interface, or enum expected
node *newNode();
^
Main.java:12: error: class, interface, or enum expected
struct node {
^
Main.java:14: error: class, interface, or enum expected
    node *left, *right;
    ^
Main.java:17: error: class, interface, or enum expected
    node() : left(NULL), right(NULL), sum(0) {}
    ^
Main.java:22: error: class, interface, or enum expected
        rv = r;
        ^
Main.java:23: error: class, interface, or enum expected
    }
    ^
Main.java:29: error: class, interface, or enum expected
            left = newNode();
            ^
Main.java:30: error: class, interface, or enum expected
            right = newNode();
            ^
Main.java:31: error: class, interface, or enum expected
            left->init(lv, m);
            ^
Main.java:32: error: class, interface, or enum expected
            right->init(m + 1, rv);
            ^
Main.java:33: error: class, interface, or enum expected
        }
        ^
Main.java:40: error: class, interface, or enum expected
        }
        ^
Main.java:44: error: class, interface, or enum expected
        }
        ^
Main.java:47: error: class, interface, or enum expected
        return left->getSum(l, r) + right->getSum(l, r);
        ^
Main.java:48: error: class, interface, or enum expected
    }
    ^
Main.java:54: error: class, interface, or enum expected
            return;
            ^
Main.java:55: error: class, interface, or enum expected
        }
        ^
Main.java:58: error: class, interface, or enum expected
        (p <= left->rv ? left : right)->update(p, newVal);
        ^
Main.java:59: error: class, interface, or enum expected
        sum = left->sum + right->sum;
        ^
Main.java:60: error: class, interface, or enum expected
    }
    ^
Main.java:64: error: class, interface, or enum expected
node *newNode() {
^
Main.java:66: error: class, interface, or enum expected
    static node buf[(int) 1e7];
           ^
Main.java:67: error: as of release 1.4, 'assert' is a keyword, and may not be used as an identifier
    assert(bufSize);
    ^
  (use -source 1.3 or lower to use 'assert' as an identifier)
Main.java:68: error: class, interface, or enum expected
    return &buf[--bufSize];
    ^
Main.java:69: error: class, interface, or enum expected
}
^
Main.java:74: error: class, interface, or enum expected
	rmq->init(0, 1e9);
	^
Main.java:76: error: class, interface, or enum expected
}
^
30 errors
stdout
Standard output is empty