#include<bits/stdc++.h>
using namespace std;
/// range sum query
struct node;
node *newNode();
struct node {
int lv, rv, sum;
node *left, *right;
node() : left(NULL), right(NULL), sum(0) {}
inline void init(int l, int r) {
lv = l;
rv = r;
}
inline void extend() {
if (!left) {
int m = (lv + rv) / 2;
left = newNode();
right = newNode();
left->init(lv, m);
right->init(m + 1, rv);
}
}
int getSum(int l, int r) {
if (r < lv || rv < l) {
return 0;
}
if (l <= lv && rv <= r) {
return sum;
}
extend();
return left->getSum(l, r) + right->getSum(l, r);
}
void update(int p, int newVal) {
if (lv == rv) {
sum = newVal;
return;
}
extend();
(p <= left->rv ? left : right)->update(p, newVal);
sum = left->sum + right->sum;
}
};
node *newNode() {
static int bufSize = 1e7;
static node buf[(int) 1e7];
assert(bufSize);
return &buf[--bufSize];
}
main() {
node *rmq = newNode();
rmq->init(0, 1e9);
/// do smth
}
I2luY2x1ZGU8Yml0cy9zdGRjKysuaD4KdXNpbmcgbmFtZXNwYWNlIHN0ZDsKCgovLy8gcmFuZ2Ugc3VtIHF1ZXJ5CgoKc3RydWN0IG5vZGU7Cm5vZGUgKm5ld05vZGUoKTsKCgpzdHJ1Y3Qgbm9kZSB7CiAgICBpbnQgbHYsIHJ2LCBzdW07CiAgICBub2RlICpsZWZ0LCAqcmlnaHQ7CgoKICAgIG5vZGUoKSA6IGxlZnQoTlVMTCksIHJpZ2h0KE5VTEwpLCBzdW0oMCkge30KCgogICAgaW5saW5lIHZvaWQgaW5pdChpbnQgbCwgaW50IHIpIHsKICAgICAgICBsdiA9IGw7CiAgICAgICAgcnYgPSByOwogICAgfQoKCiAgICBpbmxpbmUgdm9pZCBleHRlbmQoKSB7CiAgICAgICAgaWYgKCFsZWZ0KSB7CiAgICAgICAgICAgIGludCBtID0gKGx2ICsgcnYpIC8gMjsKICAgICAgICAgICAgbGVmdCA9IG5ld05vZGUoKTsKICAgICAgICAgICAgcmlnaHQgPSBuZXdOb2RlKCk7CiAgICAgICAgICAgIGxlZnQtPmluaXQobHYsIG0pOwogICAgICAgICAgICByaWdodC0+aW5pdChtICsgMSwgcnYpOwogICAgICAgIH0KICAgIH0KCgogICAgaW50IGdldFN1bShpbnQgbCwgaW50IHIpIHsKICAgICAgICBpZiAociA8IGx2IHx8IHJ2IDwgbCkgewogICAgICAgICAgICByZXR1cm4gMDsKICAgICAgICB9CgogICAgICAgIGlmIChsIDw9IGx2ICYmIHJ2IDw9IHIpIHsKICAgICAgICAgICAgcmV0dXJuIHN1bTsKICAgICAgICB9CgogICAgICAgIGV4dGVuZCgpOwogICAgICAgIHJldHVybiBsZWZ0LT5nZXRTdW0obCwgcikgKyByaWdodC0+Z2V0U3VtKGwsIHIpOwogICAgfQoKCiAgICB2b2lkIHVwZGF0ZShpbnQgcCwgaW50IG5ld1ZhbCkgewogICAgICAgIGlmIChsdiA9PSBydikgewogICAgICAgICAgICBzdW0gPSBuZXdWYWw7CiAgICAgICAgICAgIHJldHVybjsKICAgICAgICB9CgogICAgICAgIGV4dGVuZCgpOwogICAgICAgIChwIDw9IGxlZnQtPnJ2ID8gbGVmdCA6IHJpZ2h0KS0+dXBkYXRlKHAsIG5ld1ZhbCk7CiAgICAgICAgc3VtID0gbGVmdC0+c3VtICsgcmlnaHQtPnN1bTsKICAgIH0KfTsKCgpub2RlICpuZXdOb2RlKCkgewogICAgc3RhdGljIGludCBidWZTaXplID0gMWU3OwogICAgc3RhdGljIG5vZGUgYnVmWyhpbnQpIDFlN107CiAgICBhc3NlcnQoYnVmU2l6ZSk7CiAgICByZXR1cm4gJmJ1ZlstLWJ1ZlNpemVdOwp9CgoKbWFpbigpIHsKCW5vZGUgKnJtcSA9IG5ld05vZGUoKTsKCXJtcS0+aW5pdCgwLCAxZTkpOwovLy8gZG8gc210aAp9Cg==
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