# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
471174 | MohammadAghil | Monkey and Apple-trees (IZhO12_apple) | C++14 | 451 ms | 139460 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,l,r) for(int i = (l); i < r; i++)
#define per(i,r,l) for(int i = (r); i >= l; i--)
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x).size()
#define pb push_back
#define ff first
#define ss second
const ll mod = 1e9 + 7, maxn = 123456, inf = 1e9 + 5;
struct node{
node *lch, *rch;
int sum, lazy;
node(){
lch = rch = NULL;
sum = lazy = 0;
}
} *root;
void shift(node *p, int lx, int rx){
if(p->lch == NULL){
p->lch = new node();
p->rch = new node();
}
if(p->lazy){
int mid = (lx + rx)/2;
p->lch->sum = mid - lx;
p->rch->sum = rx - mid;
p->lch->lazy = p->rch->lazy = 1;
p->lazy = 0;
}
}
int get(int l, int r, node *p, int lx = 1, int rx = inf){
if(l <= lx && r >= rx) return p->sum;
if(l >= rx || r <= lx) return 0;
shift(p, lx, rx);
int mid = (lx + rx)/2;
return get(l, r, p->lch, lx, mid) + get(l, r, p->rch, mid, rx);
}
void add(int l, int r, node *p, int lx = 1, int rx = inf){
if(l <= lx && r >= rx){
p->sum = rx - lx;
p->lazy = 1;
return;
}
if(l >= rx || r <= lx) return;
shift(p, lx, rx);
int mid = (lx + rx)/2;
add(l, r, p->lch, lx, mid);
add(l, r, p->rch, mid, rx);
p->sum = p->lch->sum + p->rch->sum;
}
int main(){
cin.tie(0) -> sync_with_stdio(0);
int q, c = 0; cin >> q;
root = new node();
while(q--){
int d, l, r; cin >> d >> l >> r;
if(d == 1){
c = get(l + c, r + c + 1, root);
cout << c << '\n';
}else{
add(l + c, r + c + 1, root);
}
}
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |