# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
682917 | vjudge1 | 원숭이와 사과 나무 (IZhO12_apple) | C++17 | 401 ms | 262144 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <fstream>
#include <cassert>
#include <cstring>
#include <unordered_set>
#include <unordered_map>
#include <numeric>
#include <ctime>
#include <bitset>
#include <complex>
#include <chrono>
#include <random>
#include <functional>
#define taskname ""
using namespace std;
const long long MAXN = 1e9, INF = 1e18;
struct node
{
long long left, right;
long long val = 0;
bool lazy = false;
node *left_child = nullptr, *right_child = nullptr;
node(int lb, int rb)
{
left = lb;
right = rb;
}
void extend()
{
if (!left_child && left < right)
{
int mid = (left + right) / 2;
left_child = new node(left, mid);
right_child = new node(mid + 1, right);
}
}
~node()
{
delete left_child;
delete right_child;
left_child = NULL;
right_child = NULL;
}
void push()
{
if (lazy)
{
extend();
left_child->val = left_child->right - left_child->left + 1;
left_child->lazy = true;
right_child->val = right_child->right - right_child->left + 1;
right_child->lazy = true;
lazy = false;
}
}
void update(long long l, long long r, long long newval)
{
if (l > r)
return;
if (l == left && right == r)
{
val = right - left + 1;
lazy = true;
}
else
{
extend();
push();
long long mid = (left + right) / 2;
left_child->update(l, min(r, mid), newval);
right_child->update(max(l, mid + 1), r, newval);
val = left_child->val + right_child->val;
}
}
long long query(long long l, long long r)
{
if (l > r)
return 0;
if (l == left && r == right)
return val;
extend();
push();
long long mid = (left + right) / 2;
return left_child->query(l, min(mid, r)) + right_child->query(max(mid + 1, l), r);
}
};
void solve()
{
long long m;
cin >> m;
node *root = new node(1, MAXN);
long long c = 0;
while (m--)
{
long long d, x, y;
cin >> d >> x >> y;
if (d == 1)
{
c = root->query(x + c, y + c);
cout << c << '\n';
}
else
{
root->update(x + c, y + c, 1);
}
}
}
signed main()
{
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
if (fopen(taskname ".inp", "r"))
{
freopen(taskname ".inp", "r", stdin);
freopen(taskname ".out", "w", stdout);
}
long long segtree = 1;
// cin >> segtree;
while (segtree--)
{
solve();
}
}
컴파일 시 표준 에러 (stderr) 메시지
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |