#include "bits/stdc++.h"
#define MAXN 100009
#define INF 1000000007
#define mp(x,y) make_pair(x,y)
#define all(v) v.begin(),v.end()
#define pb(x) push_back(x)
#define wr cout<<"----------------"<<endl;
#define ppb() pop_back()
#define tr(ii,c) for(__typeof((c).begin()) ii=(c).begin();ii!=(c).end();ii++)
#define ff first
#define ss second
#define my_little_dodge 46
#define debug(x) cerr<< #x <<" = "<< x<<endl;
using namespace std;
typedef long long ll;
typedef pair<int,int> PII;
template<class T>bool umin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
template<class T>bool umax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
struct node {
int mn,ans,lazy,l,r;
node(){
l=r=-1;
}
}s[4000009];
const int B=1e9;
int nd;
void merge(int v,int l,int r){
s[v].mn=min(s[l].mn,s[r].mn);
s[v].ans=0;
if(s[l].mn==s[v].mn)
s[v].ans+=s[l].ans;
if(s[r].mn==s[v].mn)
s[v].ans+=s[r].ans;
}
void add(int v,int val){
s[v].lazy+=val;
s[v].mn+=val;
}
void shift(int v){
if(v==-1 or s[v].lazy==0)
return;
add(s[v].l,s[v].lazy);
add(s[v].r,s[v].lazy);
s[v].lazy=0;
}
int give(){nd++;
if(nd<4000009)
return nd;
return 1;
}
void inc(int v,int l,int r,int x=1,int y=B){
if(v==-1 or l>y or x>r or l>r)
return;
if(l<=x and y<=r){
//cout<<"$ "<<x<<" "<<y<<endl;
add(v,1);
return;
}
int mid=(x+y)>>1;
if(s[v].l==-1){
s[v].l=give();
s[nd].ans=mid-x+1;
s[nd].mn=s[nd].lazy=0;
}
if(s[v].r==-1){
s[v].r=give();
s[nd].ans=y-mid;
s[nd].mn=s[nd].lazy=0;
}
shift(v);
inc(s[v].l,l,r,x,mid);
inc(s[v].r,l,r,mid+1,y);
merge(v,s[v].l,s[v].r);
}
PII ans[22];int p;
void get(int v,int l,int r,int x=1,int y=B){
if(v==-1 or l>y or x>r or l>r or x>y)
return;
if(l<=x and y<=r){
//cout<<x<<" "<<y<<" $ "<<v->mn<<" "<<v->ans<<endl;
ans[p++]=mp(s[v].mn,s[v].ans);
return;
}
int mid=(x+y)>>1;
if(s[v].l==-1){
s[v].l=give();
s[nd].ans=mid-x+1;
s[nd].mn=s[nd].lazy=0;
}
if(s[v].r==-1){
s[v].r=give();
s[nd].ans=y-mid;
s[nd].mn=s[nd].lazy=0;
}
shift(v);
get(s[v].l,l,r,x,mid);
get(s[v].r,l,r,mid+1,y);
merge(v,s[v].l,s[v].r);
}
int main(){
//freopen("file.in", "r", stdin);
s[0].ans=B;s[0].lazy=s[0].mn=0;
int q,c=0;
scanf("%d",&q);
while(q--){
int t;int l,r;
scanf("%d%d%d",&t,&l,&r);l+=c;r+=c;
if(t==2)
inc(0,l,r);
else{
p=0;get(0,l,r);int mn=INF;
for(int i=0;i<p;i++)
umin(mn,ans[i].ff);
if(mn>0)
c=r-l+1;
else{
c=(r-l+1);
for(int i=0;i<p;i++)
if(ans[i].ff==0)
c-=ans[i].ss;
}
printf("%d\n",c);
}
}
return 0;
}
Compilation message
apple.cpp: In function 'int main()':
apple.cpp:105:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
105 | scanf("%d",&q);
| ~~~~~^~~~~~~~~
apple.cpp:108:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
108 | scanf("%d%d%d",&t,&l,&r);l+=c;r+=c;
| ~~~~~^~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
43 ms |
78572 KB |
Output is correct |
2 |
Correct |
43 ms |
78572 KB |
Output is correct |
3 |
Correct |
44 ms |
78572 KB |
Output is correct |
4 |
Runtime error |
147 ms |
159212 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
5 |
Halted |
0 ms |
0 KB |
- |