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>
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef pair<ull, ull> pull;
typedef pair<int, int> pii;
typedef pair<ld, ld> pld;
map<pair<ll, pair<stack<pll>, stack<pll>>>, ll> dp;
map<pair<ll, pair<stack<pll>, stack<pll>>>, ll> calc;
ll n;
pll ar[1000009];
ll mod = 1e9+7;
map<pair<stack<pll>, stack<pll>>, ll> mpp;
map<pair<stack<pll>, stack<pll>>, ll> mppnew;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
//freopen("in.txt", "r", stdin);
//freopen("out.txt", "w", stdout);
cin >> n;
for(ll i = 0; i < n; ++i)
cin >> ar[i].ff >> ar[i].ss;
sort(ar, ar+n);
stack<pll> tmp;
tmp.push({0, 1e18});
mpp[{tmp, tmp}] = 1;
for(ll i = 0; i < n; ++i){
for(auto u : mpp){
stack<pll> tmpa = u.ff.ff;
stack<pll> tmpb = u.ff.ss;
while(tmpa.top().ss < ar[i].ff)
tmpa.pop();
while(tmpb.top().ss < ar[i].ff)
tmpb.pop();
if(tmpa.top().ss > ar[i].ss){
tmpa.push(ar[i]);
mppnew[{tmpa, tmpb}] += u.ss;
mppnew[{tmpa, tmpb}] %= mod;
tmpa.pop();
}
if(tmpb.top().ss > ar[i].ss){
tmpb.push(ar[i]);
mppnew[{tmpa, tmpb}] += u.ss;
mppnew[{tmpa, tmpb}] %= mod;
tmpb.pop();
}
}
mpp = mppnew;
mppnew.clear();
}
ll ans = 0;
for(auto u : mpp){
ans = (ans+u.ss)%mod;
}
cout << ans << "\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... |