#pragma GCC optimize("O3")
//#pragma GCC target("avx2")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define int long long
#define fi first
#define se second
#define pb push_back
#define endl '\n'
mt19937 rng(chrono::steady_clock().now().time_since_epoch().count());
template<typename T>void show(vector<T> &v){
for(auto &i: v){
cout << i << ' ';
}
cout << endl;
}
const int N = 12e6+6, INF = 1e18, LOG = 18, MOD = 1e9+7;
int nxt = 1;
vector<int> L(N),R(N),st(N),lz(N);
void push(int l, int r, int in){
if(lz[in] == 0) return;
if(l != r){
if(!L[in]) L[in] = ++nxt;
if(!R[in]) R[in] = ++nxt;
lz[L[in]] = 1;
lz[R[in]] = 1;
}
st[in] = (r-l+1);
lz[in] = 0;
}
void update(int l, int r, int in, int ql, int qr){
push(l, r, in);
if(l > qr || r < ql) return;
if(ql <= l && r <= qr){
lz[in] = 1;
push(l, r, in);
return;
}
int mid = (l+r)/2;
if(!L[in]) L[in] = ++nxt;
update(l, mid, L[in], ql, qr);
if(!R[in]) R[in] = ++nxt;
update(mid+1, r, R[in], ql, qr);
st[in] = st[L[in]] + st[R[in]];
}
int get(int l, int r, int in, int ql, int qr){
push(l,r,in);
if(ql <= l && r <= qr){
return st[in];
}
int mid = (l+r)/2;
int q1=0,q2=0;
if(ql <= mid){
if(L[in]) q1 = get(l, mid, L[in], ql, qr);
}
if(qr >= mid+1){
if(R[in]) q2 = get(mid+1, r, R[in], ql, qr);
}
return q1+q2;
}
void solve(){
int m;
cin >> m;
int C = 0;
while(m--){
int d,x,y;
cin >> d >> x >> y;
if(d == 1){
int res = get(1, 1e9, 1, x+C, y+C);
cout << res << endl;
C = res;
}
else{
update(1, 1e9, 1, x+C, y+C);
}
}
}
signed main(){
ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
freopen("f.in","r",stdin);
freopen("f.out","w",stdout);
int t = 1;
//cin >> t;
for(int i = 1; i <= t; i++){
//cout << "Scenario #" << i << ": " << endl;
solve();
}
}
컴파일 시 표준 에러 (stderr) 메시지
apple.cpp: In function 'int main()':
apple.cpp:99:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
99 | freopen("f.in","r",stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~
apple.cpp:100:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
100 | freopen("f.out","w",stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |