Submission #382608

# Submission time Handle Problem Language Result Execution time Memory
382608 2021-03-27T21:37:42 Z JerryLiu06 Monkey and Apple-trees (IZhO12_apple) C++11
0 / 100
229 ms 262148 KB
#include <bits/stdc++.h>
 
using namespace std;
 
struct Node {
    int sum, lazy; Node *lc, *rc;
     
    Node(): sum(0), lazy(0), lc(nullptr), rc(nullptr) {}
 
    void pushdown(int l, int r) { 
        if (!lazy || l == r) return ; int mid = (l + r) / 2;
        
        if (!lc) { lc = new Node(); lc -> lazy = 1; lc -> sum = mid - l + 1; }
        if (!rc) { rc = new Node(); rc -> lazy = 1; rc -> sum = r - mid; }
        
        lazy = 0;
    }
    void update(int l, int r, int tl, int tr) { int mid = (l + r) / 2;
        if (tl <= l && r <= tr) { lazy = 1; sum = r - l + 1; return ; } pushdown(l, r);
 
        if (tl > mid) { if (!rc) rc = new Node(); rc -> update(mid + 1, r, tl, tr); }
        
        else if (tr <= mid) { if (!lc) lc = new Node(); lc -> update(l, mid, tl, tr); }
        
        else { if (!lc) lc = new Node(); lc -> update(l, mid, tl, tr); if (!rc) rc = new Node(); rc -> update(mid + 1, r, tl, tr); }
        
        sum = 0; if (lc) sum += lc -> sum; if (rc) sum += rc -> sum;
    }
    int query(int l, int r, int tl, int tr) { int mid = (l + r) / 2;
        if (l > tr || r < tl) return 0; if (tl <= l && r <= tr) return sum; pushdown(l, r);
        
        return ((lc) ? (lc -> query(l, mid, tl, tr)) : 0) + ((rc) ? (rc -> query(mid + 1, r, tl, tr)) : 0);
    }
};
 
int M, C; Node root;
 
int main() {
    ios_base::sync_with_stdio(false); cin.tie(0);
 
    cin >> M;
 
    for (int i = 0; i < M; i++) { int D, X, Y; cin >> D >> X >> Y;
 
        if (D == 1) { C = root.query(1, 1e9, X + C, Y + C); cout << C << "\n"; }
 
        if (D == 2) root.update(1, 1e9, X + C, Y + C);
    }
}

Compilation message

apple.cpp: In member function 'void Node::pushdown(int, int)':
apple.cpp:11:9: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
   11 |         if (!lazy || l == r) return ; int mid = (l + r) / 2;
      |         ^~
apple.cpp:11:39: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if'
   11 |         if (!lazy || l == r) return ; int mid = (l + r) / 2;
      |                                       ^~~
apple.cpp: In member function 'int Node::query(int, int, int, int)':
apple.cpp:30:9: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
   30 |         if (l > tr || r < tl) return 0; if (tl <= l && r <= tr) return sum; pushdown(l, r);
      |         ^~
apple.cpp:30:41: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if'
   30 |         if (l > tr || r < tl) return 0; if (tl <= l && r <= tr) return sum; pushdown(l, r);
      |                                         ^~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 376 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Runtime error 229 ms 262148 KB Execution killed with signal 9
4 Halted 0 ms 0 KB -