#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <bits/stdc++.h>
using namespace std;
using namespace __gnu_pbds;
#define int long long
#define ff first
#define ss second
#define tobit(n) bitset<(int)30>(n)
typedef unsigned long long ull;
#define all(v) (v).begin(), (v).end()
#pragma GCC optimize("Ofast","inline","-ffast-math")
#define rtt(v) rotate(vec.begin(), vec.begin() + k, vec.end()); //move k elements back
vector<int> dx = {1, -1, 0, 0, 1, 1, -1, -1}, dy = {0, 0, 1, -1, 1, -1, 1, -1};
vector<pair<int, int>> DX = {{-1, 0}, {1, 0}, {0, -1}, {0, 1}};
const vector<pair<int, int>> ANS = {{1, 0}, {-1, 0}, {0, 1}, {0, -1}};
const int MOD = 1e9 + 7, N = (int)1e6, inf = numeric_limits<int>::max();
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
void IO(string str_ = ""){
if((int)str_.size()){
freopen((str_ + ".in").c_str(), "r", stdin);
freopen((str_ + ".out").c_str(), "w", stdout);
}
}
void HASH(){
const int k = 31, mod = 1e9+7;
string s = "abacabadaba";
long long h = 0, m = 1;
for(auto c : s){
int x = (int) (c - 'a' + 1);
h = (h + m * x) % mod;
m = (m * k) % mod;
}
}
void rabinKarp(string pattern, string str, int q){
int m = pattern.size(), n = str.size();
int i, j, p = 0, t = 0, h = 1, d = 256;
for(i = 0; i < m - 1; i++) h = (h * d) % q;
for(i = 0; i < m; i++) p = (d * p + pattern[i]) % q, t = (d * t + str[i]) % q;
for(i = 0; i <= n - m; i++){
if(p == t){
for(j = 0; j < m; j++){
if(str[i + j] != pattern[j]) break;
} if(j == m) cout << "Pattern found at index " << i << endl;
} if(i < n - m){
t = (d * (t - str[i] * h) + str[i + m]) % q;
if(t < 0) t = (t + q);
}
}
}
struct Node {
int l, r;
int sum;
bool lazy;
Node *left, *right;
Node(int l, int r) : l(l), r(r), sum(0), lazy(false), left(nullptr), right(nullptr) {}
};
void update(Node* node, int l, int r) {
if(l > node -> r || r < node -> l) return;
if(node -> lazy) return;
if(l <= node -> l && node -> r <= r){
node -> sum = node -> r - node -> l + 1;
node -> lazy = true; return;
} int mid = node -> l + (node -> r - node -> l) / 2;
if(node -> left == nullptr){
node -> left = new Node(node -> l, mid);
node -> right = new Node(mid + 1, node -> r);
} update(node -> left, l, r);
update(node -> right, l, r);
node -> sum = node -> left -> sum + node -> right -> sum;
}
int query(Node* node, int l, int r){
if(l > node -> r || r < node -> l) return 0;
if(node -> lazy) return min(r, node -> r) - max(l, node -> l) + 1;
if(l <= node -> l && node -> r <= r) return node-> sum;
int mid = node -> l + (node -> r - node -> l) / 2;
if(node -> left == nullptr){
node -> left = new Node(node -> l, mid);
node -> right = new Node(mid + 1, node -> r);
} return query(node -> left, l, r) + query(node -> right, l, r);
}
signed main(){ // clock_t the_time = clock(); double t_;
IO(""); int M, C = 0; cin >> M;
Node* root = new Node(1, 1000000000);
for(int i = 0; i < M; i++){
int D, X, Y; cin >> D >> X >> Y;
int l = X + C, r = Y + C;
if(D == 1){
int ans = query(root, l, r);
cout << query(root, l, r) << '\n';
C = ans;
} else update(root, l, r);
} // t_ = double(clock() - the_time) / CLOCKS_PER_SEC; cout << fixed << setprecision(16)<< t_ << " sec.";
}
const int fastIO = [](){
ios_base::sync_with_stdio(false);
cin.tie(nullptr); cout.tie(nullptr);
return 0;
}();
/*
Открыть терминал: F5
Закрыть терминал: F6
Спрятать/показать терминал: F7
Скомпилировать и запустить: F9
Только запустить: F12
*/
Compilation message (stderr)
apple.cpp: In function 'void IO(std::string)':
apple.cpp:22:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
22 | freopen((str_ + ".in").c_str(), "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
apple.cpp:23:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
23 | freopen((str_ + ".out").c_str(), "w", stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |