Submission #370929

#TimeUsernameProblemLanguageResultExecution timeMemory
370929pure_memMonkey and Apple-trees (IZhO12_apple)C++14
0 / 100
2 ms492 KiB
#include <bits/stdc++.h> #define X first #define Y second #define MP make_pair #define ll long long using namespace std; const int N = 3e5 + 12; const int INF = 1e9; struct node{ node *L, *R; int sum = 0, tt = 0; }; void push(node *v, int tl, int tr){ if(!v->tt) return; int tm = (tl + tr) / 2; v->L->sum = tm - tl + 1, v->R->sum = tr - tm; v->L->tt = v->R->tt = 1, v->tt = 0; } void upd(node *v, int tl, int tr, int l, int r){ if(tl > r || l > tr) return; if(tl >= l && tr <= r){ v->sum = tr - tl + 1, v->tt = 1; return; } if(!v->L) v->L = new node(); if(!v->R) v->R = new node(); push(v, tl, tr); int tm = (tl + tr) / 2; upd(v->L, tl, tm, l, r); upd(v->R, tm + 1, tr, l, r); v->sum = v->L->sum + v->R->sum; } int get(node *v, int tl, int tr, int l, int r){ if(tl > r || l > tr) return 0; if(tl >= l && tr <= r) return v->sum; if(!v->L) v->L = new node(); if(!v->R) v->R = new node(); push(v, tl, tr); int tm = (tl + tr) / 2; return get(v->L, tl, tm, l, r) + get(v->R, tm + 1, tr, l, r); } int main () { freopen("f.in", "r", stdin); freopen("f.out", "w", stdout); ios::sync_with_stdio(0), cin.tie(0), cout.tie(0); node *root = new node(); int sums = 0, q; cin >> q; for(int tc, l, r;q--;){ cin >> tc >> l >> r, l += sums, r += sums; if(tc == 1){ int ans = get(root, 1, INF, l, r); cout << ans << "\n", sums += ans; } else{ upd(root, 1, INF, l, r); } } }

Compilation message (stderr)

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