Submission #892522

#TimeUsernameProblemLanguageResultExecution timeMemory
8925221075508020060209tcInterval Collection (CCO20_day2problem2)C++14
4 / 25
714 ms87636 KiB
#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.erase(r); 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)

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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...