Submission #946356

# Submission time Handle Problem Language Result Execution time Memory
946356 2024-03-14T14:21:23 Z simona1230 Boat (APIO16_boat) C++17
0 / 100
5 ms 8916 KB
#include <bits/stdc++.h>

using namespace std;
long long n;
struct school
{
    int first,second,i;
    school(){}
    school(int _l,int _r,int _i)
    {
        first=_l;
        second=_r;
        i=_i;
    }
};
school p[200001];
pair<long long,long long> a[200001];
bool cmp(school s1,school s2)
{
    return s1.first<=s2.first;
}

void read()
{
    cin>>n;
    for(long long i=1;i<=n;i++)
    {
        int x,y;
        cin>>x>>y;
        p[i]={x,y,i};
    }
    sort(p+1,p+n+1,cmp);

    long long last=0;
    p[0]={0,0,0};
    a[0]={0,0};
    for(long long i=1;i<=n;i++)
    {
        int idx=p[i].i;
        long long len=p[i].second-p[i].first;

        a[idx].first=last+1;

        if(p[i-1].second>=p[i].first)
        {
            long long same=p[i-1].second-p[i].first;
            a[idx].first=last-same;
        }

        a[idx].second=a[idx].first+len;
        last=a[idx].second;
        //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:30:19: warning: narrowing conversion of 'i' from 'long long int' to 'int' [-Wnarrowing]
   30 |         p[i]={x,y,i};
      |                   ^
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 4440 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 4440 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 5 ms 8916 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 4440 KB Output isn't correct
2 Halted 0 ms 0 KB -