제출 #312029

#제출 시각아이디문제언어결과실행 시간메모리
312029wildturtleInterval Collection (CCO20_day2problem2)C++14
22 / 25
4281 ms383096 KiB
#include<bits/stdc++.h> using namespace std; int a,b,t,tree[4000050],treeL[4000050],treeR[4000050]; 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<=4000040;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...