Submission #745201

#TimeUsernameProblemLanguageResultExecution timeMemory
745201Ahmed57Osumnjičeni (COCI21_osumnjiceni)C++17
0 / 110
239 ms25172 KiB
//LCA #include <bits/stdc++.h> using namespace std; int main(){ int n; cin>>n; int P[n+1][19]; for(int i = 0;i<=n;i++)P[i][0]= n; set<pair<pair<int,int>,int>> s; set<int> ind; for(int i = 0;i<n;i++)ind.insert(i); for(int i = 0;i<n;i++){ int a,b;cin>>a>>b; int ma = -1; pair<pair<int,int>,int> p = {{a,0},0}; auto it = s.lower_bound(p); if(it!=s.begin()){ it--; if((*it).first.second>=a){ ma = max(ma,(*it).second); s.erase(it); } } it = s.lower_bound(p); if(it!=s.end()&&(*it).first.first<=b){ ma = max(ma,(*it).second); s.erase(it); it = s.lower_bound(p); } p.second = i; p.first.second = b; s.insert(p); while(!ind.empty()&&(*ind.begin())<=ma){ P[(*ind.begin())][0] = i; ind.erase(ind.begin()); } } for(int i = n;i>=0;i--){ for(int j= 1;j<19;j++){ P[i][j] = P[P[i][j-1]][j-1]; } } int q;cin>>q; while(q--){ int x,y;cin>>x>>y; x--;y--; long long sum = 0; for(int j = 18;j>=0;j--){ if(P[x][j]<=y){ x = P[x][j]; sum+=(1<<j); } } cout<<sum+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...