Submission #312028

#TimeUsernameProblemLanguageResultExecution timeMemory
312028wildturtleInterval Collection (CCO20_day2problem2)C++14
0 / 25
2171 ms412168 KiB
#include<bits/stdc++.h> using namespace std; int a,b,t,tree[2000020],treeL[2000020],treeR[2000020]; multiset <int> stl,str,msl[1000006],msr[1000006]; char ch; #define tavi begin() #define bolo rbegin() void update(int node,int L,int R,int idx,int 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 (int i=1;i<=2000010;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+1,b,0); update(1,1,1e6+1,a,1); } else { stl.erase(stl.find(a)); str.erase(str.find(b)); msl[b].erase(a); msr[a].erase(b); update(1,1,1e6+1,b,0); update(1,1,1e6+1,a,1); } if(*(stl.bolo)<=*(str.tavi)) cout<<*(msr[*(stl.bolo)].tavi)-*(msl[*(str.tavi)].bolo)<<endl; else cout<<tree[1]<<endl; } }
#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...