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 <bits/stdc++.h>
using namespace std;
# define mnri first.second
#define mxle first.first
pair <pair <long long, long long> , long long> tree[4000035];
long long x,l,r,le1,ri1,ans,q,mnr,mxl,mx=1000005;
char ch;
multiset<long long>::iterator it;
multiset< long long> le,ri,ms1[1000005],ms2[1000005];
void update(long long node, long long le, long long ri, long long idx, long long val, int ty)
{
if (le>idx || ri<idx) return;
if (le==ri)
{
if (ty==0)
{
tree[node].mnri=val;
}
else tree[node].mxle=val;
tree[node].second=tree[node].mnri-tree[node].mxle;
return;
}
long long mid=(le+ri)/2;
update(2*node,le,mid,idx,val, ty);
update(2*node+1, mid+1, ri, idx, val, ty);
tree[node].mnri=min(tree[2*node].mnri, tree[2*node+1].mnri);
tree[node].mxle=max(tree[2*node].mxle, tree[2*node+1].mxle);
x=min(tree[2*node].second, tree[2*node+1].second);
tree[node].second=min(x,tree[2*node+1].mnri-tree[2*node].mxle);
}
int main()
{
std::ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);
cin>>q;
for (long long i=1; i<=4000020; i++)
{
tree[i].mnri=1000000000;
tree[i].mxle=-1000000000;
tree[i].second=2000000000;
}
while (q--)
{
cin>>ch>>l>>r;
if (ch=='R')
{
le.erase(le.find(l));
ri.erase(ri.find(r));
ms1[l].erase(ms1[l].find(r));
ms2[r].erase(ms2[r].find(l));
if (!ms1[l].size()) ms1[l].insert(1e9);
if (!ms2[r].size()) ms2[r].insert(-1e9);
mnr=*ms1[l].begin();
update(1,1,mx,l,mnr,0);
it=ms2[r].end();
it--;
mxl=*it;
update(1,1,mx,r,mxl,1);
}
else
{
ms1[l].insert(r);
ms2[r].insert(l);
le.insert(l);
ri.insert(r);
mnr=*ms1[l].begin();
it=ms2[r].end();
it--;
mxl=*it;
update(1,1,mx,l,mnr,0);
update(1,1,mx,r,mxl,1);
}
it=le.end();
it--;
mxl=*it;
mnr=*(ri.begin());
if (mnr<=mxl)
{
cout<<tree[1].second<<endl;
}
else
{
ri1=*(ms1[mxl].begin());
it=ms2[mnr].end();
it--;
le1=*it;
cout<<ri1-le1<<endl;
}
}
}
# | 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... |