# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
858433 | Requiem | 원숭이와 사과 나무 (IZhO12_apple) | C++17 | 2052 ms | 348 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
#define int long long
#define pb push_back
#define fast ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
#define MOD 1000000007
#define INF 1e18
#define fi first
#define se second
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define FORD(i,a,b) for(int i=a;i>=b;i--)
#define sz(a) ((int)(a).size())
#define endl '\n'
#define pi 3.14159265359
#define TASKNAME "f"
template<typename T> bool maximize(T &res, const T &val) { if (res < val){ res = val; return true; }; return false; }
template<typename T> bool minimize(T &res, const T &val) { if (res > val){ res = val; return true; }; return false; }
using namespace std;
typedef pair<int,int> ii;
typedef pair<int,ii> iii;
typedef vector<int> vi;
struct SparseSegmentTree{
int sum,lazy,l,r;
SparseSegmentTree *toleft=NULL, *toright=NULL;
SparseSegmentTree(): sum(0), lazy(-1), l(0), r(0) {}
SparseSegmentTree(int l,int r): sum(0), lazy(-1), l(l), r(r){}
};
int cnt = 0;
SparseSegmentTree *root;
void push(SparseSegmentTree *root){
if (root!=NULL){
int mid = (root->l + root->r) / 2;
if (root->toleft == NULL) root->toleft = new SparseSegmentTree(root->l,mid);
if (root->toright == NULL) root->toright = new SparseSegmentTree(mid+1,root->r);
if (root->lazy==1){
root->sum = root->r - root->l +1;
root->toleft->lazy = root->lazy;
root->toright->lazy = root->lazy;
root->lazy = -1;
}
}
}
void upd(SparseSegmentTree *root,int u,int v){
push(root);
if (root->l > v or root->r < u) return;
if (root->l >= u and root->r <=v) {
root->lazy = 1;
push(root);
return;
}
upd(root->toleft,u,v);
upd(root->toright,u,v);
root->sum = root->toleft->sum + root->toright->sum;
}
int get(SparseSegmentTree *root,int u,int v){
push(root);
if (root->l > v or root->r < u) return 0;
if (root->l >= u and root->r <=v) return root->sum;
return get(root->toleft,u,v) + get(root->toright,u,v);
}
int n;
main()
{
fast;
freopen(TASKNAME".in","r",stdin);
freopen(TASKNAME".out","w",stdout);
int n;
cin>>n;
int c = 0;
root = new SparseSegmentTree(1,1e9);
for(int i=1;i<=n;i++){
int type,x,y;
cin>>type>>x>>y;
if (type==1) {
c = get(root,x+c,y+c);
cout<<c<<endl;
}
else{
upd(root,x+c,y+c);
}
}
}
컴파일 시 표준 에러 (stderr) 메시지
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |