# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
884635 | OAleksa | Monkey and Apple-trees (IZhO12_apple) | C++14 | 143 ms | 132160 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>
using namespace std;
#define f first
#define s second
//#define int long long
const int N = 1e7 + 69;
int st[4 * N], q, c;
void push(int v, int tl, int tr) {
int mid = (tl + tr) / 2;
int s = tr - tl + 1;
if (st[v] == s) {
st[v * 2] = mid - tl + 1;
st[v * 2 + 1] = tr - mid;
}
}
void upd(int v, int tl, int tr, int l, int r) {
if (tl > r || tr < l)
return;
else if (tl >= l && tr <= r)
st[v] = (tr - tl + 1);
else {
int mid = (tl + tr) / 2;
push(v, tl, tr);
upd(v * 2, tl, mid, l, r);
upd(v * 2 + 1, mid + 1, tr, l, r);
st[v] = st[v * 2] + st[v * 2 + 1];
}
}
int get(int v, int tl, int tr, int l, int r) {
if (tl > r || tr < l)
return 0;
else if (tl >= l && tr <= r)
return st[v];
else {
int mid = (tl + tr) / 2;
push(v, tl, tr);
return get(v * 2, tl, mid, l, r) + get(v * 2 + 1, mid + 1, tr, l, r);
}
}
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int tt = 1;
//cin >> tt;
while (tt--) {
cin >> q;
while (q--) {
int t, l, r;
cin >> t >> l >> r;
l += c, r += c;
if (t == 2)
upd(1, 1, N - 1, l, r);
else {
c = get(1, 1, N - 1, l, r);
cout << c << '\n';
}
}
}
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |