# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
593872 | Do_you_copy | 원숭이와 사과 나무 (IZhO12_apple) | C++17 | 47 ms | 100428 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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 <ll, ll>;
using pil = pair <ll, ll>;
using pli = pair <ll, ll>;
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 ll maxN = 1e5 + 1;
ll n;
ll node_cnt = 1;
struct TNode{
ll l, r, lazy, sum;
TNode(): l(-1), r(-1), lazy(0), sum(0){}
};
TNode st[maxN * 32];
void add_node(ll id){
if (st[id].l == -1){
st[id].l = ++node_cnt;
}
if (st[id].r == -1){
st[id].r = ++node_cnt;
}
}
void pull(ll id, ll l, ll r){
if (st[id].lazy){
ll 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(ll id, ll i, ll j, ll x, ll l = 1, ll r = ll(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);
ll 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;
}
ll get(ll id, ll i, ll j, ll l = 1, ll r = ll(1e9)){
if (r < i || l > j) return 0;
if (i <= l && r <= j){
return st[id].sum;
}
add_node(id);
pull(id, l, r);
ll 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;
ll C = 0;
for (ll i = 1; i <= n; ++i){
ll t, x, y;
cin >> t >> x >> y;
x += C;
y += C;
if (t == 1){
ll 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();
}
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |