답안 #730851

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
730851 2023-04-26T14:24:56 Z bgnbvnbv Boat (APIO16_boat) C++14
100 / 100
460 ms 6356 KB
#include<bits/stdc++.h>

using namespace std;
#define int long long
#define pll pair<int,int>
#define fi first
#define se second
const int mod=(int)1e9+7;
const int maxn=2*505;
int sz,a[maxn],b[maxn];
vector<int>v,s;
int n;
vector<pll>block;
int val[maxn][maxn];
int cnt[maxn];
int add[maxn];
int chia[maxn];
int pw(int x,int y)
{
    if(y==0) return 1;
    int x1=pw(x,y/2);
    x1=x1*x1%mod;
    if(y&1) x1=x1*x%mod;
    return x1;
}
int pre[maxn];
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];
        v.push_back(a[i]-1);
        v.push_back(b[i]);
    }
    for(int i=1;i<=n;i++) chia[i]=pw(i,mod-2);
    sort(v.begin(),v.end());
    for(int i=0;i<v.size();i++)
    {
        if(i==0||v[i]!=v[i-1]) s.push_back(v[i]);
    }
    swap(v,s);
    for(int i=0;i<v.size();i++)
    {
        if(i==0) block.push_back({0,v[i]});
        else block.push_back({v[i-1]+1,v[i]});
    }
    for(int i=0;i<block.size();i++) pre[i]=1;
    int tt=0,valcu;
    for(int i=1;i<=n;i++)
    {
        a[i]=lower_bound(block.begin(),block.end(),(pll){a[i]+1,0ll})-block.begin()-1;
        b[i]=lower_bound(block.begin(),block.end(),(pll){b[i]+1,0ll})-block.begin()-1;
        for(int j=a[i];j<=b[i];j++)
        {
            cnt[j]++;
            val[j][cnt[j]]=pre[j-1];
            for(int k=1;k<=cnt[j];k++)
            {
                tt=cnt[j]-k+1;
                valcu=val[j][k]*(block[j].se-block[j].fi)%mod*chia[tt]%mod;
                val[j][k]+=valcu;
                if(k==cnt[j]) valcu=0;
                if(val[j][k]>=mod) val[j][k]-=mod;
                add[j]+=valcu;
                if(add[j]>=mod) add[j]-=mod;
            }
            add[j]+=val[j][cnt[j]];
            if(add[j]>=mod) add[j]-=mod;
        }
        for(int j=1;j<block.size();j++)
        {
            add[j]+=add[j-1];
            if(add[j]>=mod) add[j]-=mod;
            pre[j]+=add[j];
            if(pre[j]>=mod) pre[j]-=mod;
        }
        for(int j=1;j<block.size();j++) add[j]=0;
    }
    cout << (pre[block.size()-1]-1+mod)%mod;
}

Compilation message

boat.cpp: In function 'int main()':
boat.cpp:40: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]
   40 |     for(int i=0;i<v.size();i++)
      |                 ~^~~~~~~~~
boat.cpp:45: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]
   45 |     for(int i=0;i<v.size();i++)
      |                 ~^~~~~~~~~
boat.cpp:50:18: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   50 |     for(int i=0;i<block.size();i++) pre[i]=1;
      |                 ~^~~~~~~~~~~~~
boat.cpp:73:22: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   73 |         for(int j=1;j<block.size();j++)
      |                     ~^~~~~~~~~~~~~
boat.cpp:80:22: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   80 |         for(int j=1;j<block.size();j++) add[j]=0;
      |                     ~^~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 2388 KB Output is correct
2 Correct 3 ms 2388 KB Output is correct
3 Correct 4 ms 2388 KB Output is correct
4 Correct 3 ms 2388 KB Output is correct
5 Correct 3 ms 2388 KB Output is correct
6 Correct 3 ms 2388 KB Output is correct
7 Correct 4 ms 2388 KB Output is correct
8 Correct 3 ms 2388 KB Output is correct
9 Correct 3 ms 2388 KB Output is correct
10 Correct 3 ms 2388 KB Output is correct
11 Correct 3 ms 2388 KB Output is correct
12 Correct 3 ms 2388 KB Output is correct
13 Correct 3 ms 2388 KB Output is correct
14 Correct 3 ms 2388 KB Output is correct
15 Correct 3 ms 2388 KB Output is correct
16 Correct 1 ms 724 KB Output is correct
17 Correct 1 ms 724 KB Output is correct
18 Correct 1 ms 724 KB Output is correct
19 Correct 1 ms 724 KB Output is correct
20 Correct 1 ms 724 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 2388 KB Output is correct
2 Correct 3 ms 2388 KB Output is correct
3 Correct 4 ms 2388 KB Output is correct
4 Correct 3 ms 2388 KB Output is correct
5 Correct 3 ms 2388 KB Output is correct
6 Correct 3 ms 2388 KB Output is correct
7 Correct 4 ms 2388 KB Output is correct
8 Correct 3 ms 2388 KB Output is correct
9 Correct 3 ms 2388 KB Output is correct
10 Correct 3 ms 2388 KB Output is correct
11 Correct 3 ms 2388 KB Output is correct
12 Correct 3 ms 2388 KB Output is correct
13 Correct 3 ms 2388 KB Output is correct
14 Correct 3 ms 2388 KB Output is correct
15 Correct 3 ms 2388 KB Output is correct
16 Correct 1 ms 724 KB Output is correct
17 Correct 1 ms 724 KB Output is correct
18 Correct 1 ms 724 KB Output is correct
19 Correct 1 ms 724 KB Output is correct
20 Correct 1 ms 724 KB Output is correct
21 Correct 170 ms 5304 KB Output is correct
22 Correct 151 ms 5200 KB Output is correct
23 Correct 138 ms 5052 KB Output is correct
24 Correct 148 ms 5184 KB Output is correct
25 Correct 172 ms 5144 KB Output is correct
26 Correct 333 ms 5720 KB Output is correct
27 Correct 344 ms 5784 KB Output is correct
28 Correct 362 ms 5592 KB Output is correct
29 Correct 359 ms 5620 KB Output is correct
30 Correct 4 ms 4308 KB Output is correct
31 Correct 5 ms 4380 KB Output is correct
32 Correct 5 ms 4308 KB Output is correct
33 Correct 5 ms 4436 KB Output is correct
34 Correct 3 ms 4308 KB Output is correct
35 Correct 3 ms 4436 KB Output is correct
36 Correct 4 ms 4436 KB Output is correct
37 Correct 4 ms 4376 KB Output is correct
38 Correct 4 ms 4436 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 1108 KB Output is correct
2 Correct 2 ms 1108 KB Output is correct
3 Correct 3 ms 1108 KB Output is correct
4 Correct 4 ms 1108 KB Output is correct
5 Correct 3 ms 1108 KB Output is correct
6 Correct 7 ms 1132 KB Output is correct
7 Correct 5 ms 1236 KB Output is correct
8 Correct 5 ms 1236 KB Output is correct
9 Correct 5 ms 1224 KB Output is correct
10 Correct 5 ms 1108 KB Output is correct
11 Correct 3 ms 1108 KB Output is correct
12 Correct 2 ms 1108 KB Output is correct
13 Correct 3 ms 1108 KB Output is correct
14 Correct 3 ms 1108 KB Output is correct
15 Correct 3 ms 1108 KB Output is correct
16 Correct 2 ms 844 KB Output is correct
17 Correct 2 ms 724 KB Output is correct
18 Correct 2 ms 864 KB Output is correct
19 Correct 3 ms 852 KB Output is correct
20 Correct 2 ms 712 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 2388 KB Output is correct
2 Correct 3 ms 2388 KB Output is correct
3 Correct 4 ms 2388 KB Output is correct
4 Correct 3 ms 2388 KB Output is correct
5 Correct 3 ms 2388 KB Output is correct
6 Correct 3 ms 2388 KB Output is correct
7 Correct 4 ms 2388 KB Output is correct
8 Correct 3 ms 2388 KB Output is correct
9 Correct 3 ms 2388 KB Output is correct
10 Correct 3 ms 2388 KB Output is correct
11 Correct 3 ms 2388 KB Output is correct
12 Correct 3 ms 2388 KB Output is correct
13 Correct 3 ms 2388 KB Output is correct
14 Correct 3 ms 2388 KB Output is correct
15 Correct 3 ms 2388 KB Output is correct
16 Correct 1 ms 724 KB Output is correct
17 Correct 1 ms 724 KB Output is correct
18 Correct 1 ms 724 KB Output is correct
19 Correct 1 ms 724 KB Output is correct
20 Correct 1 ms 724 KB Output is correct
21 Correct 170 ms 5304 KB Output is correct
22 Correct 151 ms 5200 KB Output is correct
23 Correct 138 ms 5052 KB Output is correct
24 Correct 148 ms 5184 KB Output is correct
25 Correct 172 ms 5144 KB Output is correct
26 Correct 333 ms 5720 KB Output is correct
27 Correct 344 ms 5784 KB Output is correct
28 Correct 362 ms 5592 KB Output is correct
29 Correct 359 ms 5620 KB Output is correct
30 Correct 4 ms 4308 KB Output is correct
31 Correct 5 ms 4380 KB Output is correct
32 Correct 5 ms 4308 KB Output is correct
33 Correct 5 ms 4436 KB Output is correct
34 Correct 3 ms 4308 KB Output is correct
35 Correct 3 ms 4436 KB Output is correct
36 Correct 4 ms 4436 KB Output is correct
37 Correct 4 ms 4376 KB Output is correct
38 Correct 4 ms 4436 KB Output is correct
39 Correct 2 ms 1108 KB Output is correct
40 Correct 2 ms 1108 KB Output is correct
41 Correct 3 ms 1108 KB Output is correct
42 Correct 4 ms 1108 KB Output is correct
43 Correct 3 ms 1108 KB Output is correct
44 Correct 7 ms 1132 KB Output is correct
45 Correct 5 ms 1236 KB Output is correct
46 Correct 5 ms 1236 KB Output is correct
47 Correct 5 ms 1224 KB Output is correct
48 Correct 5 ms 1108 KB Output is correct
49 Correct 3 ms 1108 KB Output is correct
50 Correct 2 ms 1108 KB Output is correct
51 Correct 3 ms 1108 KB Output is correct
52 Correct 3 ms 1108 KB Output is correct
53 Correct 3 ms 1108 KB Output is correct
54 Correct 2 ms 844 KB Output is correct
55 Correct 2 ms 724 KB Output is correct
56 Correct 2 ms 864 KB Output is correct
57 Correct 3 ms 852 KB Output is correct
58 Correct 2 ms 712 KB Output is correct
59 Correct 199 ms 5672 KB Output is correct
60 Correct 173 ms 5584 KB Output is correct
61 Correct 174 ms 5692 KB Output is correct
62 Correct 203 ms 5680 KB Output is correct
63 Correct 179 ms 5708 KB Output is correct
64 Correct 448 ms 6352 KB Output is correct
65 Correct 445 ms 6332 KB Output is correct
66 Correct 446 ms 6276 KB Output is correct
67 Correct 458 ms 6356 KB Output is correct
68 Correct 460 ms 6300 KB Output is correct
69 Correct 157 ms 5708 KB Output is correct
70 Correct 162 ms 5556 KB Output is correct
71 Correct 167 ms 5576 KB Output is correct
72 Correct 171 ms 5572 KB Output is correct
73 Correct 172 ms 5708 KB Output is correct
74 Correct 30 ms 1336 KB Output is correct
75 Correct 29 ms 1256 KB Output is correct
76 Correct 29 ms 1276 KB Output is correct
77 Correct 31 ms 1280 KB Output is correct
78 Correct 34 ms 1344 KB Output is correct