# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
331784 | kshitij_sodani | 원숭이와 사과 나무 (IZhO12_apple) | C++14 | 72 ms | 3180 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
//#pragma GCC optimize("Ofast,unroll-loops")
#include <bits/stdc++.h>
using namespace std;
typedef long long llo;
#define mp make_pair
#define pb push_back
#define a first
#define b second
#define endl '\n'
vector<int> tree;
vector<int> l;
vector<int> r;
vector<int> vis;
int co=0;
void update(int no,int ll,int rr,int aa,int bb){
if(vis[no]){
return;
}
if(rr<aa or ll>bb){
return;
}
if(aa<=ll and rr<=bb){
//cout<<ll<<".."<<rr<<endl;
tree[no]=rr-ll+1;
vis[no]=1;
return;
}
else{
int mid=(ll+rr)/2;
if(l[no]==-1){
co++;
tree.pb(0);
l[no]=co;
l.pb(-1);
r.pb(-1);
vis.pb(0);
}
update(l[no],ll,mid,aa,bb);
if(r[no]==-1){
co++;
tree.pb(0);
r[no]=co;
l.pb(-1);
r.pb(-1);
vis.pb(0);
}
update(r[no],mid+1,rr,aa,bb);
tree[no]=tree[l[no]]+tree[r[no]];
}
}
int query(int no,int ll,int rr,int aa,int bb){
if(aa>rr or bb<ll){
return 0;
}
if(aa<=ll and rr<=bb){
// cout<<ll<<",,"<<rr<<endl;
return tree[no];
}
else{
if(vis[no]){
return min(rr,bb)-max(ll,aa)+1;
}
int mid=(ll+rr)/2;
int cur=0;
if(l[no]!=-1){
cur+=query(l[no],ll,mid,aa,bb);
}
if(r[no]!=-1){
cur+=query(r[no],mid+1,rr,aa,bb);
}
return cur;
}
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int m;
tree.pb(0);
l.pb(-1);
r.pb(-1);
vis.pb(0);
cin>>m;
int cc=0;
while(m--){
int tt,aa,bb;
cin>>tt>>aa>>bb;
aa+=cc;
bb+=cc;
if(tt==1){
cc=query(0,0,1e9,aa,bb);
cout<<cc<<endl;
}
else{
update(0,0,1e9,aa,bb);
}
}
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |