# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
593861 | Do_you_copy | 원숭이와 사과 나무 (IZhO12_apple) | C++17 | 23 ms | 50388 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define taskname "test"
#define fi first
#define se second
#define pb push_back
#define faster ios_base::sync_with_stdio(0); cin.tie(0);
using namespace std;
using ll = long long;
using pii = pair <int, int>;
using pil = pair <int, ll>;
using pli = pair <ll, int>;
using pll = pair <ll, ll>;
using ull = unsigned ll;
mt19937 Rand(chrono::steady_clock::now().time_since_epoch().count());
ll min(const ll &a, const ll &b){
return (a < b) ? a : b;
}
ll max(const ll &a, const ll &b){
return (a > b) ? a : b;
}
//const ll Mod = 1000000009;
//const ll Mod2 = 999999999989;
//only use when required
const int maxN = 1e5 + 1;
int n;
int node_cnt = 1;
struct TNode{
int l, r, lazy, sum;
TNode(): l(-1), r(-1), lazy(0), sum(0){}
};
TNode st[maxN * 32];
void add_node(int id){
if (st[id].l == -1){
st[id].l = ++node_cnt;
}
if (st[id].r == -1){
st[id].r = ++node_cnt;
}
}
void pull(int id, int l, int r){
if (st[id].lazy){
int mid = (l + r) / 2;
st[st[id].l].lazy += st[id].lazy;
st[st[id].r].lazy += st[id].lazy;
st[st[id].l].sum += (mid - l + 1) * st[id].lazy;
st[st[id].r].sum += (r - mid) * st[id].lazy;
st[id].lazy = 0;
}
}
void update(int id, int i, int j, int x, int l = 1, int r = int(1e9)){
if (r < i || l > j) return;
if (i <= l && r <= j){
st[id].lazy += x;
st[id].sum += (r - l + 1) * x;
return;
}
add_node(id);
pull(id, l, r);
int mid = (l + r) / 2;
update(st[id].l, i, j, x, l, mid);
update(st[id].r, i, j, x, mid + 1, r);
st[id].sum = st[st[id].l].sum + st[st[id].r].sum;
}
int get(int id, int i, int j, int l = 1, int r = int(1e9)){
if (r < i || l > j) return 0;
if (i <= l && r <= j){
return st[id].sum;
}
add_node(id);
pull(id, l, r);
int mid = (l + r) / 2;
return get(st[id].l, i, j, l, mid) + get(st[id].r, i, j, mid + 1, r);
}
void Init(){
cin >> n;
int C = 0;
for (int i = 1; i <= n; ++i){
int t, x, y;
cin >> t >> x >> y;
x += C;
y += C;
if (t == 1){
int ans = get(1, x, y);
C += ans;
cout << ans << "\n";
}
else{
update(1, x, y, 1);
}
}
}
int main(){
if (fopen(taskname".inp", "r")){
freopen(taskname".inp", "r", stdin);
//freopen(taskname".out", "w", stdout);
}
faster;
ll tt = 1;
//cin >> tt;
while (tt--){
Init();
}
}
컴파일 시 표준 에러 (stderr) 메시지
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |