#include<bits/stdc++.h>
#define el '\n'
#define int long long
using namespace std ;
mt19937 rd(chrono::steady_clock::now().time_since_epoch().count());
const int MN = 1e7 + 5;
struct Segtri{
vector<int> st , lazy;
Segtri(int n) : st(4 * n + 5) , lazy(4 * n + 5) {};
void fix(int id , int l , int r){
if (!lazy[id]) return;
st[id] = r - l + 1;
if (l != r){
lazy[id << 1] = lazy[id];
lazy[id << 1 | 1] = lazy[id];
}
lazy[id] = 0;
}
void update(int id , int l , int r , int u , int v , int val){
fix(id , l , r);
if (l > v || r < u) return;
else if (l >= u && r <= v){
lazy[id] = val;
fix(id , l , r);
return;
}
int mid = l + r >> 1;
update(id << 1 , l , mid , u , v , val);
update(id << 1 | 1 , mid + 1 , r , u , v , val);
st[id] = st[id << 1] + st[id << 1 | 1];
}
int get(int id , int l , int r , int u , int v){
fix(id , l , r);
if (l > v || r < u) return 0;
else if (l >= u && r <= v) return st[id];
int mid = l + r >> 1;
return get(id << 1 , l , mid , u , v) + get(id << 1 | 1 , mid + 1 , r , u , v);
}
};
int32_t main (){
ios_base::sync_with_stdio(0);
cin.tie(0);
int m;
cin >> m;
Segtri it(MN);
int last = 0;
for ( int i = 1 ; i <= m ; i++ ){
int type , l , r;
cin >> type >> l >> r;
l += last;
r += last;
if (type == 1){
last = it.get(1 , 1 , MN , l , r);
cout << last << el;
}
else {
it.update(1 , 1 , MN , l , r , 1);
}
}
}
Compilation message
apple.cpp: In member function 'void Segtri::update(long long int, long long int, long long int, long long int, long long int, long long int)':
apple.cpp:33:17: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
33 | int mid = l + r >> 1;
| ~~^~~
apple.cpp: In member function 'long long int Segtri::get(long long int, long long int, long long int, long long int, long long int)':
apple.cpp:43:17: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
43 | int mid = l + r >> 1;
| ~~^~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
69 ms |
262144 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |