Submission #967140

#TimeUsernameProblemLanguageResultExecution timeMemory
967140ttamxPort Facility (JOI17_port_facility)C++17
0 / 100
0 ms344 KiB
#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 x; cin >> x >> p[x]; } 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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...