#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define gcd __gcd
#define sz(v) (int) v.size()
#define pb push_back
#define pi pair<int,int>
#define all(v) (v).begin(), (v).end()
#define compact(v) (v).erase(unique(all(v)), (v).end())
#define FOR(i, a, b) for(int i = (a); i <= (b); i++)
#define REV(i, a, b) for(int i = (a); i >= (b); i--)
#define dbg(x) "[" #x " = " << (x) << "]"
///#define int long long
using ll = long long;
using ld = long double;
using ull = unsigned long long;
template<typename T> bool ckmx(T& a, const T& b){if(a < b) return a = b, true; return false;}
template<typename T> bool ckmn(T& a, const T& b){if(a > b) return a = b, true; return false;}
const int N = 2e5+5;
const ll MOD = 1e9+7;
const ll INF = 1e18;
struct Node{
Node *left, *right;
int cnt, lazy;
Node(int v = 0): cnt(v), lazy((v > 0 ? 1 : 0)){
left = nullptr;
right = nullptr;
}
void down(int l, int r){
if(lazy){
int m = l+r>>1;
left->cnt = (m - l + 1);
right->cnt = (r - m);
left->lazy = right->lazy = 1;
lazy = 0;
}
}
void update(int l, int r, int u, int v){
if(cnt == (r - l + 1)) return;
if(l >= u && r <= v){
cnt = (r - l + 1);
lazy = 1;
return;
}
int m = l+r>>1;
if(u <= m){
if(left == nullptr) left = new Node();
left->update(l, m, u, v);
}
if(v > m){
if(right == nullptr) right = new Node();
right->update(m + 1, r, u, v);
}
cnt = (left != nullptr ? left->cnt : 0) + (right != nullptr ? right->cnt : 0);
}
int query(int l, int r, int u, int v){
if(!cnt) return 0;
if(l >= u && r <= v) return cnt;
int m = l+r>>1;
if(left == nullptr) left = new Node();
if(right == nullptr) right = new Node();
down(l, r);
return (u <= m ? left->query(l, m, u, v) : 0) + (v > m ? right->query(m + 1, r, u, v) : 0);
}
};
void solve()
{
int q; cin >> q;
int ans = 0; Node root;
while(q--){
int op; cin >> op;
if(op == 1){
int l,r; cin >> l >> r;
ans = root.query(1, 1e9, l + ans, r + ans);
cout << ans << "\n";
}
else{
int l,r; cin >> l >> r;
root.update(1, 1e9, l + ans, r + ans);
}
}
}
signed main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
#define name "InvMOD"
if(fopen(name".INP", "r")){
freopen(name".INP","r",stdin);
freopen(name".OUT","w",stdout);
}
int t = 1; //cin >> t;
while(t--) solve();
return 0;
}
Compilation message (stderr)
apple.cpp: In function 'int main()':
apple.cpp:113:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
113 | freopen(name".INP","r",stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
apple.cpp:114:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
114 | freopen(name".OUT","w",stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |