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;
long long a,b,t,tree[4000035],treeL[4000035],treeR[4000035];
multiset <long long> stl,str,msl[1000005],msr[1000005];
char ch;
#define tavi begin()
#define bolo rbegin()
void update(long long node,long long L,long long R,long long idx,long long mxare) {
if(idx<L || R<idx) return;
if(L==R) {
if(mxare) { if(msr[idx].empty()) treeR[node]=1e9; else treeR[node]=*msr[idx].tavi; }
else { if(msl[idx].empty()) treeL[node]=-1e9; else treeL[node]=*msl[idx].bolo; }
tree[node]=treeR[node]-treeL[node];
return;
}
update(2*node,L,(L+R)/2,idx,mxare);
update(2*node+1,(L+R)/2+1,R,idx,mxare);
tree[node]=min(min(tree[2*node],tree[2*node+1]),treeR[2*node+1]-treeL[2*node]);
treeL[node]=max(treeL[2*node],treeL[2*node+1]);
treeR[node]=min(treeR[2*node],treeR[2*node+1]);
}
int main() {
std::ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);
for (long long i=1;i<=4000020;i++) {
tree[i]=2*1e9; treeL[i]=-1e9; treeR[i]=1e9;
}
cin>>t;
while(t--) {
cin>>ch>>a>>b;
if(ch=='A') {
stl.insert(a);
str.insert(b);
msl[b].insert(a);
msr[a].insert(b);
update(1,1,1e6+5,b,0);
update(1,1,1e6+5,a,1);
}
else {
stl.erase(stl.find(a));
str.erase(str.find(b));
msl[b].erase(msl[b].find(a));
msr[a].erase(msr[a].find(b));
update(1,1,1e6+5,b,0);
update(1,1,1e6+5,a,1);
}
if(*(stl.bolo)<=*(str.tavi)) cout<<*(msr[*(stl.bolo)].tavi)-*(msl[*(str.tavi)].bolo)<<endl;
else cout<<tree[1]<<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... |