#include <bits/stdc++.h>
// include <ext/pb_ds/assoc_container.hpp>
// include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;
using namespace std;
#define all(x) x.begin(), x.end()
#define pb push_back
// define ordered_set tree<int,null_type,less_equal<int>,rb_tree_tag,tree_order_statistics_node_update>
#define mpr make_pair
#define ln '\n'
void IO(string name){freopen((name+".in").c_str(),"r",stdin); freopen((name+".out").c_str(),"w",stdout);}
#define int long long
const int N = 1e7+1;
int T[N*4], lazy[N*4];
void push(int v, int l, int r){
if ( !lazy[v] ) return;
if ( l != r ){
lazy[v*2] += lazy[v];
lazy[v*2+1] += lazy[v];
}
T[v] = (r-l+1)*lazy[v];
lazy[v] = 0;
}
void upd(int v, int l, int r, int tl, int tr){
push(v, l, r);
if ( l > tr or r < tl ) return;
if ( tl <= l and tr >= r ){
lazy[v]++;
push(v, l, r);
return;
}
int md = (l+r)>>1;
upd(v*2, l, md, tl, tr), upd(v*2+1, md+1, r, tl, tr);
T[v] = T[v*2]+T[v*2+1];
}
int get(int v, int l, int r, int tl, int tr){
push(v, l, r);
if ( l > tr or tl > r ) return 0;
if ( tl <= l and tr >= r ) return T[v];
int md = (l+r)>>1;
return get(v*2, l, md, tl, tr)+get(v*2+1, md+1, r, tl, tr);
}
signed main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int q; cin >> q;
int C = 0;
while ( q-- ){
int t, x, y; cin >> t >> x >> y;
x += C, y += C;
if ( t == 1 ){
int res = get(1, 1, N-1, x, y);
cout << res << ln;
C = res;
}
else upd(1, 1, N-1, x, y);
}
cout << '\n';
}
Compilation message
apple.cpp: In function 'void IO(std::string)':
apple.cpp:11:29: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
11 | void IO(string name){freopen((name+".in").c_str(),"r",stdin); freopen((name+".out").c_str(),"w",stdout);}
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
apple.cpp:11:70: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
11 | void IO(string name){freopen((name+".in").c_str(),"r",stdin); freopen((name+".out").c_str(),"w",stdout);}
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
468 KB |
Output is correct |
3 |
Incorrect |
1 ms |
468 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |