#include <bits/stdc++.h>
#define ll long long
#define str string
#define ins insert
#define ld long double
#define pb push_back
#define pf push_front
#define pof pop_front()
#define pob pop_back()
#define lb lower_bound
#define ub upper_bound
#define endl "\n"
#define fr first
#define sc second
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define sz size()
#define vll vector<ll>
#define bc back()
#define arr array
using namespace std;
template <class _T>
bool chmin(_T &x, const _T &y){
if (x>y)x=y;
return x>y;
}
template <class _T>
bool chmax(_T &x, const _T &y){
if (x<y)x=y;
return x<y;
}
//void fre(string s){freopen((s+".in").c_str(),"r",stdin);freopen((s+".out").c_str(),"w",stdout);}
void start(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
}
const ll inf=1e18+7;
const ll mod=1e9+7;
const ll N=1e6+5;
const ld eps=1e-9;
struct node{
ll l,r,ans;
node(){
l=-inf;
r=inf;
ans=inf;
}
};
vector<node> t(N*4);
multiset<ll> mr[N],ml[N];
void upd(ll id,ll pos,ll val,ll v=1,ll tl=1,ll tr=N){
if(tl>pos || tr<pos) return ;
if(tl==tr){
if(id==1){
ml[pos].ins(val);
t[v].l=*ml[tl].rbegin();
}
else {
mr[pos].ins(val);
t[v].r=*mr[tl].begin();
}
t[v].ans=t[v].r-t[v].l;
return;
}
ll tm=(tl+tr)/2;
upd(id,pos,val,v*2,tl,tm);
upd(id,pos,val,v*2+1,tm+1,tr);
t[v].l=max(t[v*2].l,t[v*2+1].l);
t[v].r=min(t[v*2].r,t[v*2+1].r);
t[v].ans=min({t[v*2+1].r-t[v*2].l,t[v*2].ans,t[v*2+1].ans});
}
void er(ll id,ll pos,ll val,ll v=1,ll tl=1,ll tr=N){
if(tl>pos || tr<pos) return ;
if(tl==tr){
if(id==1){
ml[pos].erase(ml[pos].find(val));
t[v].l=*ml[tl].rbegin();
}
else {
mr[pos].erase(mr[pos].find(val));
t[v].r=*mr[tl].begin();
}
t[v].ans=t[v].r-t[v].l;
return;
}
ll tm=(tl+tr)/2;
er(id,pos,val,v*2,tl,tm);
er(id,pos,val,v*2+1,tm+1,tr);
t[v].l=max(t[v*2].l,t[v*2+1].l);
t[v].r=min(t[v*2].r,t[v*2+1].r);
t[v].ans=min({t[v*2+1].r-t[v*2].l,t[v*2].ans,t[v*2+1].ans});
}
ll get(ll id,ll pos,ll v=1,ll tl=1,ll tr=N){
if(tl>pos || tr<pos) return (id==1 ? -inf : inf);
if(tl==tr) return (id==1 ? t[v].l : t[v].r);
ll tm=(tl+tr)/2;
ll a=get(id,pos,v*2,tl,tm);
ll b=get(id,pos,v*2+1,tm+1,tr);
if(id==1) return max(a,b);
else return min(a,b);
}
void solve(){
ll i;
ll n;
cin>>n;
char ch;
ll l,r;
multiset<ll> ls,rs;
for(i=0;i<N;i++){
ml[i].ins(-inf);
mr[i].ins(inf);
}
for(i=0;i<n;i++){
cin>>ch;
cin>>l>>r;
if(ch=='A'){
ls.ins(l);
rs.ins(r);
upd(1,r,l);
upd(2,l,r);
}else{
ls.erase(ls.find(l));
rs.erase(rs.find(r));
er(1,r,l);
er(2,l,r);
}
if(*ls.rbegin()>=*rs.begin()){
cout<<t[1].ans<<endl;
}else{
ll mxl=get(1,*rs.begin()),mnr=get(2,*ls.rbegin());
cout<<mnr-mxl<<endl;
}
}
}
signed main(){
start();
ll t=1;
// cin>>t;
while(t--) solve();
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |