Submission #1019162

#TimeUsernameProblemLanguageResultExecution timeMemory
1019162blackslexMonkey and Apple-trees (IZhO12_apple)C++17
100 / 100
408 ms232560 KiB
#include<bits/stdc++.h> using namespace std; int q, rc, x, y, c; struct node { int val; bool lz; node *l, *r; node() : val(val), l(nullptr), r(nullptr) {} node(int val) : val(val), l(nullptr), r(nullptr) {} }; typedef node* pnode; pnode rt = nullptr; void push (int l, int r, pnode &cur) { if (!cur->lz) return; cur->val = r - l + 1; if (l < r) { if (!cur->l) cur->l = new node(); if (!cur->r) cur->r = new node(); cur->l->lz = cur->r->lz = 1; } cur->lz = 0; } void upd (int l, int r, pnode &cur, int tl, int tr) { if (!cur) cur = new node(); push(l, r, cur); if (l > tr || r < tl) return; if (l >= tl && r <= tr) return cur->lz = 1, push(l, r, cur), void(); int mid = (l + r) >> 1; upd(l, mid, cur->l, tl, tr); upd(mid + 1, r, cur->r, tl, tr); cur->val = (cur->l ? cur->l->val : 0) + (cur->r ? cur->r->val : 0); } int qr (int l, int r, pnode cur, int tl, int tr) { if (l > tr || r < tl || !cur) return 0; push(l, r, cur); if (l >= tl && r <= tr) return cur->val; int mid = (l + r) >> 1; return qr(l, mid, cur->l, tl, tr) + qr(mid + 1, r, cur->r, tl, tr); } int main() { scanf("%d", &q); while (q--) { scanf("%d %d %d", &rc, &x, &y); if (rc == 2) upd(-1e9, 1e9, rt, x + c, y + c); else printf("%d\n", c = qr(-1e9, 1e9, rt, x + c, y + c)); } }

Compilation message (stderr)

apple.cpp: In constructor 'node::node()':
apple.cpp:11:5: warning: 'node::val' is initialized with itself [-Winit-self]
   11 |     node() : val(val), l(nullptr), r(nullptr) {}
      |     ^~~~
apple.cpp: In function 'int main()':
apple.cpp:49:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   49 |     scanf("%d", &q);
      |     ~~~~~^~~~~~~~~~
apple.cpp:51:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   51 |         scanf("%d %d %d", &rc, &x, &y);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
apple.cpp: In constructor 'node::node()':
apple.cpp:11:18: warning: '*<unknown>.node::val' is used uninitialized in this function [-Wuninitialized]
   11 |     node() : val(val), l(nullptr), r(nullptr) {}
      |                  ^~~
#Verdict Execution timeMemoryGrader output
Fetching results...