# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
334440 | NhoxZuji | Monkey and Apple-trees (IZhO12_apple) | C++14 | 48 ms | 3180 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>
#define all(x) x.begin(), x.end()
#define eb emplace_back
#define pb push_back
#define pf push_front
#define mp make_pair
#define pii pair<int, int>
#define pll pair<long long, long long>
#define pdd pair<double, double>
#define fi first
#define se second
#define fr(x, y, z) for (int x = y; x <= z; ++x)
#define loop(x) while(x--)
#define read(x) freopen(x".INP","r",stdin);
#define write(x) freopen(x".OUT","w",stdout);
#define NULL nullptr
#define nametask "main"
using namespace std;
typedef long long ll;
int mi(int x, int y){
return (x > y ? y : x);
}
int ma(int x, int y){
return (x > y ? x : y);
}
int n;
struct node{
int s, l, r;
node *lid, *rid;
node(int x, int y) : l(x), r(y), s(0), lid(NULL), rid(NULL) {}
void upd(int x, int y){
if (s == r - l + 1) return;
if (x <= l && r <= y) s = r - l + 1; else
{
int mid = (l + r) >> 1;
if (x <= mid){
if (!lid) lid = new node(l, mid);
lid->upd(x, y);
}
if (y > mid){
if (!rid) rid = new node(mid + 1, r);
rid->upd(x, y);
}
s = 0;
s += (lid ? lid->s : 0);
s += (rid ? rid->s : 0);
}
}
int query(int x, int y){
if (x > r || l > y) return 0;
if (x <= l && r <= y) return s;
if (s == r - l + 1) return mi(r, y) - ma(x, l) + 1;
int res = 0;
res += (lid ? lid->query(x, y) : 0);
res += (rid ? rid->query(x, y) : 0);
return res;
}
};
node root(1, (int) 1e9);
int main()
{
ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
//read(nametask); write(nametask);
cin >> n;
int c = 0;
loop(n){
int d, x, y;
cin >> d >> x >> y;
if (d == 1){
c = root.query(x + c, y + c);
cout << c << "\n";
} else root.upd(x + c, y + c);
}
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |