#define COUNT 100000001
и используется просто подстановкой COUNT вместо 100000001)#define COUNT 100000001
int _stack[COUNT];
int _inc_delta[COUNT];
int *ps = _stack, const *ps_start = _stack, const *ps_end = _stack+COUNT;
void init() {
for (int *i=_inc_delta, *pid_end=_inc_delta+COUNT; i<pid_end; ++i)
*i=0;
}
}
void push(num) {
if (ps>=ps_end) {
return; // or throw an exception
}
*ps = num;
++ps;
}
void inc(cnt, delta) {
if (cnt > 0) {
if (cnt-1>=ps-ps_start) {
return; // or throw an exception;
}
_inc_delta[cnt-1] += delta;
}
// else thrown an exception;
}
int pop() {
if (ps<=ps_start) {
return 0; // or throw an exception;
}
--ps;
int ret, idz=ps-ps_start, idy=idz-1; // ret, current and previous
ret = *ps + _inc_delta[idz];
if (_inc_delta[idz] != 0) {
if (idy >= 0) {
// Save the latest delta in previous position
_inc_delta[idy] += _inc_delta[idz];
}
_inc_delta[idz] = 0;
}
return ret;
}