Блог пользователя PassingBy

Автор PassingBy, история, 10 лет назад, По-русски

24455084.

It works on my computer and on cpp.sh.

  • Проголосовать: нравится
  • +8
  • Проголосовать: не нравится

»
10 лет назад, скрыть # |
 
Проголосовать: нравится +1 Проголосовать: не нравится

It's not recommended to use something like left->get_size() when you know that left can be equal to nullptr. It's undefined behaviour, so crashes on Codeforces.

It works on my computer and on cpp.sh.

cpp.sh uses an old version of GCC (4.9.2). In newer versions, compiler makes some optimizations with this, so the program crashes.

Consider using something like this:

        static size_t get_size(Node* node) {
            return (node == nullptr) ? 0 : (node->size);
        }

        void update() {
            size = get_size(left) + get_size(right) + 1;
        }

I didn't submit it, but in Codeforces' "Custom invocation" it works and gives correct answer :)