# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
468339 | jenishmonpara | 원숭이와 사과 나무 (IZhO12_apple) | C++14 | 425 ms | 262148 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
long double PI = acos(-1);
long double DEL = 1e-12;
long long M = 1e9 + 7;
const long long N = 3e5 + 10;
#pragma GCC optimize ("unroll-loops")
#pragma GCC optimize("Ofast")
#pragma GCC optimize ("O3")
#pragma GCC target ("avx")
#define ftt cin>>tc;for(int cas=1;cas<=tc;++cas)
#define all(a) a.begin(),a.end()
#define sq(a) ((a)*(a))
#define double long double
#define dbg cout<<"\nhi\n";
#define int long long
#define nl cout<<"\n"
#define sp <<" "<<
#define mid ((l+r)>>1)
#define X real()
#define Y imag()
//*********************************** CHECK CONSTRAINTS ***********************************
int cnt, sum, mx, mn, ans, a[N], b[N];
int n, m, d, i, j, k, l, p, q, r, t, w, x, y, z, tc;
string s;
//************************************* CODE STARTS ****************************************
struct node{
int s,lz,lson,rson;
node() : s(0),lz(0),lson(0),rson(0){}
};
vector<node> seg;
void push(int i,int l,int r){
if(seg[i].lz == 0){
return;
}
seg[i].s = r - l + 1;
if(l != r){
if(seg[i].lson == 0){
seg[i].lson=seg.size();
seg.emplace_back();
seg[i].rson=seg.size();
seg.emplace_back();
}
seg[seg[i].lson].lz = seg[seg[i].rson].lz = 1;
}
seg[i].lz=0;
}
void upd(int i,int l,int r,int a,int b){
push(i,l,r);
if(l > b or r < a){
return;
}
if(a <= l and r <= b){
seg[i].lz = 1;
push(i,l,r);
return;
}
if(seg[i].lson == 0){
seg[i].lson=seg.size();
seg.emplace_back();
seg[i].rson=seg.size();
seg.emplace_back();
}
upd(seg[i].lson,l,mid,a,b);
upd(seg[i].rson,mid+1,r,a,b);
seg[i].s = seg[seg[i].lson].s + seg[seg[i].rson].s;
}
int get(int i,int l,int r,int a,int b){
push(i,l,r);
if(l > b or r < a or seg[i].s == 0){
return 0;
}
if(a <= l and r <= b){
return seg[i].s;
}
if(seg[i].lson == 0){
return 0;
}
return get(seg[i].lson,l,mid,a,b) + get(seg[i].rson,mid+1,r,a,b);
}
int32_t main()
{
ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
//#ifndef ONLINE_JUDGE
// freopen("/Users/jenish/XCode/cp/input.txt","r",stdin);
//#endif
seg.emplace_back();
seg.emplace_back();
int c = 0;
ftt{
cin >> x >> l >> r;
if(x == 1){
c = get(1,1,1e9,c+l,c+r);
cout<<c;nl;
}
else{
upd(1,1,1e9,c+l,c+r);
}
}
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |