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 MAXN 100009
#define INF 1000000007
#define mp(x,y) make_pair(x,y)
#define all(v) v.begin(),v.end()
#define pb(x) push_back(x)
#define wr cout<<"----------------"<<endl;
#define ppb() pop_back()
#define tr(ii,c) for(__typeof((c).begin()) ii=(c).begin();ii!=(c).end();ii++)
#define ff first
#define ss second
#define my_little_dodge 46
#define next nasa
#define debug(x) cerr<< #x <<" = "<< x<<endl;
using namespace std;
typedef long long ll;
typedef pair<int,int> PII;
template<class T>bool umin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
template<class T>bool umax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
const int N=505;
map<int,int>vis;
map<int,vector<int> >add,rem;
set<int>s;
vector<int>v;
int arr[N],inv[N],par[N],dp[N],DP[N][N];
int mod(ll x){
while(x<0)
x+=INF;
return (x%INF);
}
int Fe(int x,int y){
if(!y)
return 1;
int h=Fe(x,y/2);
h=mod(h*1LL*h);
if(y&1)
h=mod(h*1LL*x);
return h;
}
void pre(int x,int y){
arr[0]=1;
int bug=x;
for(int i=1;i<=min(bug,y);i++){
arr[i]=mod(arr[i-1]*1LL*x);x--;
arr[i]=mod(arr[i]*1LL*inv[i]);
}
}
int rec(int x,int y){
if(x<0)
return 0;
int &ret=DP[x][y];
if(~ret)
return ret;
if(!y)
return ret=mod(rec(x-1,y)+par[v[x]-1]);
return ret=mod(rec(x-1,y)+rec(x-1,y-1));
}
int main(){
//~ freopen("file.in", "r", stdin);
inv[0]=1;
for(int i=1;i<N;i++)
inv[i]=Fe(i,INF-2);
int n;
scanf("%d",&n);
for(int i=1;i<=n;i++){
int l,r;
scanf("%d%d",&l,&r);
vis[l]=vis[r+1]=1;
//~ cout<<"add "<<l<<endl;
//~ cout<<"rem "<<r+1<<endl;
add[l].pb(i);
rem[r+1].pb(i);
}
tr(itt,vis){
int now=itt->ff,next;
__typeof((vis).begin())tmp=itt;tmp++;
if(tmp!=vis.end())
next=tmp->ff;
else
break;
tr(it,add[now])
s.insert(*it);
tr(it,rem[now])
s.erase(*it);
if(s.size()){
int m=s.size();
pre(next-now,m);
par[0]=1;
for(int i=1;i<=n;i++)
par[i]=mod(par[i-1]+dp[i]);
v.clear();
tr(it,s)
v.pb(*it);
memset(DP,-1,sizeof DP);
for(int i=0;i<m;i++)
for(int j=0;j<=min(next-now-1,i);j++){
if(!j)
dp[v[i]]=mod(dp[v[i]]+mod(arr[j+1]*1LL*par[v[i]-1]));
else
dp[v[i]]=mod(dp[v[i]]+mod(arr[j+1]*1LL*rec(i-1,j-1)));
}
}
}
int ans=0;
for(int i=1;i<=n;i++)
ans=mod(ans+dp[i]);
printf("%d\n",ans);
return 0;
}
Compilation message (stderr)
boat.cpp: In function 'int main()':
boat.cpp:65:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d",&n);
~~~~~^~~~~~~~~
boat.cpp:68:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d",&l,&r);
~~~~~^~~~~~~~~~~~~~
# | 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... |