Submission #1279757

#TimeUsernameProblemLanguageResultExecution timeMemory
1279757swishy123Monkey and Apple-trees (IZhO12_apple)C++20
100 / 100
377 ms198120 KiB
#include <bits/stdc++.h> #define ll long long #define pi pair<int, int> #define pl pair<ll, ll> #define x first #define y second const ll inf = 1e18; const int def = 4e6+1; using namespace std; struct Node{ int sum, lazy, tl, tr; int l, r; Node(int l, int r) : tl(l), tr(r), lazy(0), sum(0), l(-1), r(-1){} }; vector<Node> st; void extend(int u){ int tl = st[u].tl, tr = st[u].tr; int l = st[u].l, r = st[u].r; if (tl == tr) return; int mid = (tl + tr) / 2; if (l == -1){ st[u].l = st.size(); st.push_back(Node(tl, mid)); } if (r == -1){ st[u].r = st.size(); st.push_back(Node(mid + 1, tr)); } } void push(int u){ int lazy = st[u].lazy; int l = st[u].l, r = st[u].r; if (!lazy) return; if (l != -1){ st[l].sum = st[l].tr - st[l].tl + 1; st[l].lazy = 1; } if (r != -1){ st[r].sum = st[r].tr - st[r].tl + 1; st[r].lazy = 1; } st[u].lazy = 0; } void update(int ql, int qr, int crr){ if (ql > st[crr].tr || qr < st[crr].tl) return; if (st[crr].tl >= ql && st[crr].tr <= qr){ st[crr].sum = st[crr].tr - st[crr].tl + 1; st[crr].lazy = 1; return; } extend(crr); push(crr); update(ql, qr, st[crr].l); update(ql, qr, st[crr].r); st[crr].sum = st[st[crr].l].sum + st[st[crr].r].sum; } int get(int ql, int qr, int crr){ if (ql > st[crr].tr || qr < st[crr].tl) return 0; if (st[crr].tl >= ql && st[crr].tr <= qr) return st[crr].sum; extend(crr); push(crr); return get(ql, qr, st[crr].l) + get(ql, qr, st[crr].r); } void solve(){ int n; cin >> n; st.push_back(Node(0, 1e9)); int c = 0; for (int i = 0; i < n; i++){ int d, l, r; cin >> d >> l >> r; l += c; r += c; if (d == 1){ int res = get(l, r, 0); c = res; cout << res << endl; } else update(l, r, 0); } } /* */ int main(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); if (ifstream("input.txt").good()){ freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); } int t; t = 1; while (t--){ solve(); } }

Compilation message (stderr)

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