답안 #382606

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
382606 2021-03-27T21:24:34 Z JerryLiu06 원숭이와 사과 나무 (IZhO12_apple) C++11
0 / 100
545 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), lazy(0), l(L), r(R), lc(nullptr), rc(nullptr) {}
 
    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 = 1; lc -> sum = mid - l + 1;
            if (!rc) rc = new Node(mid + 1, r); rc -> lazy = 1; rc -> sum = r - mid;
        } 
        lazy = 0;
    }
    void update(int tl, int tr) { int mid = (l + r) / 2;
        pushdown(); if (tl <= l && r <= tr) { lazy = 1; pushdown(); 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, tr); if (!rc) rc = new Node(mid + 1, r); rc -> update(tl, tr); }
        
        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;
        
        return ((lc) ? (lc -> query(tl, tr)) : 0) + ((rc) ? (rc -> query(tl, tr)) : 0);
    }
};
 
int M, C; Node root(1, 1000000000);
 
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(X + C, Y + C); cout << C << "\n"; }
 
        if (D == 2) root.update(X + C, Y + C);
    }
}

Compilation message

apple.cpp: In constructor 'Node::Node(int, int)':
apple.cpp:6:20: warning: 'Node::lazy' will be initialized after [-Wreorder]
    6 |     int sum, l, r, lazy; Node *lc, *rc;
      |                    ^~~~
apple.cpp:6:14: warning:   'int Node::l' [-Wreorder]
    6 |     int sum, l, r, lazy; Node *lc, *rc;
      |              ^
apple.cpp:8:5: warning:   when initialized here [-Wreorder]
    8 |     Node(int L, int R): sum(0), lazy(0), l(L), r(R), lc(nullptr), rc(nullptr) {}
      |     ^~~~
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:14:13: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
   14 |             if (!lc) lc = new Node(l, mid); lc -> lazy = 1; lc -> sum = mid - l + 1;
      |             ^~
apple.cpp:14:45: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if'
   14 |             if (!lc) lc = new Node(l, mid); lc -> lazy = 1; lc -> sum = mid - l + 1;
      |                                             ^~
apple.cpp:15:13: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
   15 |             if (!rc) rc = new Node(mid + 1, r); rc -> lazy = 1; rc -> sum = r - mid;
      |             ^~
apple.cpp:15:49: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if'
   15 |             if (!rc) rc = new Node(mid + 1, r); rc -> lazy = 1; rc -> sum = r - mid;
      |                                                 ^~
apple.cpp: In member function 'int Node::query(int, int)':
apple.cpp:30:37: warning: unused variable 'mid' [-Wunused-variable]
   30 |     int query(int tl, int tr) { int mid = (l + r) / 2;
      |                                     ^~~
# 결과 실행 시간 메모리 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 7788 KB Output is correct
5 Correct 25 ms 9452 KB Output is correct
6 Correct 24 ms 9068 KB Output is correct
7 Correct 24 ms 9324 KB Output is correct
8 Correct 198 ms 69412 KB Output is correct
9 Correct 409 ms 118636 KB Output is correct
10 Correct 418 ms 132608 KB Output is correct
11 Correct 441 ms 143468 KB Output is correct
12 Correct 460 ms 148268 KB Output is correct
13 Correct 416 ms 181868 KB Output is correct
14 Correct 424 ms 183404 KB Output is correct
15 Runtime error 545 ms 262148 KB Execution killed with signal 9
16 Halted 0 ms 0 KB -