# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
869429 | Flan312 | Monkey and Apple-trees (IZhO12_apple) | C++17 | 426 ms | 232196 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define eb emplace_back
#define task ""
#define fast ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define nx freopen (task".inp","r",stdin), freopen (task".out","w",stdout);
#define fi first
#define se second
#define pii pair <int, int>
#define tii tuple <int, int, int>
using namespace std;
struct node
{
int cnt;
bool lazy;
node *l, *r;
node(int cnt = 0, bool lazy = 0) : cnt(cnt), lazy(lazy)
{
l = r = nullptr;
}
};
#define check(x) if (x == nullptr) x = new node();
void down(node *root, int l, int r)
{
if (root == nullptr) return;
if (root -> lazy)
{
root -> cnt = r - l + 1;
if (l != r)
{
check(root -> l);
root -> l -> lazy = 1;
check(root -> r);
root -> r -> lazy = 1;
}
root -> lazy = 0;
}
}
void update(node *root, int l, int r, int u, int v)
{
down(root, l, r);
if (l > v || r < u) return;
if (l >= u && r <= v)
{
root -> lazy = 1;
down(root, l, r);
return;
}
int mid = l + r >> 1;
check(root -> l);
check(root -> r);
update(root -> l, l, mid, u, v);
update(root -> r, mid + 1, r, u, v);
root -> cnt = (root -> l -> cnt) + (root -> r -> cnt);
}
int query(node *root, int l, int r, int u, int v)
{
if (root == nullptr) return 0;
if (l > v || r < u) return 0;
down(root, l, r);
if (l >= u && r <= v)
return root -> cnt;
int mid = l + r >> 1;
int res = 0;
if (u <= mid) res += query(root -> l, l, mid, u, v);
if (mid <= v) res += query(root -> r, mid + 1, r, u, v);
return res;
}
node *root = new node();
int t;
int main()
{
if (ifstream(task".inp")) nx
fast
cin >> t;
int c = 0;
while(t--)
{
int type, l, r;
cin >> type >> l >> r;
l += c, r += c;
if (type == 1)
{
c = query(root, 1, 1e9, l, r);
cout << c << '\n';
}
else update(root, 1, 1e9, l, r);
}
}
컴파일 시 표준 에러 (stderr) 메시지
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |