제출 #869429

#제출 시각아이디문제언어결과실행 시간메모리
869429Flan312Monkey and Apple-trees (IZhO12_apple)C++17
100 / 100
426 ms232196 KiB
#include <bits/stdc++.h> #define ll long long #define ld long double #define eb emplace_back #define task "" #define fast ios::sync_with_stdio(0),cin.tie(0),cout.tie(0); #define nx freopen (task".inp","r",stdin), freopen (task".out","w",stdout); #define fi first #define se second #define pii pair <int, int> #define tii tuple <int, int, int> using namespace std; struct node { int cnt; bool lazy; node *l, *r; node(int cnt = 0, bool lazy = 0) : cnt(cnt), lazy(lazy) { l = r = nullptr; } }; #define check(x) if (x == nullptr) x = new node(); void down(node *root, int l, int r) { if (root == nullptr) return; if (root -> lazy) { root -> cnt = r - l + 1; if (l != r) { check(root -> l); root -> l -> lazy = 1; check(root -> r); root -> r -> lazy = 1; } root -> lazy = 0; } } void update(node *root, int l, int r, int u, int v) { down(root, l, r); if (l > v || r < u) return; if (l >= u && r <= v) { root -> lazy = 1; down(root, l, r); return; } int mid = l + r >> 1; check(root -> l); check(root -> r); update(root -> l, l, mid, u, v); update(root -> r, mid + 1, r, u, v); root -> cnt = (root -> l -> cnt) + (root -> r -> cnt); } int query(node *root, int l, int r, int u, int v) { if (root == nullptr) return 0; if (l > v || r < u) return 0; down(root, l, r); if (l >= u && r <= v) return root -> cnt; int mid = l + r >> 1; int res = 0; if (u <= mid) res += query(root -> l, l, mid, u, v); if (mid <= v) res += query(root -> r, mid + 1, r, u, v); return res; } node *root = new node(); int t; int main() { if (ifstream(task".inp")) nx fast cin >> t; int c = 0; while(t--) { int type, l, r; cin >> type >> l >> r; l += c, r += c; if (type == 1) { c = query(root, 1, 1e9, l, r); cout << c << '\n'; } else update(root, 1, 1e9, l, r); } }

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

apple.cpp: In function 'void update(node*, int, int, int, int)':
apple.cpp:50:17: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   50 |     int mid = l + r >> 1;
      |               ~~^~~
apple.cpp: In function 'int query(node*, int, int, int, int)':
apple.cpp:64:17: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   64 |     int mid = l + r >> 1;
      |               ~~^~~
apple.cpp: In function 'int main()':
apple.cpp:7:20: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
    7 | #define nx freopen (task".inp","r",stdin), freopen (task".out","w",stdout);
      |            ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
apple.cpp:74:31: note: in expansion of macro 'nx'
   74 |     if (ifstream(task".inp")) nx
      |                               ^~
apple.cpp:7:52: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
    7 | #define nx freopen (task".inp","r",stdin), freopen (task".out","w",stdout);
      |                                            ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
apple.cpp:74:31: note: in expansion of macro 'nx'
   74 |     if (ifstream(task".inp")) nx
      |                               ^~
#Verdict Execution timeMemoryGrader output
Fetching results...