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 N=2e6+5;
const int MOD=1e9+7;
int n;
int p[N];
int ans=1;
stack<pair<int,int>> s;
int main(){
cin.tie(nullptr)->sync_with_stdio(false);
cin >> n;
for(int i=0;i<n;i++){
int l,r;
cin >> l >> r;
p[l]=r;
}
s.emplace(2*n+1,0);
for(int i=1;i<=2*n;i++)if(p[i]){
while(i>s.top().first)s.pop();
auto &[mx,mx2]=s.top();
if(p[i]>mx){
if(i<mx2)cout << 0,exit(0);
else mx2=mx,mx=p[i];
}else{
if(i<mx2&&mx2<p[i])mx2=p[i];
else{
s.emplace(p[i],i);
ans*=2;
if(ans>=MOD)ans-=MOD;
}
}
}
cout << ans;
}
# | 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... |