// Thanks to : TVA
// Strycks, L3, PAD, TVT, NGUYEN^2, Whisper
// My friends...
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define pii pair<int, int>
#define plli pair<ll, int>
#define pb push_back
#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define allr(x) (x).rbegin(), (x).rend()
#define bit(mask, i) ((mask >> i) & 1)
#define fi first
#define se second
#define For(i, a, b) for(int i = (a) ; i <= (b) ; ++i)
#define Ford(i, b, a) for(int i = (b) ; i >= (a) ; --i)
#define FILE freopen(name".IN", "r", stdin); freopen(name".OUT", "w", stdout);
using namespace std;
using namespace __gnu_pbds;
using ll = long long;
using str = string;
using ld = long double;
using ull = unsigned long long;
using htype = unsigned long long;
template <class T> bool ckmin(T &a, const T &b) {return (a > b ? a = b, true : false); };
template <class T> bool ckmax(T &a, const T &b) {return (a < b ? a = b, true : false); };
template <class T> void compress(vector <T> &a) {sort(all(a)); a.resize(unique(all(a)) - a.begin()); };
template <class T> int getcom(vector<T> &a, T val) {return lower_bound(all(a), val) - a.begin() + 1; };
const ll mod = 1e9 + 7; /// MOD CHANGED
ll add(ll x, ll y){
return (x + y) % mod;
}
ll sub(ll x, ll y){
return ((x - y) % mod + mod) % mod;
}
ll mul(ll x, ll y){
return (x * y) % mod;
}
mt19937_64 rd(chrono::steady_clock::now().time_since_epoch().count());
const int dx[] = {-1, 0, 0, 1};
const int dy[] = {0, -1, 1, 0};
const char MOVE[] = {'U', 'L', 'R', 'D'};
const ll INFll = 0x3f3f3f3f3f3f3f3f;
const int INFin = 0x3f3f3f3f;
const int maxn = 123456; /// MAXN CHANGED
const int maxv = 1e6 + 5; /// MAXV CHANGED
struct node{
int sum, lazy, tl, tr, l, r;
node() : sum(0), lazy(0), l(-1), r(-1) {};
};
node it[64 * maxn];
int cnt = 2;
void push(int node){
if(it[node].lazy){
it[node].sum = it[node].tr - it[node].tl + 1;
int mid = (it[node].tl + it[node].tr) >> 1;
if(it[node].l == -1){
it[node].l = cnt++;
it[it[node].l].tl = it[node].tl;
it[it[node].l].tr = mid;
}
if(it[node].r == -1){
it[node].r = cnt++;
it[it[node].r].tl = mid + 1;
it[it[node].r].tr = it[node].tr;
}
it[it[node].l].lazy = it[it[node].r].lazy = 1;
it[node].lazy = 0;
}
}
void upd(int node, int l, int r){
push(node);
if(l == it[node].tl && r == it[node].tr){
it[node].lazy = 1;
push(node);
}
else{
int mid = (it[node].tl + it[node].tr) >> 1;
if(it[node].l == -1){
it[node].l = cnt++;
it[it[node].l].tl = it[node].tl;
it[it[node].l].tr = mid;
}
if(it[node].r == -1){
it[node].r = cnt++;
it[it[node].r].tl = mid + 1;
it[it[node].r].tr = it[node].tr;
}
if(l > mid) upd(it[node].r, l, r);
else if(r <= mid) upd(it[node].l, l, r);
else{
upd(it[node].l, l, mid);
upd(it[node].r, mid + 1, r);
}
push(it[node].l);
push(it[node].r);
it[node].sum = it[it[node].l].sum + it[it[node].r].sum;
}
}
int query(int node, int l, int r){
push(node);
if(l == it[node].tl && r == it[node].tr) return it[node].sum;
int mid = (it[node].tl + it[node].tr) >> 1;
if(it[node].l == -1){
it[node].l = cnt++;
it[it[node].l].tl = it[node].tl;
it[it[node].l].tr = mid;
}
if(it[node].r == -1){
it[node].r = cnt++;
it[it[node].r].tl = mid + 1;
it[it[node].r].tr = it[node].tr;
}
if(l > mid) return query(it[node].r, l, r);
else if(r <= mid) return query(it[node].l, l, r);
else return query(it[node].l, l, mid) + query(it[node].r, mid + 1, r);
}
int main(){
fast
#define name "f"
FILE
int m; cin >> m;
it[1].sum = 0;
it[1].lazy = 0;
it[1].tl = 1;
it[1].tr = 1e9;
int c = 0;
For(i, 1, m){
int d, x, y; cin >> d >> x >> y;
if(d == 1){
c = query(1, x + c, y + c);
cout << c << '\n';
}else upd(1, x + c, y + c);
}
}
Compilation message
apple.cpp: In function 'int main()':
apple.cpp:18:21: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
18 | #define FILE freopen(name".IN", "r", stdin); freopen(name".OUT", "w", stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
apple.cpp:144:5: note: in expansion of macro 'FILE'
144 | FILE
| ^~~~
apple.cpp:18:53: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
18 | #define FILE freopen(name".IN", "r", stdin); freopen(name".OUT", "w", stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
apple.cpp:144:5: note: in expansion of macro 'FILE'
144 | FILE
| ^~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
136 ms |
262144 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |