제출 #1235218

#제출 시각아이디문제언어결과실행 시간메모리
1235218vux2code원숭이와 사과 나무 (IZhO12_apple)C++20
0 / 100
245 ms93564 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 = 2e7; 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 l, r; ll f; Node *child [2]; Node (ll x, ll y) : l (x), r (y) { child [0] = NULL; child [1] = NULL; f = 0; } }; Node* root; SegTree () { root = new Node (1, maxA); } void upfull (Node *x) { if (x != NULL) { x -> f = x -> r - x -> l + 1; } } void dn (Node *x) { if (x -> l == x -> r) return; ll mid = (x -> l + x -> r) >> 1; if (x -> f == x -> r - x -> l + 1) { if (x -> child [0] == NULL) x -> child [0] = new Node (x -> l, mid); if (x -> child [1] == NULL) x -> child [1] = new Node (mid + 1, x -> r); upfull (x -> child [0]); upfull (x -> child [1]); } } void dbg (Node *pos) { if (pos -> r <= 10) { cerr << pos -> l << ' ' << pos -> r << ' ' << pos -> f << '\n'; } } void add (Node *pos, ll l, ll r) { if (pos -> r < l || pos -> l > r) return; if (l <= pos -> l && pos -> r <= r) { pos -> f = pos -> r - pos -> l + 1; //dbg (pos); return; } dn (pos); ll mid = (pos -> l + pos -> r) >> 1; if (pos -> child [0] == NULL) pos -> child [0] = new Node (pos -> l, mid); add (pos -> child [0], l, r); if (pos -> child [1] == NULL) pos -> child [1] = new Node (mid + 1, pos -> r); add (pos -> child [1], l, r); pos -> f = pos -> child [0] -> f + pos -> child [1] -> f; //dbg (pos); } void add (ll l, ll r) { add (root, l, r); } ll get (Node *pos, ll l, ll r) { if (pos == NULL) return 0; if (pos -> r < l || pos -> l > r) return 0; if (l <= pos -> l && pos -> r <= r) return pos -> f; dn (pos); return get (pos -> child [0], l, r) + get (pos -> child [1], l, r); } ll get (ll x, ll y) { return get (root, 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(); }
#Verdict Execution timeMemoryGrader output
Fetching results...