# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
426575 | CSQ31 | 원숭이와 사과 나무 (IZhO12_apple) | C++14 | 521 ms | 207824 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define sz(a) (int)(a.size())
#define all(a) a.begin(),a.end()
#define lb lower_bound
#define ub upper_bound
#define owo ios_base::sync_with_stdio(0);cin.tie(0);
#define MOD (ll)(1e9+7)
#define INF (ll)(1e18)
#define debug(...) fprintf(stderr, __VA_ARGS__),fflush(stderr)
#define time__(d) for(long blockTime = 0; (blockTime == 0 ? (blockTime=clock()) != 0 : false);\
debug("%s time : %.4fs\n", d, (double)(clock() - blockTime) / CLOCKS_PER_SEC))
typedef long long int ll;
typedef long double ld;
typedef pair<ll,ll> PII;
typedef pair<int,int> pii;
typedef vector<vector<int>> vii;
typedef vector<vector<ll>> VII;
ll gcd(ll a,ll b){if(!b)return a;else return gcd(b,a%b);}
struct node{
int lf,rg,sum,lazy;
node *l,*r;
node(int _lf,int _rg){
l = nullptr;
r = nullptr;
sum = lazy = 0;
lf = _lf;
rg = _rg;
}
void pushdown(){
int tm = (lf+rg)/2;
if(l == nullptr)l = new node(lf,tm);
if(r == nullptr)r = new node(tm+1,rg);
if(lazy){
lazy = 0;
l->lazy = r->lazy = 1;
l->sum = tm-lf+1;
r->sum = rg-tm;
}
}
void upd(int L,int R){
if(L == lf && rg == R){
sum = rg-lf+1;
lazy = 1;
return;
}
pushdown();
int tm = (lf+rg)/2;
if(R<=tm)l->upd(L,R);
else if(tm<L)r->upd(L,R);
else{
l->upd(L,tm);
r->upd(tm+1,R);
}
sum = l->sum + r->sum;
}
int query(int L,int R){
if(L == lf && rg == R){
return sum;
}
int tm = (lf+rg)/2;
pushdown();
if(R<=tm)return l->query(L,R);
else if(tm<L)return r->query(L,R);
else return l->query(L,tm) + r->query(tm+1,R);
}
}*root = new node(1,1e9);
int main(){
owo
int m;
cin>>m;
int c=0;
while(m--){
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);
}
}
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |