This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <iostream>
#include <vector>
#include <set>
using namespace std;
struct ura
{
    int a,b;
};
vector<ura>vecus[500005];
vector<ura>vec;
const int nmax=10000005;
int aint[nmax*4];
int aint2[nmax*4];
int inf=1e9+5;
int inter(int i,int j)
{
    return max(0,min(vec[i].b,vec[j].b)-max(vec[i].a,vec[j].a));
}
int reun(int i,int j)
{
    return max(vec[i].b,vec[j].b)-min(vec[i].a,vec[j].a);
}
long long distsol,cost;
multiset<int>lfend;
multiset<int>rgend;
/// qr1 pe partea dreapta
struct undos
{
    int unde,pozupdate,delacat;
};
vector<undos>oper;
int qr1(int node,int st,int dr,int qst,int qdr)
{
    if(st>qdr || st>dr || qst>dr || qst>qdr)
    {
        return inf;
    }
    if(qst<=st && dr<=qdr)
    {
        return aint[node];
    }
    int mij=(st+dr)/2;
    return min(qr1(node*2,st,mij,qst,qdr),qr1(node*2+1,mij+1,dr,qst,qdr));
}
int qr2(int node,int st,int dr,int qst,int qdr)
{
    if(st>qdr || st>dr || qst>dr || qst>qdr)
    {
        return -inf;
    }
    if(qst<=st && dr<=qdr)
    {
        return aint2[node];
    }
    int mij=(st+dr)/2;
    return max(qr2(node*2,st,mij,qst,qdr),qr2(node*2+1,mij+1,dr,qst,qdr));
}
void update1(int node,int st,int dr,int poz,int val,int smech)
{
    if(st>poz || poz>dr)
    {
        return ;
    }
    if(poz<=st && dr<=poz)
    {
        if(smech==1)
        {
            aint[node]=val;
        }
        else
        {
            oper.push_back({1,poz,aint[node]});
            aint[node]=min(aint[node],val);
        }
        return;
    }
    int mij=(st+dr)/2;
    update1(node*2,st,mij,poz,val,smech);
    update1(node*2+1,mij+1,dr,poz,val,smech);
    aint[node]=min(aint[node*2],aint[node*2+1]);
}
void update2(int node,int st,int dr,int poz,int val,int smech)
{
    if(st>poz || poz>dr)
    {
        return ;
    }
    if(poz<=st && dr<=poz)
    {
        if(smech==1)
        {
            aint2[node]=val;
        }
        else
        {
            oper.push_back({2,poz,aint2[node]});
            aint2[node]=max(aint2[node],val);
        }
        return;
    }
    int mij=(st+dr)/2;
    update2(node*2,st,mij,poz,val,smech);
    update2(node*2+1,mij+1,dr,poz,val,smech);
    aint2[node]=max(aint2[node*2],aint2[node*2+1]);
}
void clr(int node,int st,int dr)
{
    aint2[node]=-inf;
    aint[node]=inf;
    if(st!=dr)
    {
        int mij=(st+dr)/2;
        clr(node*2,st,mij);
        clr(node*2+1,mij+1,dr);
    }
}
multiset<pair<int,int> >solutii;
void undo()
{
    undos a;
    a=oper.back();
    if(a.unde==1)
    {
        update1(1,1,nmax,a.pozupdate,a.delacat,1);
    }
    else
    {
        update2(1,1,nmax,a.pozupdate,a.delacat,1);
    }
    oper.pop_back();
}
void add(ura x)
{
    int sol=inf,cost=inf,supra=inf,nosupra=inf,supra1=inf,nosupra1=inf;
    if(lfend.size() && x.b>*prev(lfend.end()))
    {
        supra=x.b-*prev(lfend.end());
        nosupra=qr1(1,1,nmax,*prev(lfend.end()),nmax)-x.a;
    }
    else if(lfend.size())
    {
        supra=0;
        nosupra=qr1(1,1,nmax,x.b,nmax)-x.a;
    }
    lfend.insert(x.a);
    update1(1,1,nmax,x.a,x.b,0);
    if(rgend.size() && x.a<=*rgend.begin())
    {
        supra1=*rgend.begin()-x.a;
        nosupra1=x.b-qr2(1,1,nmax,1,*rgend.begin());
    }
    else if(rgend.size())
    {
        supra1=0;
        nosupra1=x.b-qr2(1,1,nmax,1,x.a);
    }
    rgend.insert(x.b);
    update2(1,1,nmax,x.b,x.a,0);
    if(supra1<supra)
    {
        swap(supra1,supra);
        swap(nosupra1,nosupra);
    }
    else if(supra1==supra)
    {
        nosupra=min(nosupra1,nosupra);
    }
    if(supra>x.b-x.a)
    {
        supra=x.b-x.a;
        nosupra=x.b-x.a;
    }
    solutii.insert({supra,nosupra});
}
int main()
{
    int n,i,j,k,l,r,z;
    cin>>n;
    char tip;
    for(i=1; i<=n; i++)
    {
        cin>>tip;
        if(tip=='A')
        {
            cin>>l>>r;
            vec.push_back({l,r});
        }
        else if(tip=='R')
        {
            cin>>l>>r;
            for(j=0; j<vec.size(); j++)
            {
                if(vec[j].a==l && vec[j].b==r)
                {
                    vec.erase(vec.begin()+j);
                    break;
                }
            }
        }
        for(j=0; j<vec.size(); j++)
            vecus[i].push_back({vec[j]});
    }
    clr(1,1,nmax);
    for(i=1; i<=n; i++)
    {
        distsol=inf;
        cost=0;
        lfend.clear();
        rgend.clear();
        solutii.clear();
        for(j=0; j<vecus[i].size(); j++)
        {
            add(vecus[i][j]);
        }
        cout<<solutii.begin()->second<<'\n';
        while(oper.size()>0)
        {
            undo();
        }
    }
    return 0;
}
Compilation message (stderr)
Main.cpp: In function 'void add(ura)':
Main.cpp:135:9: warning: unused variable 'sol' [-Wunused-variable]
  135 |     int sol=inf,cost=inf,supra=inf,nosupra=inf,supra1=inf,nosupra1=inf;
      |         ^~~
Main.cpp:135:17: warning: unused variable 'cost' [-Wunused-variable]
  135 |     int sol=inf,cost=inf,supra=inf,nosupra=inf,supra1=inf,nosupra1=inf;
      |                 ^~~~
Main.cpp: In function 'int main()':
Main.cpp:192:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<ura>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  192 |             for(j=0; j<vec.size(); j++)
      |                      ~^~~~~~~~~~~
Main.cpp:201:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<ura>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  201 |         for(j=0; j<vec.size(); j++)
      |                  ~^~~~~~~~~~~
Main.cpp:212:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<ura>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  212 |         for(j=0; j<vecus[i].size(); j++)
      |                  ~^~~~~~~~~~~~~~~~
Main.cpp:178:15: warning: unused variable 'k' [-Wunused-variable]
  178 |     int n,i,j,k,l,r,z;
      |               ^
Main.cpp:178:21: warning: unused variable 'z' [-Wunused-variable]
  178 |     int n,i,j,k,l,r,z;
      |                     ^| # | 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... |