Submission #682917

#TimeUsernameProblemLanguageResultExecution timeMemory
682917vjudge1Monkey and Apple-trees (IZhO12_apple)C++17
0 / 100
401 ms262144 KiB
#include <iostream> #include <vector> #include <map> #include <set> #include <stack> #include <queue> #include <algorithm> #include <string> #include <cmath> #include <cstdio> #include <iomanip> #include <fstream> #include <cassert> #include <cstring> #include <unordered_set> #include <unordered_map> #include <numeric> #include <ctime> #include <bitset> #include <complex> #include <chrono> #include <random> #include <functional> #define taskname "" using namespace std; const long long MAXN = 1e9, INF = 1e18; struct node { long long left, right; long long val = 0; bool lazy = false; node *left_child = nullptr, *right_child = nullptr; node(int lb, int rb) { left = lb; right = rb; } void extend() { if (!left_child && left < right) { int mid = (left + right) / 2; left_child = new node(left, mid); right_child = new node(mid + 1, right); } } ~node() { delete left_child; delete right_child; left_child = NULL; right_child = NULL; } void push() { if (lazy) { extend(); left_child->val = left_child->right - left_child->left + 1; left_child->lazy = true; right_child->val = right_child->right - right_child->left + 1; right_child->lazy = true; lazy = false; } } void update(long long l, long long r, long long newval) { if (l > r) return; if (l == left && right == r) { val = right - left + 1; lazy = true; } else { extend(); push(); long long mid = (left + right) / 2; left_child->update(l, min(r, mid), newval); right_child->update(max(l, mid + 1), r, newval); val = left_child->val + right_child->val; } } long long query(long long l, long long r) { if (l > r) return 0; if (l == left && r == right) return val; extend(); push(); long long mid = (left + right) / 2; return left_child->query(l, min(mid, r)) + right_child->query(max(mid + 1, l), r); } }; void solve() { long long m; cin >> m; node *root = new node(1, MAXN); long long c = 0; while (m--) { long long d, x, y; cin >> d >> x >> y; if (d == 1) { c = root->query(x + c, y + c); cout << c << '\n'; } else { root->update(x + c, y + c, 1); } } } signed main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); if (fopen(taskname ".inp", "r")) { freopen(taskname ".inp", "r", stdin); freopen(taskname ".out", "w", stdout); } long long segtree = 1; // cin >> segtree; while (segtree--) { solve(); } }

Compilation message (stderr)

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