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;
#define int long long
const int mod=(int)1e9+7;
const int maxn=505;
int sz,a[maxn],b[maxn];
vector<int>v,s;
int bit[1000005];
void update(int pos,int val)
{
while(pos<=sz)
{
bit[pos]+=val;
if(bit[pos]>=mod) bit[pos]-=mod;
pos+=pos&(-pos);
}
}
int get(int pos)
{
int ans=0;
while(pos>0)
{
ans+=bit[pos];
if(ans>=mod) ans-=mod;
pos-=(pos&(-pos));
}
return ans;
}
int n;
signed main()
{
ios_base::sync_with_stdio(false); cin.tie(NULL);
cin >> n;
for(int i=1;i<=n;i++)
{
cin >> a[i] >> b[i];
for(int j=a[i];j<=b[i];j++) v.push_back(j);
}
sort(v.begin(),v.end());
s.push_back(-1);
s.push_back(0);
for(int i=0;i<v.size();i++)
{
if(i==0||v[i]!=v[i-1]) s.push_back(v[i]);
}
swap(v,s);
sz=v.size()-1;
update(1,1);
for(int i=1;i<=n;i++)
{
int l=lower_bound(v.begin(),v.end(),a[i])-v.begin();
int r=lower_bound(v.begin(),v.end(),b[i])-v.begin();
for(int j=r;j>=l;j--)
{
update(j,get(j-1));
}
}
cout << (get(sz)-1+mod)%mod;
}
Compilation message (stderr)
boat.cpp: In function 'int main()':
boat.cpp:43:18: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
43 | for(int i=0;i<v.size();i++)
| ~^~~~~~~~~
# | 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... |