/*#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("O3")
#pragma GCC target ("avx2")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")*/
#include<bits/stdc++.h>
#define sz(v) (int)v.size()
#define ll long long
#define pb push_back
#define x first
#define y second
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define nl "\n"
using namespace std;
using pii = pair<int, int>;
const int N = (int)1e5 + 7; // make sure this is right
const int M = (int)15e6 + 7;
const int inf = (int)1e9 + 7;
const ll INF = (ll)3e18 + 7;
const ll MOD = (ll)998244353; // make sure this is right
pii dir[] = {{1, 0}, {0, 1}, {-1, 0}, {0, -1}};
int L[M], R[M], add[M], timer;
ll t[M];
void push(int v, int tl, int tr) {
if(add[v] == -1) return;
if(tl != tr) {
if(L[v]) {
add[L[v]] = add[v];
}
if(R[v]) {
add[R[v]] = add[v];
}
}
t[v] = 1ll * (tr - tl + 1) * add[v];
add[v] = -1;
}
void upd(int v, int tl, int tr, int l, int r) {
if(tl > r || l > tr)
return;
if(!L[v]) L[v] = ++timer;
if(!R[v]) R[v] = ++timer;
push(v, tl, tr);
if(tl >= l && tr <= r) {
add[v] = 1;
push(v, tl, tr);
return;
}
int mid = (tl + tr) >> 1;
upd(L[v], tl, mid, l, r);
upd(R[v], mid + 1, tr, l, r);
t[v] = t[L[v]] + t[R[v]];
}
ll get(int v, int tl, int tr, int l, int r) {
if(!L[v]) L[v] = ++timer;
if(!R[v]) R[v] = ++timer;
push(v, tl, tr);
if(tl >= l && tr <= r)
return t[v];
if(tl > r || l > tr || !v)
return 0;
int mid = (tl + tr) / 2;
return get(L[v], tl, mid, l, r) + get(R[v], mid + 1, tr, l, r);
}
void solve() {
fill(add, add + M, -1);
int q;
cin >> q;
timer = 1;
int o = 1e9, C = 0;
while(q--) {
int tp;
ll l, r, x;
cin >> tp;
if(tp == 2) {
cin >> l >> r;
upd(1, 1, o, l + C, r + C);
} else {
cin >> l >> r;
cout << (C = get(1, 1, o, l + C, r + C)) << "\n";
}
}
}
signed main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
int test = 1;
//cin >> test;
for(int i = 1; i <= test; ++i) {
//cout << "Case #" << i << ": ";
solve();
}
return 0;
}
Compilation message
apple.cpp: In function 'void solve()':
apple.cpp:13:11: warning: unused variable 'first' [-Wunused-variable]
13 | #define x first
| ^~~~~
apple.cpp:86:12: note: in expansion of macro 'x'
86 | ll l, r, x;
| ^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
21 ms |
58964 KB |
Output is correct |
2 |
Correct |
21 ms |
58964 KB |
Output is correct |
3 |
Incorrect |
22 ms |
59004 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |