#include <bits/stdc++.h>
#define ll long long
#define se second
#define fi first
#define codedbyMC ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define file_in(NAME) freopen(NAME".INP", "r", stdin)
#define file_out(NAME) freopen(NAME".OUT", "w", stdout)
#define iffile(NAME) if (fopen(NAME".INP", "r")) {file_in(NAME); file_out(NAME);}
#define pb push_back
#define eb emplace_back
#define all(v) v.begin(), v.end()
#define sz(v) (int)v.size()
#define trav(a, x) for(auto &a : x)
#define endl '\n'
#define debug(x) cout << #x << " = " << x << endl;
#define lb(v, x) lower_bound(all(v), x)
#define ub(v, x) upper_bound(all(v), x)
#define ms(arr, v) memset(arr, v, sizeof(arr))
#define pii pair<int, int>
#define pll pair<ll, ll>
#define pli pair<ll, int>
#define vi vector<int>
#define vpii vector<pii>
#define fort(i,l,r) for (int i=l;i<=r;i++)
#define forl(i,l,r) for (int i=l;i>=r;i--)
#define builcnt(x) __builtin_popcountll(x)
#define getbit(x, i) ((x >> i) & 1)
#define onbit(x, i) (x | (1LL << i))
#define resetbit(x, i) (x & ~(1LL << i))
#define clearbit(x, i) (x ^ (1LL << i))
using namespace std;
const int N = 5e5+7;
const int MOD = 1e9+7;
const ll INF = 1e18;
const ll NEG = -1e18;
template<class T> bool chmin(T &a, const T &b){ if(b < a){ a = b; return true;} return false; }
template<class T> bool chmax(T &a, const T &b){ if(b > a){ a = b; return true;} return false; }
inline void add(int &a, int b){a += b; if (a >= MOD) a -= MOD;}
inline void sub(int &a, int b){a -= b; if (a < 0) a += MOD;}
inline int mul(const int &a, const int &b){return 1ll * (a%MOD) * (b%MOD) % MOD;}
int n, m, k, q, x, y, t;
ll an = 0;
vector<int> a, f;
void sub1() {
}
struct dynamic_segment_tree{
struct node {
ll val;
int lazy;
node *l, *r;
node(ll v = 0) : val(v), lazy(-1), l(nullptr), r(nullptr) {}
};
node *root;
int L, R;
dynamic_segment_tree(int l, int r){
L = l;
R = r;
root = nullptr;
}
inline void ensure(node* &nd) {
if (!nd) nd = new node(0);
}
void push(node* &id, int l, int r) {
if (!id || id->lazy == -1 || l == r) return;
int mid = (l + r) >> 1;
ensure(id->l);
ensure(id->r);
if (id->lazy == 1) {
id->l->val = (ll)(mid - l + 1);
id->l->lazy = 1;
id->r->val = (ll)(r - mid);
id->r->lazy = 1;
}
id->lazy = -1;
};
void upd(node* &id, int l, int r, int u, int v) {
if (v < l || r < u) return;
ensure(id);
if (u <= l && r <= v) {
id->val = (ll)(r - l + 1);
id->lazy = 1;
return;
}
push(id, l, r);
int mid = (l + r) >> 1;
upd(id->l, l, mid, u, v);
upd(id->r, mid + 1, r, u, v);
ll leftVal = id->l ? id->l->val : 0;
ll rightVal = id->r ? id->r->val : 0;
id->val = leftVal + rightVal;
};
void upd(int u, int v) {
if (u > v) return;
if (v < L || u > R) return;
u = max(u, L); v = min(v, R);
upd(root, L, R, u, v);
}
ll get(node* &id, int l, int r, int u, int v) {
if (!id || v < l || r < u) return 0;
if (u <= l && r <= v) {
return id->val;
}
push(id, l, r);
int mid = (l + r) >> 1;
ll res = 0;
if (u <= mid) res += get(id->l, l, mid, u, v);
if (v > mid) res += get(id->r, mid + 1, r, u, v);
return res;
};
ll get(int u, int v){
if (u > v) return 0;
if (v < L || u > R) return 0;
u = max(u, L); v = min(v, R);
return get(root, L, R, u, v);
}
void clear(node* id) {
if (!id) return;
clear(id->l);
clear(id->r);
delete id;
}
void clearAll() {
clear(root);
root = nullptr;
}
};
int main() {
codedbyMC
iffile("test")
iffile("")
cin >> n;
const int LBOUND = 1;
const int RBOUND = 1000000000;
dynamic_segment_tree dst(LBOUND, RBOUND);
ll C = 0;
for (int i = 0; i < n; ++i) {
int ty;
ll u, v;
cin >> ty >> u >> v;
ll l = u + C;
ll r = v + C;
if (l < LBOUND) l = LBOUND;
if (r > RBOUND) r = RBOUND;
if (l > r) {
if (ty == 1) {
cout << 0 << endl;
C = 0;
}
continue;
}
if (ty == 2) {
dst.upd((int)l, (int)r);
} else if (ty == 1) {
ll ans = dst.get((int)l, (int)r);
cout << ans << endl;
C = ans;
}
}
dst.clearAll();
return 0;
}
/*
:****+:
:#####****.
##########****-
.+***+. :############****:
.***######..##############***.
.***########-=################:
.**##########=################
:**###########+#############:
***#############-#######+-.:--:.
-**#################+#*###########*.
-**############**#################**
=##########=-*##################***.
+*##*+..*#####################***.
+#######################***.
.########################**.
#################=######***
****##############.####***.
+***#############. :+#+:
.==.+****####:#:
:*****=. #.
-#.
*#
+#
=#.
*#
.#-
Mchau — don’t give up!
time:
bhehe
*/
Compilation message (stderr)
apple.cpp: In function 'int main()':
apple.cpp:6:40: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
6 | #define file_in(NAME) freopen(NAME".INP", "r", stdin)
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
apple.cpp:8:62: note: in expansion of macro 'file_in'
8 | #define iffile(NAME) if (fopen(NAME".INP", "r")) {file_in(NAME); file_out(NAME);}
| ^~~~~~~
apple.cpp:142:5: note: in expansion of macro 'iffile'
142 | iffile("test")
| ^~~~~~
apple.cpp:7:40: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
7 | #define file_out(NAME) freopen(NAME".OUT", "w", stdout)
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
apple.cpp:8:77: note: in expansion of macro 'file_out'
8 | #define iffile(NAME) if (fopen(NAME".INP", "r")) {file_in(NAME); file_out(NAME);}
| ^~~~~~~~
apple.cpp:142:5: note: in expansion of macro 'iffile'
142 | iffile("test")
| ^~~~~~
apple.cpp:6:40: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
6 | #define file_in(NAME) freopen(NAME".INP", "r", stdin)
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
apple.cpp:8:62: note: in expansion of macro 'file_in'
8 | #define iffile(NAME) if (fopen(NAME".INP", "r")) {file_in(NAME); file_out(NAME);}
| ^~~~~~~
apple.cpp:143:5: note: in expansion of macro 'iffile'
143 | iffile("")
| ^~~~~~
apple.cpp:7:40: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
7 | #define file_out(NAME) freopen(NAME".OUT", "w", stdout)
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
apple.cpp:8:77: note: in expansion of macro 'file_out'
8 | #define iffile(NAME) if (fopen(NAME".INP", "r")) {file_in(NAME); file_out(NAME);}
| ^~~~~~~~
apple.cpp:143:5: note: in expansion of macro 'iffile'
143 | iffile("")
| ^~~~~~| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |