This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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 time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |