#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
#define N "\n"
#define all(object) object.begin(), object.end()
#define sz(object) (int)object.size()
#define ph push_back
#define pp pop_back
#define ss second
#define ff first
inline void ZoTH(string name = "")
{
ios_base::sync_with_stdio(false),
cin.tie(nullptr),
cout.tie(nullptr);
if (sz(name))
{
freopen((name + ".in").c_str(), "r", stdin);
freopen((name + ".out").c_str(), "w", stdout);
}
}
struct node
{
int sum , lft , rgt ;
bool lazy ;
node * left , * right ;
node (int s,int _lft,int _rgt,node * l=nullptr, node* r=nullptr)
{
sum= s ;
lft = _lft;
rgt = _rgt ;
left = l ;
right = r ;
lazy=0;
}
void mrg()
{
if(!lazy)
sum =(left?left->sum:0)+(right?right->sum:0);
else sum = rgt-lft+1;
if(left) left->lazy |=lazy;
if(right) right->lazy |=lazy ;
}
};
void update(node * at , ll lq,ll rq)
{
if(lq<=at->lft&&at->rgt<=rq)
{
at->lazy=1;
at->mrg();
}
else
{
int m =(at->lft+at->rgt)/2;
int l = at->lft ;
int r= at->rgt;
if(lq<=m)
{
if(!at->left)at->left=new node(0,l,m);
at->mrg();
update(at->left,lq,rq);
}
if(m+1<=rq)
{
if(!at->right)at->right=new node(0,m+1,r);
at->mrg();
update(at->right,lq,rq) ;
}
at->mrg();
}
}
int take(node*at,int lq,int rq)
{
if(lq<=at->lft&&at->rgt<=rq)
{
at->mrg();
return at->sum;
}
int m =(at->lft+at->rgt)/2;
int l = at->lft ;
int r= at->rgt;
int ret =0 ;
if(lq<=m)
{
if(!at->left)at->left=new node(0,l,m);
at->mrg();
ret+=take(at->left,lq,rq) ;
}
if(m+1<=rq)
{
if(!at->right)at->right=new node(0,m+1,r);
at->mrg();
ret+=take(at->right,lq,rq) ;
}
at->mrg();
return ret ;
}
void solve(int t)
{
// Goooo
const int n = (int)1e9+2;
int m ;
cin>>m ;
node *root = new node (0,1,n);
int c=0 ;
while(m--)
{
int x ,t, y ;
cin>>t>> x >> y ;
if(t==1)
{
c = take(root,x+c,y+c);
cout << c << N ;
}else{
update(root,x+c,y+c);
}
}
// stooo
}
int main()
{
ZoTH("");
// T_BEGIN
int t = 1;
// cin >> t;
for (int i = 1; i <= t; i++)
{
// cout << "Case " << i << ": ";
solve(i);
cout << N;
}
}
Compilation message
apple.cpp: In function 'void ZoTH(std::string)':
apple.cpp:22:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
22 | freopen((name + ".in").c_str(), "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
apple.cpp:23:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
23 | freopen((name + ".out").c_str(), "w", stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
344 KB |
Output is correct |
4 |
Correct |
10 ms |
3932 KB |
Output is correct |
5 |
Correct |
12 ms |
4700 KB |
Output is correct |
6 |
Correct |
12 ms |
4440 KB |
Output is correct |
7 |
Correct |
12 ms |
4700 KB |
Output is correct |
8 |
Correct |
118 ms |
34108 KB |
Output is correct |
9 |
Correct |
230 ms |
59400 KB |
Output is correct |
10 |
Correct |
215 ms |
65360 KB |
Output is correct |
11 |
Correct |
217 ms |
70192 KB |
Output is correct |
12 |
Correct |
241 ms |
72252 KB |
Output is correct |
13 |
Correct |
193 ms |
83716 KB |
Output is correct |
14 |
Correct |
200 ms |
84504 KB |
Output is correct |
15 |
Correct |
323 ms |
152880 KB |
Output is correct |
16 |
Correct |
317 ms |
153936 KB |
Output is correct |
17 |
Correct |
213 ms |
87172 KB |
Output is correct |
18 |
Correct |
197 ms |
87124 KB |
Output is correct |
19 |
Correct |
312 ms |
157240 KB |
Output is correct |
20 |
Correct |
309 ms |
157260 KB |
Output is correct |