# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
892515 | 1075508020060209tc | Interval Collection (CCO20_day2problem2) | C++14 | 539 ms | 95268 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#pragma GCC optimize("O3")
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define X first
#define Y second
int Q;
map<pair<int,int>,int>freqseg;
multiset<int>mstv;
map<int,int>mp;
void add(int l,int r){
if(freqseg.size()==1){
mp[r]=l;
return;
}
auto it=mp.lower_bound(r);
if(it==mp.begin()){
mstv.insert((*it).first-l);
mp[r]=l;
return;
}
if(it==mp.end()){
it=prev(it);
mstv.insert(r-(*it).second);
mp[r]=l;
return;
}
int l1=(*it).second;int l2=(*prev(it)).second;
int r1=(*it).first;int r2=(*prev(it)).first;
mstv.erase(mstv.find(r1-l2));
mstv.insert(r1-l);
mstv.insert(r-l2);
mp[r]=l;
}
void del(int l,int r){
auto it=mp.lower_bound(r);
if(it==mp.begin()){
mstv.erase(mstv.find((*next(it)).first-l));
mp.erase(r);
return;
}
if(next(it)==mp.end()){
mstv.erase(mstv.find(r-(*prev(it)).second));
mp.erase(r);
return;
}
int l2=(*it).second;int l1=(*prev(it)).second;
int r2=(*it).first;int r1=(*prev(it)).first;
mstv.insert(r2-l1);
mp[r]=l;
mstv.erase(mstv.find(r2-l));
mstv.erase(mstv.find(r-l1));
}
signed main(){
cin.tie(0);
ios_base::sync_with_stdio(0);
cin>>Q;
while(Q--){
char typ;
cin>>typ;
int l;int r;
cin>>l>>r;
if(typ=='A'){
freqseg[{l,r}]++;
if(freqseg[{l,r}]==1){
add(l,r);
}
}else{
freqseg[{l,r}]--;
if(freqseg[{l,r}]==0){
del(l,r);
freqseg.erase({l,r});
}
}
if(freqseg.size()==1){
int l=(*freqseg.begin()).first.first;
int r=(*freqseg.begin()).first.second;
cout<<r-l<<"\n";
}else{
cout<<(*mstv.begin())<<"\n";
}
}
}
Compilation message (stderr)
# | 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... |