Submission #382308

# Submission time Handle Problem Language Result Execution time Memory
382308 2021-03-27T03:57:06 Z JerryLiu06 Monkey and Apple-trees (IZhO12_apple) C++11
0 / 100
508 ms 262148 KB
#include <bits/stdc++.h>

using namespace std;

struct Node {
    int sum, l, r, lazy; Node *lc, *rc;

    Node(int L, int R): sum(0), l(L), r(R), lc(NULL), rc(NULL) {}

    void pushdown() {
        if (!lazy) return ; sum = r - l + 1; int mid = (l + r) / 2;

        if (l < r) { if (!lc) lc = new Node(l, mid); lc -> lazy = lazy; if (!rc) rc = new Node(mid + 1, r); rc -> lazy = lazy; } lazy = 0;
    }
    void update(int tl, int tr) { int mid = (l + r) / 2;
        pushdown(); if (l > tr || r < tl) return ; if (tl <= l && r <= tr) { lazy = 1; return ; }

        if (tl > mid) { if (!rc) rc = new Node(mid + 1, r); rc -> update(tl, tr); }
        
        else if (tr <= mid) { if (!lc) lc = new Node(l, mid); lc -> update(tl, tr); }
        
        else { if (!lc) lc = new Node(l, mid); lc -> update(tl, mid); if (!rc) rc = new Node(mid + 1, r); rc -> update(mid + 1, tr); }
        
        if (lc) lc -> pushdown(); if (rc) rc -> pushdown();

        sum = 0; if (lc) sum += lc -> sum; if (rc) sum += rc -> sum;
    }
    int query(int tl, int tr) { int mid = (l + r) / 2;
        pushdown(); if (l > tr || r < tl) return 0; if (tl <= l && r <= tr) return sum;

        int res = 0; if (lc) res += lc -> query(tl, tr); if (rc) res += rc -> query(tl, tr); return res;
    }
};

int M, C; Node *root;

int main() {
    ios_base::sync_with_stdio(false); cin.tie(0);

    cin >> M; root = new Node(1, 1000000000);

    for (int i = 0; i < M; i++) { int D, X, Y; cin >> D >> X >> Y;

        if (D == 1) { C = root -> query(X + C, Y + C); cout << C << "\n"; }

        if (D == 2) root -> update(X + C, Y + C);
    }
}

Compilation message

apple.cpp: In member function 'void Node::pushdown()':
apple.cpp:11:9: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
   11 |         if (!lazy) return ; sum = r - l + 1; int mid = (l + r) / 2;
      |         ^~
apple.cpp:11:29: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if'
   11 |         if (!lazy) return ; sum = r - l + 1; int mid = (l + r) / 2;
      |                             ^~~
apple.cpp: In member function 'void Node::update(int, int)':
apple.cpp:24:9: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
   24 |         if (lc) lc -> pushdown(); if (rc) rc -> pushdown();
      |         ^~
apple.cpp:24:35: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if'
   24 |         if (lc) lc -> pushdown(); if (rc) rc -> pushdown();
      |                                   ^~
apple.cpp: In member function 'int Node::query(int, int)':
apple.cpp:28:37: warning: unused variable 'mid' [-Wunused-variable]
   28 |     int query(int tl, int tr) { int mid = (l + r) / 2;
      |                                     ^~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 21 ms 8556 KB Output is correct
5 Correct 26 ms 10476 KB Output is correct
6 Correct 26 ms 10092 KB Output is correct
7 Correct 26 ms 10348 KB Output is correct
8 Correct 211 ms 77036 KB Output is correct
9 Correct 431 ms 131104 KB Output is correct
10 Correct 470 ms 147080 KB Output is correct
11 Correct 462 ms 159468 KB Output is correct
12 Correct 472 ms 165100 KB Output is correct
13 Correct 437 ms 205164 KB Output is correct
14 Correct 458 ms 207084 KB Output is correct
15 Runtime error 508 ms 262148 KB Execution killed with signal 9
16 Halted 0 ms 0 KB -