#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
#include <cstdio>
using namespace std;
#ifndef ONLINE_JUDGE
#define dbg(x) cerr << #x <<" "; print(x); cerr << endl;
#else
#define dbg(x)
#endif
void print(long long t) {cerr << t;}
void print(int t) {cerr << t;}
void print(string t) {cerr << t;}
void print(char t) {cerr << t;}
void print(double t) {cerr << t;}
void print(long double t) {cerr << t;}
void print(unsigned long long t) {cerr << t;}
template <class T, class V> void print(pair <T, V> p);
template <class T> void print(vector <T> v);
template <class T> void print(set <T> v);
template <class T, class V> void print(map <T, V> v);
template <class T> void print(multiset <T> v);
template <class T, class V> void print(T v[],V n) {cerr << "["; for(int i = 0; i < n; i++) {cerr << v[i] << " ";} cerr << "]";}
template <class T, class V> void print(pair <T, V> p) {cerr << "{"; print(p.first); cerr << ","; print(p.second); cerr << "}";}
template <class T> void print(vector <T> v) {cerr << "[ "; for (T i : v) {print(i); cerr << " ";} cerr << "]";}
template <class T> void print(set <T> v) {cerr << "[ "; for (T i : v) {print(i); cerr << " ";} cerr << "]";}
template <class T> void print(multiset <T> v) {cerr << "[ "; for (T i : v) {print(i); cerr << " ";} cerr << "]";}
template <class T, class V> void print(map <T, V> v) {cerr << "[ "; for (auto i : v) {print(i); cerr << " ";} cerr << "]";}
template <class T> void print(queue <T> q) {cerr << "[ "; while(!q.empty()) {print(q.front()); cerr << " "; q.pop();} cerr << "]";}
template <class T> void print(priority_queue <T> q) {cerr << "[ "; while(!q.empty()) {print(q.top()); cerr << " "; q.pop();} cerr << "]";}
template <class T> void print(int n__, T arr[]) {cerr << "[ "; for(int i = 0; i <= n__; i++) {print(arr[i]); cerr << " ";} cerr << "]";}
#define pb push_back
#define YES cout << "YES\n"
#define NO cout << "NO\n"
#define voch cout << -1 << '\n'
#define ll long long
#define ppb pop_back
#define OK cout << "OK" << endl;
#define ld long double
#define all(v) (v).begin(), (v).end()
#define MP make_pair
#define PII pair <int, int>
#define lower lower_bound
#define upper upper_bound
#define endl '\n'
#define ull unsigned long long
#define PLL pair <ll, ll>
#define flush cout.flush();
void setIO(string name = "") {
if (!name.empty()) {
freopen((name + ".in").c_str(), "r", stdin);
freopen((name + ".out").c_str(), "w", stdout);
}
}
void fastIO(){
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
}
void setPrecision(int x){
if(x == 0){
return;
}
cout.setf(ios::fixed);
cout.precision(x);
return;
}
const int inf = 1e9 + 5, LOG = 31;
const ll inf64 = 1e18 + 5, mod = 1e9 + 7, wmod = 998244353;
const int N = 1e6 + 5;
int m, c;
struct SparseSegTree{
int hashvich = 1;
struct node{
int val, l, r;
bool lazy;
} tree[10 * N];
void propagate(int x, int lx, int rx){
if(!tree[x].lazy || rx == lx) return;
int m = (rx + lx) / 2;
if(!tree[x].l) tree[x].l = ++hashvich;
if(!tree[x].r) tree[x].r = ++hashvich;
tree[tree[x].l].val = (m - lx + 1);
tree[tree[x].r].val = (rx - m);
tree[tree[x].l].lazy = 1;
tree[tree[x].r].lazy = 1;
tree[x].lazy = 0;
}
// void build(int pos){
// build(pos, 1, 1, inf);
// }
// void build(int pos, int x, int lx, int rx){
// if(lx == rx) return;
// int m = (lx + rx) / 2;
// if(pos <= m){
// if(!tree[x].l) tree[x].l = ++hashvich;
// build(pos, tree[x].l, lx, m);
// }
// else{
// if(!tree[x].r) tree[x].r = ++hashvich;
// build(pos, tree[x].r, m + 1, rx);
// }
// }
void upd(int l, int r){
upd(l, r, 1, 1, inf);
}
void upd(int l, int r, int x, int lx, int rx){
if(x == 0) return;
propagate(x, lx, rx);
if(lx > r || rx < l) return;
if(lx >= l && rx <= r){
tree[x].lazy = 1;
tree[x].val = (rx - lx + 1);
return;
}
int m = (lx + rx) / 2;
if(!tree[x].l) tree[x].l = ++hashvich;
if(!tree[x].r) tree[x].r = ++hashvich;
upd(l, r, tree[x].l, lx, m);
upd(l, r, tree[x].r, m + 1, rx);
tree[x].val = tree[tree[x].l].val + tree[tree[x].r].val;
}
int qry(int l, int r){
return qry(l, r, 1, 1, inf);
}
int qry(int l, int r, int x, int lx, int rx){
if(x == 0) return 0;
propagate(x, lx, rx);
if(lx >= l && rx <= r) return tree[x].val;
if(lx > r || rx < l) return 0;
int m = (lx + rx) / 2;
if(!tree[x].l) tree[x].l = ++hashvich;
if(!tree[x].r) tree[x].r = ++hashvich;
return qry(l, r, tree[x].l, lx, m) + qry(l, r, tree[x].r, m + 1, rx);
}
} st;
void solve(int TST_NUM){
cin >> m;
while(m--){
int t, x, y;
cin >> t >> x >> y;
x += c, y += c;
if(t == 1){
//dbg(MP(x, y));
int res = st.qry(x, y);
cout << res << endl;
c = res;
}
else{
//dbg(MP(x, y));
st.upd(x, y);
}
}
}
int main(){
fastIO();
int Tests = 1;
//cin >> Tests;
int TST_NUM = 1;
while(Tests--){
solve(TST_NUM++);
}
return 0;
}
//mcmcmcmcmcmc
//mcmcmcmcmcmc
//mcmcmcmcmcmc
//mcmcmcmcmcmc
Compilation message (stderr)
apple.cpp: In function 'void setIO(std::string)':
apple.cpp:55:24: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
55 | freopen((name + ".in").c_str(), "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
apple.cpp:56:24: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
56 | freopen((name + ".out").c_str(), "w", stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |