# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
471148 | MohammadAghil | 원숭이와 사과 나무 (IZhO12_apple) | C++17 | 128 ms | 262148 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 + 5, inf = 1e9 + 5;
struct node{
ll lx, rx, sum = 0, lazy = 0, l = 0, r = 0;
node(){}
node(ll sum, ll lazy, ll lx, ll rx, ll l = 0, ll r = 0):
sum(sum), lazy(lazy), lx(lx), rx(rx), l(l), r(r){}
};
struct seg{
vector<node> a;
int cnt = 1;
seg(int n){
a.resize(n);
a[1] = node(0, 0, 1, 1e9 + 1);
}
void build(int x){
if(!a[x].l){
int mid = (a[x].lx + a[x].rx)/2;
a[++cnt] = node(0, 0, a[x].lx, mid);
a[x].l = cnt;
a[++cnt] = node(0, 0, mid, a[x].rx);
a[x].r = cnt;
}
}
void shift(int x){
if(a[x].lazy){
a[x].sum = a[x].rx - a[x].lx;
build(x);
a[a[x].l].lazy = a[a[x].r].lazy = 1;
a[x].lazy = 0;
}
}
void set(int l, int r, int x){
shift(x);
if(l == a[x].lx && r == a[x].rx){
a[x].lazy = 1;
shift(x);
return;
}
build(x);
int mid = (a[x].lx + a[x].rx)/2;
if(l >= mid) set(l, r, a[x].r);
else if(r <= mid) set(l, r, a[x].l);
else{
set(l, mid, a[x].l);
set(mid, r, a[x].r);
}
shift(a[x].l);
shift(a[x].r);
a[x].sum = a[a[x].l].sum + a[a[x].r].sum;
}
int get(int l, int r, int x){
shift(x);
if(l == a[x].lx && r == a[x].rx) return a[x].sum;
int mid = (a[x].lx + a[x].rx)/2;
build(x);
if(r <= mid) return get(l, r, a[x].l);
else if(l >= mid) return get(l, r, a[x].r);
else return get(l, mid, a[x].l) + get(mid, r, a[x].r);
}
};
int main(){
cin.tie(0) -> sync_with_stdio(0);
int q; cin >> q;
seg st(maxn*64);
int c = 0;
while(q--){
int d, l, r; cin >> d >> l >> r;
if(d == 2){
st.set(c + l, c + r + 1, 1);
}else{
c = st.get(c + l, c + r + 1, 1);
cout << c << '\n';
}
}
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |