#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define endl '\n'
const int N = 3e6 + 5;
const long long mod = 1e9 + 7;
const int mod2 = 998244353;
const long long lim = 1e9;
const int lg = 22;
const int base = 311;
const int base2 = 511;
const long double eps = 1e-12;
ll st[N], lazy[N], L[N], R[N];
ll cnt = 1;
void down(ll k, ll l, ll r){
if (L[k] == 0) cnt++, L[k] = cnt;
if (R[k] == 0) cnt++, R[k] = cnt;
ll mid = (l + r) >> 1;
st[L[k]] = mid - l + 1;
st[R[k]] = r - mid;
lazy[L[k]] = 1;
lazy[R[k]] = 1;
lazy[k] = 0;
}
ll get(ll k, ll l, ll r, ll x, ll y){
if (l != r && lazy[k]) down(k, l, r);
if (x > r || y < l) return 0;
if (x <= l && y >= r) return st[k];
ll res = 0;
ll mid = (l + r) >> 1;
if (L[k]) res = res + get(L[k], l, mid, x, y);
if (R[k]) res = res + get(R[k], mid + 1, r, x, y);
//cout << l << " " << r << " " << res << endl;
return res;
}
void upd(ll k, ll l, ll r, ll x, ll y){
if (l != r && lazy[k]) down(k, l, r);
if (x > r || y < l) return;
if (x <= l && y >= r){
st[k] = r - l + 1;
lazy[k] = 1;
return;
}
ll mid = (l + r) >> 1;
if (L[k] == 0) cnt++, L[k] = cnt;
if (R[k] == 0) cnt++, R[k] = cnt;
upd(L[k], l, mid, x, y);
upd(R[k], mid + 1, r, x, y);
st[k] = st[L[k]] + st[R[k]];
}
signed main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
if (fopen("tests.inp", "r")){
freopen("tests.inp", "r", stdin);
freopen("tests.out", "w", stdout);
}
ll m;
cin >> m;
ll c = 0;
while (m--){
ll d, x, y;
cin >> d >> x >> y;
x += c;
y += c;
if (d == 1){
c = get(1, 1, lim, x, y);
cout << c << endl;
} else {
upd(1, 1, lim, x, y);
}
}
}
/*
Ans:
Out:
*/
Compilation message
apple.cpp: In function 'int main()':
apple.cpp:56:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
56 | freopen("tests.inp", "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
apple.cpp:57:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
57 | freopen("tests.out", "w", stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
304 KB |
Output is correct |
2 |
Correct |
1 ms |
296 KB |
Output is correct |
3 |
Correct |
1 ms |
304 KB |
Output is correct |
4 |
Correct |
12 ms |
5980 KB |
Output is correct |
5 |
Correct |
17 ms |
7212 KB |
Output is correct |
6 |
Correct |
15 ms |
6956 KB |
Output is correct |
7 |
Correct |
14 ms |
7128 KB |
Output is correct |
8 |
Correct |
129 ms |
52336 KB |
Output is correct |
9 |
Correct |
298 ms |
89204 KB |
Output is correct |
10 |
Runtime error |
351 ms |
192956 KB |
Execution killed with signal 11 |
11 |
Halted |
0 ms |
0 KB |
- |