Submission #716721

# Submission time Handle Problem Language Result Execution time Memory
716721 2023-03-30T23:24:59 Z snpmrnhlol Boat (APIO16_boat) C++17
100 / 100
923 ms 4632 KB
#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
int segs[250001],dp[250001];
int length[1001];
int segl[1001];
int l[501],r[501];
int dp2[1001];
int inv[250001];
vector <int> v2[1001];
int p(int a,int b){
    int r = 1;
    while(b > 0){
        if(b%2 == 1)r = 1ll*r*a%mod;
        a = 1ll*a*a%mod;
        b/=2;
    }
    return r;
}
void precalc(){
    for(int i = 0;i <= 250000;i++){
        inv[i] = p(i,mod - 2);
    }
}
int main(){
    precalc();
    int n,i,cnt = 1,j,cnt2 = 0,ans = 0;
    cin>>n;
    for(i = 0;i < n;i++){
        cin>>l[i]>>r[i];
        segl[i*2] = l[i];
        segl[i*2+1] = r[i] + 1;
    }
    sort(segl,segl + 2*n);
    for(i = 1;i < 2*n;i++){
        if(segl[i] != segl[cnt - 1]){
            segl[cnt++] = segl[i];
        }
    }
    for(i = 0;i < n;i++){
        for(j = cnt - 1;j >= 0;j--){
            if(l[i] <= segl[j] && segl[j] <= r[i]){
                segs[cnt2++] = j;
                length[j] = segl[j + 1] - segl[j];
            }
        }
    }
    segs[cnt2++] = cnt;
    length[cnt] = 1;
    for(i = 0;i < cnt2;i++){
        dp[i] = 1;
        for(j = segs[i] - 1;j >= 0;j--){
            dp[i]+=dp2[j];
            dp[i]%=mod;
        }
        ///update dp2[segs[i]]
        dp2[segs[i]] = 0;
        v2[segs[i]].push_back(dp[i]);
        int prod = length[segs[i]];
        for(j = v2[segs[i]].size() - 1;j >= 0;j--){
            dp2[segs[i]] = (dp2[segs[i]] + 1ll*v2[segs[i]][j]*prod)%mod;
            prod = 1ll*prod*(length[segs[i]] + v2[segs[i]].size() - j)%mod;
            prod = 1ll*prod*inv[v2[segs[i]].size() - j + 1]%mod;
        }
    }
    ans = (dp[cnt2 - 1] + mod - 1)%mod;
    cout<<ans;
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 39 ms 1236 KB Output is correct
2 Correct 36 ms 1200 KB Output is correct
3 Correct 36 ms 1280 KB Output is correct
4 Correct 36 ms 1236 KB Output is correct
5 Correct 36 ms 1228 KB Output is correct
6 Correct 38 ms 1228 KB Output is correct
7 Correct 39 ms 1240 KB Output is correct
8 Correct 38 ms 1260 KB Output is correct
9 Correct 36 ms 1208 KB Output is correct
10 Correct 37 ms 1228 KB Output is correct
11 Correct 36 ms 1256 KB Output is correct
12 Correct 36 ms 1200 KB Output is correct
13 Correct 36 ms 1236 KB Output is correct
14 Correct 37 ms 1324 KB Output is correct
15 Correct 37 ms 1208 KB Output is correct
16 Correct 38 ms 1232 KB Output is correct
17 Correct 38 ms 1228 KB Output is correct
18 Correct 36 ms 1208 KB Output is correct
19 Correct 35 ms 1292 KB Output is correct
20 Correct 36 ms 1312 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 39 ms 1236 KB Output is correct
2 Correct 36 ms 1200 KB Output is correct
3 Correct 36 ms 1280 KB Output is correct
4 Correct 36 ms 1236 KB Output is correct
5 Correct 36 ms 1228 KB Output is correct
6 Correct 38 ms 1228 KB Output is correct
7 Correct 39 ms 1240 KB Output is correct
8 Correct 38 ms 1260 KB Output is correct
9 Correct 36 ms 1208 KB Output is correct
10 Correct 37 ms 1228 KB Output is correct
11 Correct 36 ms 1256 KB Output is correct
12 Correct 36 ms 1200 KB Output is correct
13 Correct 36 ms 1236 KB Output is correct
14 Correct 37 ms 1324 KB Output is correct
15 Correct 37 ms 1208 KB Output is correct
16 Correct 38 ms 1232 KB Output is correct
17 Correct 38 ms 1228 KB Output is correct
18 Correct 36 ms 1208 KB Output is correct
19 Correct 35 ms 1292 KB Output is correct
20 Correct 36 ms 1312 KB Output is correct
21 Correct 477 ms 3364 KB Output is correct
22 Correct 455 ms 3380 KB Output is correct
23 Correct 414 ms 3320 KB Output is correct
24 Correct 445 ms 3352 KB Output is correct
25 Correct 472 ms 3404 KB Output is correct
26 Correct 767 ms 4260 KB Output is correct
27 Correct 780 ms 4252 KB Output is correct
28 Correct 761 ms 4176 KB Output is correct
29 Correct 747 ms 4168 KB Output is correct
30 Correct 37 ms 1244 KB Output is correct
31 Correct 38 ms 1284 KB Output is correct
32 Correct 41 ms 1356 KB Output is correct
33 Correct 39 ms 1292 KB Output is correct
34 Correct 38 ms 1256 KB Output is correct
35 Correct 38 ms 1352 KB Output is correct
36 Correct 38 ms 1360 KB Output is correct
37 Correct 38 ms 1256 KB Output is correct
38 Correct 41 ms 1356 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 44 ms 1396 KB Output is correct
2 Correct 38 ms 1300 KB Output is correct
3 Correct 43 ms 1384 KB Output is correct
4 Correct 39 ms 1408 KB Output is correct
5 Correct 40 ms 1356 KB Output is correct
6 Correct 42 ms 1384 KB Output is correct
7 Correct 45 ms 1504 KB Output is correct
8 Correct 41 ms 1356 KB Output is correct
9 Correct 41 ms 1372 KB Output is correct
10 Correct 41 ms 1416 KB Output is correct
11 Correct 40 ms 1420 KB Output is correct
12 Correct 38 ms 1356 KB Output is correct
13 Correct 40 ms 1372 KB Output is correct
14 Correct 41 ms 1360 KB Output is correct
15 Correct 39 ms 1308 KB Output is correct
16 Correct 37 ms 1356 KB Output is correct
17 Correct 38 ms 1260 KB Output is correct
18 Correct 38 ms 1304 KB Output is correct
19 Correct 37 ms 1372 KB Output is correct
20 Correct 37 ms 1356 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 39 ms 1236 KB Output is correct
2 Correct 36 ms 1200 KB Output is correct
3 Correct 36 ms 1280 KB Output is correct
4 Correct 36 ms 1236 KB Output is correct
5 Correct 36 ms 1228 KB Output is correct
6 Correct 38 ms 1228 KB Output is correct
7 Correct 39 ms 1240 KB Output is correct
8 Correct 38 ms 1260 KB Output is correct
9 Correct 36 ms 1208 KB Output is correct
10 Correct 37 ms 1228 KB Output is correct
11 Correct 36 ms 1256 KB Output is correct
12 Correct 36 ms 1200 KB Output is correct
13 Correct 36 ms 1236 KB Output is correct
14 Correct 37 ms 1324 KB Output is correct
15 Correct 37 ms 1208 KB Output is correct
16 Correct 38 ms 1232 KB Output is correct
17 Correct 38 ms 1228 KB Output is correct
18 Correct 36 ms 1208 KB Output is correct
19 Correct 35 ms 1292 KB Output is correct
20 Correct 36 ms 1312 KB Output is correct
21 Correct 477 ms 3364 KB Output is correct
22 Correct 455 ms 3380 KB Output is correct
23 Correct 414 ms 3320 KB Output is correct
24 Correct 445 ms 3352 KB Output is correct
25 Correct 472 ms 3404 KB Output is correct
26 Correct 767 ms 4260 KB Output is correct
27 Correct 780 ms 4252 KB Output is correct
28 Correct 761 ms 4176 KB Output is correct
29 Correct 747 ms 4168 KB Output is correct
30 Correct 37 ms 1244 KB Output is correct
31 Correct 38 ms 1284 KB Output is correct
32 Correct 41 ms 1356 KB Output is correct
33 Correct 39 ms 1292 KB Output is correct
34 Correct 38 ms 1256 KB Output is correct
35 Correct 38 ms 1352 KB Output is correct
36 Correct 38 ms 1360 KB Output is correct
37 Correct 38 ms 1256 KB Output is correct
38 Correct 41 ms 1356 KB Output is correct
39 Correct 44 ms 1396 KB Output is correct
40 Correct 38 ms 1300 KB Output is correct
41 Correct 43 ms 1384 KB Output is correct
42 Correct 39 ms 1408 KB Output is correct
43 Correct 40 ms 1356 KB Output is correct
44 Correct 42 ms 1384 KB Output is correct
45 Correct 45 ms 1504 KB Output is correct
46 Correct 41 ms 1356 KB Output is correct
47 Correct 41 ms 1372 KB Output is correct
48 Correct 41 ms 1416 KB Output is correct
49 Correct 40 ms 1420 KB Output is correct
50 Correct 38 ms 1356 KB Output is correct
51 Correct 40 ms 1372 KB Output is correct
52 Correct 41 ms 1360 KB Output is correct
53 Correct 39 ms 1308 KB Output is correct
54 Correct 37 ms 1356 KB Output is correct
55 Correct 38 ms 1260 KB Output is correct
56 Correct 38 ms 1304 KB Output is correct
57 Correct 37 ms 1372 KB Output is correct
58 Correct 37 ms 1356 KB Output is correct
59 Correct 526 ms 3568 KB Output is correct
60 Correct 506 ms 3472 KB Output is correct
61 Correct 467 ms 3468 KB Output is correct
62 Correct 552 ms 3864 KB Output is correct
63 Correct 512 ms 3512 KB Output is correct
64 Correct 900 ms 4632 KB Output is correct
65 Correct 923 ms 4588 KB Output is correct
66 Correct 917 ms 4564 KB Output is correct
67 Correct 918 ms 4616 KB Output is correct
68 Correct 918 ms 4584 KB Output is correct
69 Correct 488 ms 3372 KB Output is correct
70 Correct 467 ms 3436 KB Output is correct
71 Correct 468 ms 3616 KB Output is correct
72 Correct 514 ms 3508 KB Output is correct
73 Correct 509 ms 3404 KB Output is correct
74 Correct 81 ms 1756 KB Output is correct
75 Correct 80 ms 1700 KB Output is correct
76 Correct 82 ms 1720 KB Output is correct
77 Correct 84 ms 1748 KB Output is correct
78 Correct 81 ms 1820 KB Output is correct