#include <bits//stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
typedef tree<long long, null_type, less<long long>, rb_tree_tag,
tree_order_statistics_node_update>
ordered_set;
typedef tree<long long, null_type, less_equal<long long>, rb_tree_tag,
tree_order_statistics_node_update>
ordered_multiset;
#define ll long long
#define ld long double
#define iloop(m, h) for (auto i = m; i != h; i += (m < h ? 1 : -1))
#define jloop(m, h) for (auto j = m; j != h; j += (m < h ? 1 : -1))
#define kloop(m, h) for (auto k = m; k != h; k += (m < h ? 1 : -1))
#define lloop(m, h) for (auto l = m; l != h; l += (m < h ? 1 : -1))
#define iloop_(m, h, g) for (auto i = m; i < h; i += g)
#define jloop_(m, h, g) for (auto j = m; j < h; j += g)
#define kloop_(m, h, g) for (auto k = m; k < h; k += g)
#define lloop_(m, h, g) for (auto l = m; l < h; l += g)
#define getchar_unlocked _getchar_nolock // comment before submission
#define pll pair<ll, ll>
#define plll pair<ll, pll>
#define pllll pair<pll, pll>
#define vll vector<ll>
#define qll queue<ll>
#define dll deque<ll>
#define pqll priority_queue<ll>
#define gll greater<ll>
#define INF 1000000000000000
#define MOD1 1000000007
#define MOD2 998244353
#define MOD3 1000000009
mt19937 rng(chrono::system_clock::now().time_since_epoch().count());
ll c = 0;
struct node {
ll s, e, m, v = 0, lazy = 0;
node *l, *r;
node (ll S, ll E) {
s = S, e = E, m = (S+E)>>1;
l = r = nullptr;
}
void lcreate() {
if (l == nullptr) l = new node(s, m);
l->lazy |= lazy;
if (lazy) l->v = (m-s+1);
}
void rcreate() {
if (r == nullptr) r = new node(m+1, e);
r->lazy |= lazy;
if (lazy) r->v = (e-m);
}
void upd(ll S, ll E) {
if (s == S && e == E) {lazy = 1; v = (e-s+1); return;}
if (E <= m) lcreate(), l->upd(S, E);
else if (S > m) rcreate(), r->upd(S, E);
else lcreate(), rcreate(), l->upd(S, m), r->upd(m+1, E);
if (l == nullptr) v = r->v;
else if (r == nullptr) v = l->v;
else v = l->v + r->v;
}
ll qu(ll S, ll E) {
if (s == S && e == E) return v;
if (E <= m) {lcreate(); return l->qu(S, E);}
if (S > m) {rcreate(); return r->qu(S, E);}
lcreate(); rcreate(); return l->qu(S, m) + r->qu(m+1, E);
}
} *root = new node(1, 1e9 + 7);
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
ll q;
cin >> q;
ll cmd, t1, t2;
while (q--) {
cin >> cmd >> t1 >> t2;
if (cmd == 1) {
c = root->qu(t1 + c, t2 + c);
cout << c << "\n";
}
else {
root->upd(t1 + c, t2 + c);
}
}
}
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |