# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
946349 |
2024-03-14T14:13:36 Z |
simona1230 |
Boat (APIO16_boat) |
C++17 |
|
5 ms |
8796 KB |
#include <bits/stdc++.h>
using namespace std;
long long n;
pair<long long,long long> p[200001],a[200001];
void read()
{
cin>>n;
for(long long i=1;i<=n;i++)
{
cin>>p[i].first>>p[i].second;
}
sort(p+1,p+n+1);
long long last=0;
p[0]={0,0};
a[0]={0,0};
for(long long i=1;i<=n;i++)
{
long long len=p[i].second-p[i].first;
a[i].first=a[i-1].second+1;
if(p[i-1].second>=p[i].first)
{
long long same=p[i-1].second-p[i].first;
a[i].first=a[i-1].second-same;
}
a[i].second=a[i].first+len;
//cout<<a[i].first<<" "<<a[i].second<<endl;
}
}
const long long mod=1e9+7;
long long t[4000001];
long long query(long long i,long long l,long long r,long long ql,long long qr)
{
if(ql>qr)return 0;
if(l>=ql&&r<=qr)
{
//cout<<i<<" "<<l<<" "<<r<<" "<<t[i]<<" query"<<endl;
return t[i];
}
long long m=(l+r)/2;
return (query(i*2,l,m,ql,min(qr,m))+query(i*2+1,m+1,r,max(ql,m+1),qr))%mod;
}
void update(long long i,long long l,long long r,long long idx,long long val)
{
if(l==r)
{
t[i]+=val;
t[i]%=mod;
return;
}
long long m=(l+r)/2;
if(m>=idx)update(i*2,l,m,idx,val);
else update(i*2+1,m+1,r,idx,val);
t[i]=t[i*2]+t[i*2+1];
t[i]%=mod;
//cout<<i<<" "<<l<<" "<<r<<" "<<t[i]<<endl;
}
void solve()
{
update(1,0,a[n].second,0,1);
for(long long i=1;i<=n;i++)
{
for(long long j=a[i].second;j>=a[i].first;j--)
{
long long help=query(1,0,a[n].second,0,j-1);
//cout<<i<<" "<<j<<" "<<dp[i][j]<<endl;
update(1,0,a[n].second,j,help);
}
}
int fin=query(1,0,a[n].second,1,a[n].second);
cout<<fin<<endl;
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
read();
solve();
return 0;
}
// 1000000000 1000000000
Compilation message
boat.cpp: In function 'void read()':
boat.cpp:16:15: warning: unused variable 'last' [-Wunused-variable]
16 | long long last=0;
| ^~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
4444 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
4444 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
5 ms |
8796 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
4444 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |