제출 #1124306

#제출 시각아이디문제언어결과실행 시간메모리
1124306sunflower원숭이와 사과 나무 (IZhO12_apple)C++20
100 / 100
340 ms137384 KiB
#include <bits/stdc++.h> using namespace std; #define left __left #define right __right const int inf = (int) 1e9 + 7; struct node { int sum = 0; int lazy = 0; node *left = nullptr; node *right = nullptr; }; typedef node* Node; Node root = new node; void down(Node cur, int l, int r) { // if (l >= r || cur->lazy == 0) return; if (cur->left == nullptr) cur->left = new node; if (cur->right == nullptr) cur->right = new node; if (cur->lazy > 0 && l < r) { int g = (l + r) >> 1; cur->left->sum = g - l + 1; cur->right->sum = r - g; cur->left->lazy = 1; cur->right->lazy = 1; } cur->lazy = 0; return; } void update(Node cur, int l, int r, int u, int v) { if (l > v || u > r) return; if (u <= l && r <= v) { cur->sum = r - l + 1; cur->lazy = 1; return; } down(cur, l, r); int g = (l + r) >> 1; // if (cur->left == nullptr) cur->left = new node; // if (cur->right == nullptr) cur->right = new node; update(cur->left, l, g, u, v); update(cur->right, g + 1, r, u, v); cur->sum = cur->left->sum + cur->right->sum; } int get(Node cur, int l, int r, int u, int v) { if (l > v || u > r) return 0; if (u <= l && r <= v) return cur->sum; down(cur, l, r); int g = (l + r) >> 1; return get(cur->left, l, g, u, v) + get(cur->right, g + 1, r, u, v); } int main() { ios_base::sync_with_stdio(0); cin.tie(0);cout.tie(0); if (fopen("test.inp","r")) { freopen("test.inp","r",stdin); freopen("test.out","w",stdout); } int n; cin >> n; int preAns = 0; while (n--) { int type, l, r; cin >> type >> l >> r; l += preAns; r += preAns; if (type == 2) { update(root, 1, inf, l, r); } else { cout << (preAns = get(root, 1, inf, l, r)) << "\n"; } } return 0; }

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

apple.cpp: In function 'int main()':
apple.cpp:65:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   65 |         freopen("test.inp","r",stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
apple.cpp:66:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   66 |         freopen("test.out","w",stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...