Submission #1235251

#TimeUsernameProblemLanguageResultExecution timeMemory
1235251vux2codeMonkey and Apple-trees (IZhO12_apple)C++20
100 / 100
303 ms205688 KiB
// Src : Vux2Code /* Note : */ #include <bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; typedef pair<ll, ll> pll; #define fi first #define se second #define pusb push_back #define popb pop_back #define pusf push_front #define popf pop_front #define vec3d vector<vector<vector<ll>>> #define vec2d vector<vector<ll>> #define vec1d vector<ll> vec3d set3 (ll x, ll y, ll z, ll val = 0) {return vec3d (x, vec2d (y, vec1d (z, val)));} vec2d set2 (ll x, ll y, ll val = 0) {return vec2d (x, vec1d (y, val));} template<typename T> using rvs_pq = std::priority_queue<T, std::vector<T>, std::greater<T>>; #define forinc(i, a, b) for (ll i = (a); i <= (b); ++i) #define fordec(i, a, b) for (ll i = (a); i >= (b); --i) #define foreach(i, j) for (ll i : (j)) #define all(a) (a).begin (), (a). end () #define uni(a) (a).erase(unique((a).begin(), (a). end ()), (a). end ()) const ll maxN = 1e6 + 5, maxLog = 20, inf64 = 1e18, inf32 = 1e9, mod = 1e9 + 7, maxA = 1e9; void maxi(ll &x, ll y) { x = max(x, y); } void mini(ll &x, ll y) { x = min(x, y); } /* ---------HASHING-------- */ // const base = 31, mod2 = 1e9 + 9; /* ---------BITMASK-------- */ // ll count(ll x) { return __builtin_popcountll(x); } // ll fst(ll x) { return 63 - __builtin_clzll(x); } // ll last(ll x) { return __builtin_ctzll(x); } // bool bit(ll x, ll y) { return ((x >> y) & 1); } ll t = 1; struct SegTree { struct Node { ll f, lz; Node *child [2]; Node () { child [0] = NULL; child [1] = NULL; f = 0; lz = 0; } }; Node* root; SegTree () { root = new Node (); } void upfull (Node *x, ll l, ll r) { if (x == NULL) return; x -> f = r - l + 1; x -> lz = 1; } void dn (Node *x, ll l, ll r) { if (l == r) return; ll mid = (l + r) >> 1; if (x -> child [0] == NULL) x -> child [0] = new Node (); if (x -> child [1] == NULL) x -> child [1] = new Node (); if (x -> lz) { upfull (x -> child [0], l, mid); upfull (x -> child [1], mid + 1, r); x -> lz = 0; } } void add (Node *pos, ll l, ll r, ll u, ll v) { if (r < u || v < l) return; if (u <= l && r <= v) return upfull (pos, l, r); dn (pos, l, r); ll mid = (l + r) >> 1; add (pos -> child [0], l, mid, u, v); add (pos -> child [1], mid + 1, r, u, v); pos -> f = pos -> child [0] -> f + pos -> child [1] -> f; } void add (ll l, ll r) { add (root, 1, maxA, l, r); } ll get (Node *pos, ll l, ll r, ll u, ll v) { if (pos == NULL) return 0; if (r < u || v < l) return 0; if (u <= l && r <= v) return pos -> f; dn (pos, l, r); ll mid = (l + r) >> 1; return get (pos -> child [0], l, mid, u, v) + get (pos -> child [1], mid + 1, r, u, v); } ll get (ll x, ll y) { return get (root, 1, maxA, x, y); } }s; ll n; void solve() { ll n;cin >> n; ll c = 0; while (n --) { ll type, x, y; cin >> type >> x >> y; if (type == 2) { s. add (x + c, y + c); } else { c = s. get (x + c, y + c); cout << c << '\n'; } //cerr << '\n'; } } int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); #define TASK "untitled1" if (fopen (TASK".inp", "r")) { freopen (TASK".inp", "r", stdin); freopen (TASK".out", "w", stdout); } // cin >> t; while (t--) solve(); }

Compilation message (stderr)

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