# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
684074 | vovamr | Monkey and Apple-trees (IZhO12_apple) | C++17 | 236 ms | 71240 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define fi first
#define se second
#define ll long long
#define ld long double
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define mpp make_pair
#define ve vector
using namespace std;
using namespace __gnu_pbds;
template<class T> using oset = tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;
const ll inf = 1e18; const int iinf = 1e9;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
template <typename T> inline bool chmin(T& a, T b) { return (a > b ? a = b, 1 : 0); }
template <typename T> inline bool chmax(T& a, T b) { return (a < b ? a = b, 1 : 0); }
const int L = 1;
const int R = 1e9;
const int N = (1e5 + 100) * 33 + 100;
int w = 0;
struct node {
int l, r, s, push;
} t[4 * N];
inline int node() {
int v = w++;
t[v] = {-1, -1, 0, -1};
return v;
}
inline void push(int v, int vl, int vr) {
if (t[v].push == -1) return;
if (!~t[v].l) t[v].l = node();
if (!~t[v].r) t[v].r = node();
int m = vl + vr >> 1;
t[t[v].l].push = t[t[v].r].push = t[v].push;
t[t[v].l].s = (m - vl + 1) * t[v].push;
t[t[v].r].s = (vr - m) * t[v].push;
t[v].push = -1;
}
inline void upd(int &v, int vl, int vr, int l, int r, int x) {
if (l > r) return;
if (!~v) v = node();
if (vl == l && vr == r) {
t[v].s = x * (vr - vl + 1);
t[v].push = x;
return;
}
push(v, vl, vr);
int m = vl + vr >> 1;
upd(t[v].l, vl, m, l, min(r, m), x);
upd(t[v].r, m + 1, vr, max(l, m + 1), r, x);
t[v].s = 0;
if (~t[v].l) t[v].s += t[t[v].l].s;
if (~t[v].r) t[v].s += t[t[v].r].s;
}
inline int get(int v, int vl, int vr, int l, int r) {
if (!~v || l > r) return 0;
else if (vl == l && vr == r) return t[v].s;
push(v, vl, vr);
int m = vl + vr >> 1;
return get(t[v].l, vl, m, l, min(r, m)) +
get(t[v].r, m + 1, vr, max(l, m + 1), r);
}
inline void solve() {
int q;
cin >> q;
int last = 0;
int rt = node();
while (q--) {
int type;
cin >> type;
if (type == 1) {
int l, r;
cin >> l >> r;
l += last;
r += last;
last = get(rt, L, R, l, r);
cout << last << '\n';
}
else {
int l, r;
cin >> l >> r;
l += last;
r += last;
upd(rt, L, R, l, r, 1);
}
}
}
signed main() {
ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
int q = 1; // cin >> q;
while (q--) solve();
cerr << fixed << setprecision(3) << "Time execution: " << (double)clock() / CLOCKS_PER_SEC << endl;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |