답안 #946374

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
946374 2024-03-14T14:52:15 Z simona1230 Boat (APIO16_boat) C++17
9 / 100
177 ms 4700 KB
#include <bits/stdc++.h>

using namespace std;
long long n;
struct school
{
    long long first,second,i;
    school(){}
    school(long long _l,long long _r,long long _i)
    {
        first=_l;
        second=_r;
        i=_i;
    }
};
school p[512];
school a[512];
bool cmp(school s1,school s2)
{
    return s1.first<=s2.first;
}
bool cmp2(school s1,school s2)
{
    return s1.i<s2.i;
}
long long lim;
void read()
{
    cin>>n;
    for(long long i=1;i<=n;i++)
    {
        long long x,y;
        cin>>x>>y;
        p[i]={x,y,i};
    }
    sort(p+1,p+n+1,cmp);

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

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

        a[i].second=a[i].first+len;
        lim=max(lim,a[i].second);
        if(lim==a[i].second)oglast=p[i].second;
        //cout<<a[i].first<<" "<<a[i].second<<endl;
    }
    sort(a+1,a+n+1,cmp2);
}

const long long mod=1e9+7;
long long t[5000001];

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,lim,0,1);

    for(long long i=1;i<=n;i++)
    {
        //cout<<a[i].first<<" "<<a[i].second<<endl;
        for(long long j=a[i].second;j>=a[i].first;j--)
        {
            long long help=query(1,0,lim,0,j-1);
            //cout<<i<<" "<<j<<" "<<help<<endl;
            update(1,0,lim,j,help);
        }
    }
    long long fin=query(1,0,lim,1,lim);
    cout<<fin<<endl;
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	read();
	solve();
	return 0;
}
/*
3
4 10
7 15
1 4

4
10 15
12 20
12 17
30 40
*/

Compilation message

boat.cpp: In function 'void read()':
boat.cpp:38:15: warning: unused variable 'last' [-Wunused-variable]
   38 |     long long last=0,oglast=0;
      |               ^~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 2392 KB Output is correct
4 Correct 1 ms 2392 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 2 ms 2396 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 1 ms 2396 KB Output is correct
11 Correct 2 ms 2396 KB Output is correct
12 Correct 1 ms 2396 KB Output is correct
13 Correct 1 ms 2396 KB Output is correct
14 Correct 1 ms 2396 KB Output is correct
15 Correct 1 ms 2396 KB Output is correct
16 Correct 2 ms 2396 KB Output is correct
17 Correct 1 ms 2396 KB Output is correct
18 Correct 1 ms 2396 KB Output is correct
19 Correct 1 ms 2392 KB Output is correct
20 Correct 1 ms 2396 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 2392 KB Output is correct
4 Correct 1 ms 2392 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 2 ms 2396 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 1 ms 2396 KB Output is correct
11 Correct 2 ms 2396 KB Output is correct
12 Correct 1 ms 2396 KB Output is correct
13 Correct 1 ms 2396 KB Output is correct
14 Correct 1 ms 2396 KB Output is correct
15 Correct 1 ms 2396 KB Output is correct
16 Correct 2 ms 2396 KB Output is correct
17 Correct 1 ms 2396 KB Output is correct
18 Correct 1 ms 2396 KB Output is correct
19 Correct 1 ms 2392 KB Output is correct
20 Correct 1 ms 2396 KB Output is correct
21 Incorrect 177 ms 2620 KB Output isn't correct
22 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 3 ms 4700 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 2392 KB Output is correct
4 Correct 1 ms 2392 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 2 ms 2396 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 1 ms 2396 KB Output is correct
11 Correct 2 ms 2396 KB Output is correct
12 Correct 1 ms 2396 KB Output is correct
13 Correct 1 ms 2396 KB Output is correct
14 Correct 1 ms 2396 KB Output is correct
15 Correct 1 ms 2396 KB Output is correct
16 Correct 2 ms 2396 KB Output is correct
17 Correct 1 ms 2396 KB Output is correct
18 Correct 1 ms 2396 KB Output is correct
19 Correct 1 ms 2392 KB Output is correct
20 Correct 1 ms 2396 KB Output is correct
21 Incorrect 177 ms 2620 KB Output isn't correct
22 Halted 0 ms 0 KB -