Submission #874673

#TimeUsernameProblemLanguageResultExecution timeMemory
87467312345678Osumnjičeni (COCI21_osumnjiceni)C++17
110 / 110
242 ms31304 KiB
#include <bits/stdc++.h> using namespace std; const int nx=2e5+5, inf=2e9, kx=18; int n, dp[nx][kx], p, q, l, r; vector<pair<int, int>> v(nx); multiset<pair<int, int>> ms; int main() { cin.tie(NULL)->sync_with_stdio(false); cin>>n; for (int i=1; i<=n; i++) cin>>v[i].first>>v[i].second; ms.insert({-inf, -inf}); ms.insert({inf, inf}); for (int i=1; i<=n; i++) { while (prev(ms.upper_bound(make_pair(v[i].second, INT_MAX)))->second>=v[i].first) ++p, ms.erase(v[p]); dp[i][0]=p+1; ms.insert(v[i]); } for (int i=1; i<kx; i++) for (int j=1; j<=n; j++) dp[j][i]=dp[max(dp[j][i-1]-1, 1)][i-1]; cin>>q; while (q--) { cin>>l>>r; int ans=0; for (int i=kx-1; i>=0; i--) if (dp[r][i]>l) ans+=(1<<i), r=dp[r][i]-1; cout<<ans+1<<'\n'; } }
#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...