# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
334440 | NhoxZuji | 원숭이와 사과 나무 (IZhO12_apple) | C++14 | 48 ms | 3180 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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;
}
컴파일 시 표준 에러 (stderr) 메시지
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |