제출 #702764

#제출 시각아이디문제언어결과실행 시간메모리
702764boyliguanhan원숭이와 사과 나무 (IZhO12_apple)C++17
0 / 100
414 ms262144 KiB
#include<iostream> using namespace std; struct node { int v, l, r; bool rp; node* c[2]{ nullptr, nullptr }; node(int l, int r) : l(l), r(r), rp(false), v(0) {} }; node* tree = new node(1, 1e9); void pd(node* i) { if (i->rp) { i->v = i->r - i->l + 1; int mid = i->r + i->l >> 1; if (i->v > 1) { if (!i->c[0]) i->c[0] = new node(i->l, mid); if (!i->c[1]) i->c[1] = new node(mid + 1, i->r); i->c[0]->rp = i->c[1]->rp = 1; } i->rp = 0; } } void update(node* i, int l, int r) { if (l <= i->l && i->r <= r) { i->rp = 1, pd(i); return; } pd(i); int mid = i->l + i->r >> 1; if (mid < r) { if (!i->c[1]) i->c[1] = new node(mid + 1, i->r); update(i->c[1], l, r); } if (l <= mid) { if (!i->c[0]) i->c[0] = new node(i->l, mid); update(i->c[0], l, r); } i->v = 0; if (i->c[0]) pd(i->c[0]),i->v += i->c[0]->v; if (i->c[1]) pd(i->c[1]),i->v += i->c[1]->v; } int query(node* i, int l, int r) { pd(i); if (l <= i->l && i->r <= r) return i->v; int mid = i->l + i->r >> 1, res = 0; if (mid < r && i->c[1]) res = query(i->c[1], l, r); if (l <= mid && i->c[0]) res += query(i->c[0], l, r); return res; } int c; int main() { cin.sync_with_stdio(false); cin.tie(nullptr); int q; cin >> q; while (q--) { int t, x, y; cin >> t >> x >> y; x += c, y += c; if (t^2) cout << (c = query(tree, x, y)) << '\n'; else update(tree, x, y); } }

컴파일 시 표준 에러 (stderr) 메시지

apple.cpp: In constructor 'node::node(int, int)':
apple.cpp:5:7: warning: 'node::rp' will be initialized after [-Wreorder]
    5 |  bool rp;
      |       ^~
apple.cpp:4:6: warning:   'int node::v' [-Wreorder]
    4 |  int v, l, r;
      |      ^
apple.cpp:7:2: warning:   when initialized here [-Wreorder]
    7 |  node(int l, int r) : l(l), r(r), rp(false), v(0) {}
      |  ^~~~
apple.cpp: In function 'void pd(node*)':
apple.cpp:13:18: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   13 |   int mid = i->r + i->l >> 1;
      |             ~~~~~^~~~~~
apple.cpp: In function 'void update(node*, int, int)':
apple.cpp:30:17: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   30 |  int mid = i->l + i->r >> 1;
      |            ~~~~~^~~~~~
apple.cpp: In function 'int query(node*, int, int)':
apple.cpp:51:17: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   51 |  int mid = i->l + i->r >> 1, res = 0;
      |            ~~~~~^~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...