#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using T = tuple<ll, ll, ll>;
#define int long long
#define Base 41
#define sz(a) (int)a.size()
#define FOR(i, a, b) for ( int i = a ; i <= b ; i++ )
#define FORD(i, a, b) for (int i = b; i >= a; i --)
#define REP(i, n) for (int i = 0; i < n; ++i)
#define REPD(i, n) for (int i = n - 1; i >= 0; --i)
#define all(x) x.begin() , x.end()
#define pii pair<int , int>
#define fi first
#define se second
#define Lg(x) 31 - __builtin_clz(x)
#define MASK(i) (1LL << (i))
#define BIT(x, i) (((x) >> (i)) & 1)
constexpr ll LINF = (1ll << 60);
constexpr int INF = 1e9;
constexpr int MAX = 2e5 + 5;
constexpr int Mod = 1e9 + 7;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
void setupIO(){
#define name "Whisper"
//Phu Trong from Nguyen Tat Thanh High School for gifted student
srand(time(NULL));
cin.tie(nullptr)->sync_with_stdio(false); cout.tie(nullptr);
//freopen(name".inp", "r", stdin);
//freopen(name".out", "w", stdout);
cout << fixed << setprecision(10);
}
template <class X, class Y>
bool minimize(X &x, const Y &y){
X eps = 1e-9;
if (x > y + eps) {x = y; return 1;}
return 0;
}
template <class X, class Y>
bool maximize(X &x, const Y &y){
X eps = 1e-9;
if (x + eps < y) {x = y; return 1;}
return 0;
}
int Q;
struct Node{
int l, r, val, lzy;
Node(): l(-1), r(-1), val(0), lzy(0){}
Node(int _l, int _r, int _val, int _lzy): l(_l), r(_r), val(_val), lzy(_lzy){}
};
struct SparseSegmentTree{
vector<Node> f;
int n;
SparseSegmentTree(): f(MAX * 60), n(1){}
void pushDown(int id, int l, int r){
if (!f[id].lzy) return;
if (f[id].l == -1)
f[id].l = ++n;
if (f[id].r == -1)
f[id].r = ++n;
int mid = (l + r) >> 1;
int &res = f[id].lzy;
f[f[id].l].lzy = res;
f[f[id].r].lzy = res;
f[f[id].l].val = (mid - l + 1) * res;
f[f[id].r].val = (r - mid) * res;
f[id].lzy = 0;
}
void modify(int u, int v, int val, int id = 1, int l = 1, int r = INF){
if (u > r || v < l) return;
if (u <= l && v >= r){
f[id].val = val * (r - l + 1);
f[id].lzy = val;
return;
}
if (f[id].l == -1)
f[id].l = ++n;
if (f[id].r == -1)
f[id].r = ++n;
int mid = (l + r) >> 1;
pushDown(id, l, r);
modify(u, v, val, f[id].l, l, mid);
modify(u, v, val, f[id].r, mid + 1, r);
f[id].val = f[f[id].l].val + f[f[id].r].val;
}
int query(int u, int v, int id = 1, int l = 1, int r = INF){
if (u > r || v < l) return 0;
if (u <= l && v >= r) return f[id].val;
int mid = (l + r) >> 1;
pushDown(id, l, r);
int ql = query(u, v, f[id].l, l, mid);
int qr = query(u, v, f[id].r, mid + 1, r);
return ql + qr;
}
};
void Whisper(){
cin >> Q;
int c = 0;
SparseSegmentTree st;
for (int i = 1; i <= Q; ++i){
int cmd, l, r;
cin >> cmd >> l >> r;
l += c, r += c;
if (cmd == 1){
c = st.query(l, r);
cout << c << '\n';
}
else{
st.modify(l, r, 1);
}
}
}
signed main(){
setupIO();
int Test = 1;
// cin >> Test;
for ( int i = 1 ; i <= Test ; i++ ){
Whisper();
if (i < Test) cout << '\n';
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
60 ms |
262144 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |