# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
260922 |
2020-08-11T08:04:36 Z |
srvlt |
Boat (APIO16_boat) |
C++14 |
|
183 ms |
16256 KB |
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define pb push_back
#define all(x) begin(x), end(x)
#define SZ(x) (int)(x).size()
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const int n0 = 1003, mod = 1e9 + 7;
int n, l[n0], r[n0], k;
void add(int & x, int y) {
x += y;
if (x >= mod) x -= mod;
}
int bp(int x, int y) {
int res = 1;
while (y) {
if (y & 1)
res = (ll)res * x % mod;
x = (ll)x * x % mod;
y /= 2;
}
return res;
}
struct Mint {
int a = 0, b = 0;
Mint(int x = 0) {
a = 0, b = x;
if (b >= mod) {
b -= mod;
if (b == 0)
a = 1;
}
}
void operator += (const Mint & x) {
if (a == x.a) {
if (b + x.b == mod) a++;
add(b, x.b);
} else if (a > x.a)
a = x.a, b = x.b;
}
Mint operator + (const Mint & x) const {
Mint res = * this;
res += x;
return res;
}
Mint operator * (const Mint & x) const {
Mint res;
res.a = a + x.a;
res.b = (ll)b * x.b % mod;
return res;
}
Mint operator / (const Mint & x) const {
Mint res;
res.a = a - x.a;
res.b = (ll)b * bp(x.b, mod - 2) % mod;
return res;
}
};
struct Block {
int l = 0, r = 0, t = 0;
Mint add[n0], c[n0], cur;
Block() {
c[0] = 1;
}
void upd(Mint x) {
add[t++] = x;
c[t] = c[t - 1] * (r - l + t) / t;
cur = 0;
for (int i = 0; i < t; i++)
cur += c[t - i] * add[i];
}
};
Block b[n0];
int main() {
ios_base::sync_with_stdio(false), cin.tie(NULL);
cin >> n;
vector <int> crd;
for (int i = 0; i < n; i++) {
cin >> l[i] >> r[i];
r[i]++;
crd.pb(l[i]), crd.pb(r[i]);
}
crd.pb(0), crd.pb(1);
sort(all(crd));
for (int i = 1; i < SZ(crd); i++) {
if (crd[i - 1] < crd[i]) {
b[k].l = crd[i - 1];
b[k++].r = crd[i] - 1;
}
}
b[0].upd(1);
for (int i = 0; i < n; i++) {
Mint cur;
int j = 0;
for (; j < k && b[j].r < l[i]; j++)
cur += b[j].cur;
for (; j < k && b[j].r < r[i]; j++) {
b[j].upd(cur);
cur = b[j].cur;
}
}
Mint res;
for (int i = 0; i < k; i++)
res += b[i].cur;
res += (mod - 1);
if (res.a) cout << 0;
else cout << res.b;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
12 ms |
16128 KB |
Output is correct |
2 |
Correct |
12 ms |
16128 KB |
Output is correct |
3 |
Correct |
12 ms |
16128 KB |
Output is correct |
4 |
Correct |
12 ms |
16128 KB |
Output is correct |
5 |
Correct |
12 ms |
16128 KB |
Output is correct |
6 |
Correct |
12 ms |
16128 KB |
Output is correct |
7 |
Correct |
12 ms |
16128 KB |
Output is correct |
8 |
Correct |
12 ms |
16128 KB |
Output is correct |
9 |
Correct |
12 ms |
16128 KB |
Output is correct |
10 |
Correct |
12 ms |
16128 KB |
Output is correct |
11 |
Correct |
12 ms |
16128 KB |
Output is correct |
12 |
Correct |
13 ms |
16128 KB |
Output is correct |
13 |
Correct |
12 ms |
16128 KB |
Output is correct |
14 |
Correct |
12 ms |
16128 KB |
Output is correct |
15 |
Correct |
12 ms |
16128 KB |
Output is correct |
16 |
Correct |
12 ms |
16128 KB |
Output is correct |
17 |
Correct |
11 ms |
16256 KB |
Output is correct |
18 |
Correct |
11 ms |
16128 KB |
Output is correct |
19 |
Correct |
11 ms |
16128 KB |
Output is correct |
20 |
Correct |
11 ms |
16128 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
12 ms |
16128 KB |
Output is correct |
2 |
Correct |
12 ms |
16128 KB |
Output is correct |
3 |
Correct |
12 ms |
16128 KB |
Output is correct |
4 |
Correct |
12 ms |
16128 KB |
Output is correct |
5 |
Correct |
12 ms |
16128 KB |
Output is correct |
6 |
Correct |
12 ms |
16128 KB |
Output is correct |
7 |
Correct |
12 ms |
16128 KB |
Output is correct |
8 |
Correct |
12 ms |
16128 KB |
Output is correct |
9 |
Correct |
12 ms |
16128 KB |
Output is correct |
10 |
Correct |
12 ms |
16128 KB |
Output is correct |
11 |
Correct |
12 ms |
16128 KB |
Output is correct |
12 |
Correct |
13 ms |
16128 KB |
Output is correct |
13 |
Correct |
12 ms |
16128 KB |
Output is correct |
14 |
Correct |
12 ms |
16128 KB |
Output is correct |
15 |
Correct |
12 ms |
16128 KB |
Output is correct |
16 |
Correct |
12 ms |
16128 KB |
Output is correct |
17 |
Correct |
11 ms |
16256 KB |
Output is correct |
18 |
Correct |
11 ms |
16128 KB |
Output is correct |
19 |
Correct |
11 ms |
16128 KB |
Output is correct |
20 |
Correct |
11 ms |
16128 KB |
Output is correct |
21 |
Incorrect |
183 ms |
16168 KB |
Output isn't correct |
22 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
13 ms |
16128 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
12 ms |
16128 KB |
Output is correct |
2 |
Correct |
12 ms |
16128 KB |
Output is correct |
3 |
Correct |
12 ms |
16128 KB |
Output is correct |
4 |
Correct |
12 ms |
16128 KB |
Output is correct |
5 |
Correct |
12 ms |
16128 KB |
Output is correct |
6 |
Correct |
12 ms |
16128 KB |
Output is correct |
7 |
Correct |
12 ms |
16128 KB |
Output is correct |
8 |
Correct |
12 ms |
16128 KB |
Output is correct |
9 |
Correct |
12 ms |
16128 KB |
Output is correct |
10 |
Correct |
12 ms |
16128 KB |
Output is correct |
11 |
Correct |
12 ms |
16128 KB |
Output is correct |
12 |
Correct |
13 ms |
16128 KB |
Output is correct |
13 |
Correct |
12 ms |
16128 KB |
Output is correct |
14 |
Correct |
12 ms |
16128 KB |
Output is correct |
15 |
Correct |
12 ms |
16128 KB |
Output is correct |
16 |
Correct |
12 ms |
16128 KB |
Output is correct |
17 |
Correct |
11 ms |
16256 KB |
Output is correct |
18 |
Correct |
11 ms |
16128 KB |
Output is correct |
19 |
Correct |
11 ms |
16128 KB |
Output is correct |
20 |
Correct |
11 ms |
16128 KB |
Output is correct |
21 |
Incorrect |
183 ms |
16168 KB |
Output isn't correct |
22 |
Halted |
0 ms |
0 KB |
- |