# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
947832 |
2024-03-17T05:40:16 Z |
RGBB |
Boat (APIO16_boat) |
C++14 |
|
1421 ms |
6168 KB |
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <cstdint>
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pi;
typedef pair<ll, ll> pll;
typedef pair<double, double> pd;
typedef pair<ld, ld> pld;
typedef tuple<int, int, int> ti;
typedef tuple<ll, ll, ll> tll;
typedef tuple<double, double, double> td;
typedef complex<double> cd;
typedef tree<pair<int, int>, null_type, less<pair<int, int>>, rb_tree_tag, tree_order_statistics_node_update> bbst;
mt19937 g1;
int get_random_int(int a, int b) {
return uniform_int_distribution<int>(a, b)(g1);
}
//const ll MOD = 100000000105583;
int MOD = 1e9 + 7;
//int MOD = 998244353;
struct Mint {
int v;
Mint() {v = 0;}
Mint(int nv) {v = nv;}
Mint(const Mint &a) {v = a.v;}
Mint pow(int a) {
long long ret = 1;
long long base = v;
if(a < 0) {
a = -a;
base = Mint(v).inv().v;
}
while(a > 0) {
if(a & 1) ret = (ret * base) % MOD;
base = (base * base) % MOD;
a >>= 1;
}
return Mint((int)ret);
}
Mint inv() {return this->pow(MOD - 2);}
Mint operator + (int a) const {return Mint((v + a) % MOD);}
Mint operator + (const Mint &a) const {return Mint((v + a.v) % MOD);}
Mint& operator += (int a) {
v = (v + a) % MOD;
return *this;
}
Mint& operator += (const Mint &a) {
v = (v + a.v) % MOD;
return *this;
}
Mint operator - (int a) const {return Mint((v - a + MOD) % MOD);}
Mint operator - (const Mint &a) const {return Mint((v - a.v + MOD) % MOD);}
Mint& operator -= (int a) {
v = (v - a + MOD) % MOD;
return *this;
}
Mint& operator -= (const Mint &a) {
v = (v - a.v + MOD) % MOD;
return *this;
}
Mint operator * (int a) const {return Mint(((long long)v * a) % MOD);}
Mint operator * (const Mint &a) const {return Mint(((long long)v * a.v) % MOD);}
Mint& operator *= (int a) {
v = ((long long)v * a) % MOD;
return *this;
}
Mint& operator *= (const Mint &a) {
v = ((long long)v * a.v) % MOD;
return *this;
}
Mint operator / (int a) const {return Mint(v) * Mint(a).inv();}
Mint operator / (const Mint a) const {return Mint(v) * Mint(a).inv();}
Mint& operator /= (int a) {
v = ((long long)v * Mint(a).inv().v) % MOD;
return *this;
}
Mint& operator /= (const Mint &a) {
v = ((long long)v * Mint(a).inv().v) % MOD;
return *this;
}
Mint& operator = (int a) {
v = a;
v %= MOD;
if(v < 0) v += MOD;
return *this;
}
bool operator == (int a) const {return v == a;}
bool operator == (const Mint &a) const {return v == a.v;}
bool operator != (int a) const {return v != a;}
bool operator != (const Mint &a) const {return v != a.v;}
friend ostream& operator << (ostream &os, const Mint &a) {
os << a.v;
return os;
}
};
const int MAX = 500;
Mint qinv[2 * MAX];
void calcQinv() {
for(int i = 1; i < 2 * MAX; i++) qinv[i] = Mint(i).inv();
}
struct prefixBinom {
int degree, size;
Mint coeff, sum; // Note that sum is without coeff
/*
Degree 0 implies only coeff throughout
*/
prefixBinom(): degree{0}, size{0}, coeff{Mint(0)}, sum{Mint(0)} {}
prefixBinom(int s, Mint c): degree{0}, size{s}, coeff{c}, sum{Mint(s)} {}
void incDegree() {
sum *= (degree + size + 1);
sum *= qinv[degree + 2];
degree++;
}
Mint calcVal() {
return coeff * sum;
}
};
int n;
int ran[MAX][2];
int si;
map<int, int> cmp;
int invc[2 * MAX + 1];
vector<prefixBinom> dp[2 * MAX + 1];
Mint psa[2 * MAX + 1];
void calcDP(int p) {
for(int i = 0; i < si; i++) psa[i] = 0;
int lb = cmp[ran[p][0]];
int rb = cmp[ran[p][1] + 1];
for(int i = 0; i < si; i++) {
if(invc[i] == -1 || invc[i + 1] == -1) break;
if(i != 0) psa[i] = psa[i - 1];
if(i < rb) for(auto& j: dp[i]) psa[i] += j.calcVal();
int cs = invc[i + 1] - invc[i];
if(lb <= i && i < rb) {
for(auto& j: dp[i]) j.incDegree();
dp[i].push_back(prefixBinom(cs, psa[i - 1]));
}
}
}
void solve() {
calcQinv();
cin >> n;
cmp[0];
for(int i = 0; i < n; i++) {
cin >> ran[i][0] >> ran[i][1];
cmp[ran[i][0]];
cmp[ran[i][1] + 1];
}
memset(invc, -1, sizeof(invc));
for(auto& [i, j]: cmp) {
invc[si] = i;
j = si++;
}
int lb = cmp[ran[0][0]];
int rb = cmp[ran[0][1] + 1];
dp[0].push_back(prefixBinom(1, Mint(1)));
for(int i = lb; i < rb; i++) {
int ranl = invc[i];
int ranr = invc[i + 1];
dp[i].push_back(prefixBinom(ranr - ranl, Mint(1)));
}
for(int i = 1; i < n; i++) calcDP(i);
Mint ans = 0;
for(int i = 0; i < si; i++) {
for(auto& j: dp[i]) ans += j.calcVal();
}
cout << ans - 1 << "\n";
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int t;
//cin >> t;
t = 1;
while(t--) solve();
}
Compilation message
boat.cpp: In function 'void solve()':
boat.cpp:165:15: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
165 | for(auto& [i, j]: cmp) {
| ^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
344 KB |
Output is correct |
2 |
Correct |
3 ms |
348 KB |
Output is correct |
3 |
Correct |
2 ms |
348 KB |
Output is correct |
4 |
Correct |
3 ms |
348 KB |
Output is correct |
5 |
Correct |
3 ms |
508 KB |
Output is correct |
6 |
Correct |
3 ms |
348 KB |
Output is correct |
7 |
Correct |
3 ms |
348 KB |
Output is correct |
8 |
Correct |
3 ms |
344 KB |
Output is correct |
9 |
Correct |
3 ms |
344 KB |
Output is correct |
10 |
Correct |
3 ms |
504 KB |
Output is correct |
11 |
Correct |
3 ms |
344 KB |
Output is correct |
12 |
Correct |
3 ms |
348 KB |
Output is correct |
13 |
Correct |
3 ms |
572 KB |
Output is correct |
14 |
Correct |
3 ms |
348 KB |
Output is correct |
15 |
Correct |
3 ms |
348 KB |
Output is correct |
16 |
Correct |
2 ms |
348 KB |
Output is correct |
17 |
Correct |
2 ms |
348 KB |
Output is correct |
18 |
Correct |
2 ms |
348 KB |
Output is correct |
19 |
Correct |
2 ms |
348 KB |
Output is correct |
20 |
Correct |
2 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
344 KB |
Output is correct |
2 |
Correct |
3 ms |
348 KB |
Output is correct |
3 |
Correct |
2 ms |
348 KB |
Output is correct |
4 |
Correct |
3 ms |
348 KB |
Output is correct |
5 |
Correct |
3 ms |
508 KB |
Output is correct |
6 |
Correct |
3 ms |
348 KB |
Output is correct |
7 |
Correct |
3 ms |
348 KB |
Output is correct |
8 |
Correct |
3 ms |
344 KB |
Output is correct |
9 |
Correct |
3 ms |
344 KB |
Output is correct |
10 |
Correct |
3 ms |
504 KB |
Output is correct |
11 |
Correct |
3 ms |
344 KB |
Output is correct |
12 |
Correct |
3 ms |
348 KB |
Output is correct |
13 |
Correct |
3 ms |
572 KB |
Output is correct |
14 |
Correct |
3 ms |
348 KB |
Output is correct |
15 |
Correct |
3 ms |
348 KB |
Output is correct |
16 |
Correct |
2 ms |
348 KB |
Output is correct |
17 |
Correct |
2 ms |
348 KB |
Output is correct |
18 |
Correct |
2 ms |
348 KB |
Output is correct |
19 |
Correct |
2 ms |
348 KB |
Output is correct |
20 |
Correct |
2 ms |
348 KB |
Output is correct |
21 |
Correct |
477 ms |
3884 KB |
Output is correct |
22 |
Correct |
457 ms |
4280 KB |
Output is correct |
23 |
Correct |
414 ms |
3548 KB |
Output is correct |
24 |
Correct |
453 ms |
4284 KB |
Output is correct |
25 |
Correct |
479 ms |
3664 KB |
Output is correct |
26 |
Correct |
978 ms |
5400 KB |
Output is correct |
27 |
Correct |
994 ms |
5156 KB |
Output is correct |
28 |
Correct |
982 ms |
5008 KB |
Output is correct |
29 |
Correct |
971 ms |
4968 KB |
Output is correct |
30 |
Correct |
5 ms |
348 KB |
Output is correct |
31 |
Correct |
5 ms |
348 KB |
Output is correct |
32 |
Correct |
5 ms |
344 KB |
Output is correct |
33 |
Correct |
5 ms |
344 KB |
Output is correct |
34 |
Correct |
5 ms |
348 KB |
Output is correct |
35 |
Correct |
3 ms |
600 KB |
Output is correct |
36 |
Correct |
3 ms |
348 KB |
Output is correct |
37 |
Correct |
3 ms |
348 KB |
Output is correct |
38 |
Correct |
4 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
600 KB |
Output is correct |
2 |
Correct |
4 ms |
612 KB |
Output is correct |
3 |
Correct |
5 ms |
600 KB |
Output is correct |
4 |
Correct |
6 ms |
604 KB |
Output is correct |
5 |
Correct |
6 ms |
680 KB |
Output is correct |
6 |
Correct |
12 ms |
604 KB |
Output is correct |
7 |
Correct |
12 ms |
604 KB |
Output is correct |
8 |
Correct |
12 ms |
648 KB |
Output is correct |
9 |
Correct |
12 ms |
600 KB |
Output is correct |
10 |
Correct |
12 ms |
768 KB |
Output is correct |
11 |
Correct |
7 ms |
676 KB |
Output is correct |
12 |
Correct |
6 ms |
604 KB |
Output is correct |
13 |
Correct |
7 ms |
604 KB |
Output is correct |
14 |
Correct |
7 ms |
600 KB |
Output is correct |
15 |
Correct |
7 ms |
600 KB |
Output is correct |
16 |
Correct |
4 ms |
604 KB |
Output is correct |
17 |
Correct |
4 ms |
492 KB |
Output is correct |
18 |
Correct |
4 ms |
860 KB |
Output is correct |
19 |
Correct |
4 ms |
604 KB |
Output is correct |
20 |
Correct |
4 ms |
604 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
344 KB |
Output is correct |
2 |
Correct |
3 ms |
348 KB |
Output is correct |
3 |
Correct |
2 ms |
348 KB |
Output is correct |
4 |
Correct |
3 ms |
348 KB |
Output is correct |
5 |
Correct |
3 ms |
508 KB |
Output is correct |
6 |
Correct |
3 ms |
348 KB |
Output is correct |
7 |
Correct |
3 ms |
348 KB |
Output is correct |
8 |
Correct |
3 ms |
344 KB |
Output is correct |
9 |
Correct |
3 ms |
344 KB |
Output is correct |
10 |
Correct |
3 ms |
504 KB |
Output is correct |
11 |
Correct |
3 ms |
344 KB |
Output is correct |
12 |
Correct |
3 ms |
348 KB |
Output is correct |
13 |
Correct |
3 ms |
572 KB |
Output is correct |
14 |
Correct |
3 ms |
348 KB |
Output is correct |
15 |
Correct |
3 ms |
348 KB |
Output is correct |
16 |
Correct |
2 ms |
348 KB |
Output is correct |
17 |
Correct |
2 ms |
348 KB |
Output is correct |
18 |
Correct |
2 ms |
348 KB |
Output is correct |
19 |
Correct |
2 ms |
348 KB |
Output is correct |
20 |
Correct |
2 ms |
348 KB |
Output is correct |
21 |
Correct |
477 ms |
3884 KB |
Output is correct |
22 |
Correct |
457 ms |
4280 KB |
Output is correct |
23 |
Correct |
414 ms |
3548 KB |
Output is correct |
24 |
Correct |
453 ms |
4284 KB |
Output is correct |
25 |
Correct |
479 ms |
3664 KB |
Output is correct |
26 |
Correct |
978 ms |
5400 KB |
Output is correct |
27 |
Correct |
994 ms |
5156 KB |
Output is correct |
28 |
Correct |
982 ms |
5008 KB |
Output is correct |
29 |
Correct |
971 ms |
4968 KB |
Output is correct |
30 |
Correct |
5 ms |
348 KB |
Output is correct |
31 |
Correct |
5 ms |
348 KB |
Output is correct |
32 |
Correct |
5 ms |
344 KB |
Output is correct |
33 |
Correct |
5 ms |
344 KB |
Output is correct |
34 |
Correct |
5 ms |
348 KB |
Output is correct |
35 |
Correct |
3 ms |
600 KB |
Output is correct |
36 |
Correct |
3 ms |
348 KB |
Output is correct |
37 |
Correct |
3 ms |
348 KB |
Output is correct |
38 |
Correct |
4 ms |
348 KB |
Output is correct |
39 |
Correct |
6 ms |
600 KB |
Output is correct |
40 |
Correct |
4 ms |
612 KB |
Output is correct |
41 |
Correct |
5 ms |
600 KB |
Output is correct |
42 |
Correct |
6 ms |
604 KB |
Output is correct |
43 |
Correct |
6 ms |
680 KB |
Output is correct |
44 |
Correct |
12 ms |
604 KB |
Output is correct |
45 |
Correct |
12 ms |
604 KB |
Output is correct |
46 |
Correct |
12 ms |
648 KB |
Output is correct |
47 |
Correct |
12 ms |
600 KB |
Output is correct |
48 |
Correct |
12 ms |
768 KB |
Output is correct |
49 |
Correct |
7 ms |
676 KB |
Output is correct |
50 |
Correct |
6 ms |
604 KB |
Output is correct |
51 |
Correct |
7 ms |
604 KB |
Output is correct |
52 |
Correct |
7 ms |
600 KB |
Output is correct |
53 |
Correct |
7 ms |
600 KB |
Output is correct |
54 |
Correct |
4 ms |
604 KB |
Output is correct |
55 |
Correct |
4 ms |
492 KB |
Output is correct |
56 |
Correct |
4 ms |
860 KB |
Output is correct |
57 |
Correct |
4 ms |
604 KB |
Output is correct |
58 |
Correct |
4 ms |
604 KB |
Output is correct |
59 |
Correct |
646 ms |
4184 KB |
Output is correct |
60 |
Correct |
593 ms |
4040 KB |
Output is correct |
61 |
Correct |
580 ms |
3964 KB |
Output is correct |
62 |
Correct |
665 ms |
4660 KB |
Output is correct |
63 |
Correct |
626 ms |
3924 KB |
Output is correct |
64 |
Correct |
1417 ms |
5728 KB |
Output is correct |
65 |
Correct |
1421 ms |
5896 KB |
Output is correct |
66 |
Correct |
1414 ms |
5776 KB |
Output is correct |
67 |
Correct |
1420 ms |
6168 KB |
Output is correct |
68 |
Correct |
1415 ms |
5636 KB |
Output is correct |
69 |
Correct |
716 ms |
3664 KB |
Output is correct |
70 |
Correct |
743 ms |
3856 KB |
Output is correct |
71 |
Correct |
740 ms |
4244 KB |
Output is correct |
72 |
Correct |
751 ms |
4076 KB |
Output is correct |
73 |
Correct |
763 ms |
4032 KB |
Output is correct |
74 |
Correct |
104 ms |
1104 KB |
Output is correct |
75 |
Correct |
103 ms |
1080 KB |
Output is correct |
76 |
Correct |
108 ms |
1532 KB |
Output is correct |
77 |
Correct |
106 ms |
1188 KB |
Output is correct |
78 |
Correct |
108 ms |
1304 KB |
Output is correct |