Submission #892519

# Submission time Handle Problem Language Result Execution time Memory
892519 2023-12-25T13:04:04 Z 1075508020060209tc Interval Collection (CCO20_day2problem2) C++14
0 / 25
526 ms 87632 KB
#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=(*next(it)).second;int l1=(*prev(it)).second;
int r2=(*next(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

Main.cpp: In function 'void add(long long int, long long int)':
Main.cpp:30:5: warning: unused variable 'l1' [-Wunused-variable]
   30 | int l1=(*it).second;int l2=(*prev(it)).second;
      |     ^~
Main.cpp:31:24: warning: unused variable 'r2' [-Wunused-variable]
   31 | int r1=(*it).first;int r2=(*prev(it)).first;
      |                        ^~
Main.cpp: In function 'void del(long long int, long long int)':
Main.cpp:51:5: warning: unused variable 'l2' [-Wunused-variable]
   51 | int l2=(*next(it)).second;int l1=(*prev(it)).second;
      |     ^~
Main.cpp:52:30: warning: unused variable 'r1' [-Wunused-variable]
   52 | int r2=(*next(it)).first;int r1=(*prev(it)).first;
      |                              ^~
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 600 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 600 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 600 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 218 ms 35188 KB Output is correct
2 Correct 192 ms 35052 KB Output is correct
3 Correct 397 ms 70164 KB Output is correct
4 Correct 382 ms 70120 KB Output is correct
5 Correct 526 ms 87376 KB Output is correct
6 Correct 487 ms 87632 KB Output is correct
7 Runtime error 1 ms 600 KB Execution killed with signal 6
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 600 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -