# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
870950 | Hyojin | Monkey and Apple-trees (IZhO12_apple) | C++17 | 211 ms | 190288 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define bit(n,i) ((n>>i)&1)
#define all(a) (a).begin(),(a).end()
#define pb push_back
#define ep emplace_back
#define pii pair<int,int>
#define piii pair<int,pii>
#define fi first
#define se second
#define ll long long
#define debug(x) cerr << #x << ' ' << x << '\n'
#define dbg(x) cerr<<#x<<' '<<x<<' '
const int base=31;
const int MOD=1e9+7;
const int N=1e5+5;
struct segtree{
int idL,idR,sum,lazy;
segtree():idL(0),idR(0),sum(0),lazy(0){}
} st[N*4*30];
int cur;
void update(int id,int x,int l,int r)
{
st[id].sum=r-l+1;
st[id].lazy=x;
}
void down(int id,int l,int mid,int r)
{
if (st[id].idL==0) st[id].idL=++cur;
if (st[id].idR==0) st[id].idR=++cur;
if (st[id].lazy!=0)
{
update(st[id].idL,st[id].lazy,l,mid);
update(st[id].idR,st[id].lazy,mid+1,r);
st[id].lazy=0;
}
}
void update(int id,int l,int r,int u,int v)
{
if (v<l||r<u) return;
if (u<=l&&r<=v)
{
st[id].lazy++;
st[id].sum=(r-l+1);
return;
}
int mid=l+r>>1;
down(id,l,mid,r);
update(st[id].idL,l,mid,u,v);
update(st[id].idR,mid+1,r,u,v);
st[id].sum=st[st[id].idL].sum+st[st[id].idR].sum;
}
int get(int id,int l,int r,int u,int v)
{
if (u<=l&&r<=v) return st[id].sum;
int mid=l+r>>1;
down(id,l,mid,r);
if (v<=mid) return get(st[id].idL,l,mid,u,v);
if (mid+1<=u) return get(st[id].idR,mid+1,r,u,v);
return get(st[id].idL,l,mid,u,v)+get(st[id].idR,mid+1,r,u,v);
}
int main()
{
ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#ifdef Shiho
freopen("izumi_shiho_supremacy.in","r", stdin);
freopen("izumi_shiho_supremacy.out","w", stdout);
#endif
cur=1;
int q;
cin>>q;
int c=0;
while (q--)
{
int type,u,v;
cin>>type>>u>>v;
if (type==1)
{
int x=get(1,1,1e9,u+c,v+c);
c=x;
cout<<x<<"\n";
}
else
{
update(1,1,1e9,u+c,v+c);
}
}
return 0;
}
/* stuff you should look for
* int overflow, array bounds
* special cases (n=1?)
* do smth instead of nothing and stay organized
* WRITE STUFF DOWN
* DON'T GET STUCK ON ONE APPROACH
*/
컴파일 시 표준 에러 (stderr) 메시지
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |