# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
134304 | 2019-07-22T11:42:51 Z | sebinkim | Fibonacci representations (CEOI18_fib) | C++14 | 675 ms | 81572 KB |
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair <ll, ll> pll; const ll mod = 1e9 + 7; struct matrix{ ll aa, ab, ba, bb; matrix() : aa(1), ab(0), ba(0), bb(1) {} matrix(ll aa, ll ab, ll ba, ll bb) : aa(aa), ab(ab), ba(ba), bb(bb) {} matrix(ll x, ll d) { aa = x / 2 % mod; ab = (x - 1) / 2 % mod; ba = (aa * (d - 1) + 1) % mod; bb = (ab * (d - 1) + 1) % mod; } matrix operator * (matrix m) { return matrix((aa * m.aa + ab * m.ba) % mod, (aa * m.ab + ab * m.bb) % mod, (ba * m.aa + bb * m.ba) % mod, (ba * m.ab + bb * m.bb) % mod); } }; struct node{ ll d, l, r; matrix m; node() : d(0) {} node(pll p) : d((p.second - p.first) / 2), l(p.first + 1), r(p.second - 1) {} }; node operator + (node na, node nb) { if(!na.d) return nb; if(!nb.d) return na; node ret = na; ret.r = nb.r; matrix m(nb.l - na.r, nb.d); ret.m = nb.m * m * na.m; return ret; } struct segtree{ node T[1101010]; ll sz = 1 << 19; void update(ll p, pll v) { p += sz; if(T[p].d) T[p] = node(); else T[p] = node(v); for(p>>=1; p; p>>=1){ T[p] = T[p << 1] + T[p << 1 | 1]; } } ll getans() { matrix m = T[1].m * matrix(T[1].l, T[1].d); return (m.ab + m.bb) % mod; } }; segtree T; set <pll> S; vector <pll> X[101010]; vector <ll> Z; ll n; void insert(ll t, pll p) { Z.push_back(p.first); X[t].push_back(p); S.insert(p); } void erase(ll t, set <pll>::iterator it) { X[t].push_back(*it); S.erase(it); } void addval(ll t, ll x) { auto it = S.lower_bound(pll(x, 2e9)); if(it == S.begin() || prev(it) -> second < x){ pll p(x - 1, x + 1); if(it != S.begin() && prev(it) -> second + 1 == x){ p.first = prev(it) -> first; erase(t, prev(it)); } it = S.lower_bound(pll(x, 2e9)); if(it != S.end() && x + 1 == it -> first){ p.second = it -> second; erase(t, it); } insert(t, p); } else{ it = prev(it); if(it -> second - x & 1){ pll p(it -> first + 1, x); ll x1 = it -> first - 1, x2 = it -> second; erase(t, it); if(p.first < p.second) insert(t, p); if(x1 >= 0) addval(t, max(x1, 1ll)); addval(t, x2); } else{ pll p(it -> first, min(it -> second - 2, x)); x = max(it -> second, x + 1); erase(t, it); if(p.first < p.second) insert(t, p); addval(t, x); } } } int main() { ll i, x; ll d0, d1, lt, _d0, _d1, d, l; scanf("%lld", &n); for(i=0; i<n; i++){ scanf("%lld", &x); addval(i, x); } sort(Z.begin(), Z.end()); Z.erase(unique(Z.begin(), Z.end()), Z.end()); for(i=0; i<n; i++){ for(pll &t: X[i]){ x = lower_bound(Z.begin(), Z.end(), t.first) - Z.begin(); T.update(x, t); } printf("%lld\n", T.getans()); } return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 51 ms | 62968 KB | Output is correct |
2 | Correct | 51 ms | 62968 KB | Output is correct |
3 | Correct | 52 ms | 62968 KB | Output is correct |
4 | Correct | 51 ms | 63096 KB | Output is correct |
5 | Correct | 52 ms | 62968 KB | Output is correct |
6 | Correct | 52 ms | 63096 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 51 ms | 62968 KB | Output is correct |
2 | Correct | 51 ms | 62968 KB | Output is correct |
3 | Correct | 52 ms | 62968 KB | Output is correct |
4 | Correct | 51 ms | 63096 KB | Output is correct |
5 | Correct | 52 ms | 62968 KB | Output is correct |
6 | Correct | 52 ms | 63096 KB | Output is correct |
7 | Correct | 52 ms | 62972 KB | Output is correct |
8 | Correct | 53 ms | 63028 KB | Output is correct |
9 | Correct | 51 ms | 63096 KB | Output is correct |
10 | Correct | 52 ms | 62968 KB | Output is correct |
11 | Correct | 52 ms | 63096 KB | Output is correct |
12 | Correct | 52 ms | 63068 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 52 ms | 63092 KB | Output is correct |
2 | Correct | 52 ms | 63096 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 51 ms | 62968 KB | Output is correct |
2 | Correct | 51 ms | 62968 KB | Output is correct |
3 | Correct | 52 ms | 62968 KB | Output is correct |
4 | Correct | 51 ms | 63096 KB | Output is correct |
5 | Correct | 52 ms | 62968 KB | Output is correct |
6 | Correct | 52 ms | 63096 KB | Output is correct |
7 | Correct | 52 ms | 62972 KB | Output is correct |
8 | Correct | 53 ms | 63028 KB | Output is correct |
9 | Correct | 51 ms | 63096 KB | Output is correct |
10 | Correct | 52 ms | 62968 KB | Output is correct |
11 | Correct | 52 ms | 63096 KB | Output is correct |
12 | Correct | 52 ms | 63068 KB | Output is correct |
13 | Correct | 52 ms | 63092 KB | Output is correct |
14 | Correct | 52 ms | 63096 KB | Output is correct |
15 | Correct | 52 ms | 63032 KB | Output is correct |
16 | Correct | 52 ms | 63024 KB | Output is correct |
17 | Correct | 52 ms | 63096 KB | Output is correct |
18 | Correct | 52 ms | 63096 KB | Output is correct |
19 | Correct | 52 ms | 62948 KB | Output is correct |
20 | Correct | 51 ms | 62968 KB | Output is correct |
21 | Correct | 53 ms | 63096 KB | Output is correct |
22 | Correct | 51 ms | 62968 KB | Output is correct |
23 | Correct | 52 ms | 63096 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 52 ms | 63068 KB | Output is correct |
2 | Correct | 350 ms | 75108 KB | Output is correct |
3 | Correct | 373 ms | 74136 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 51 ms | 62968 KB | Output is correct |
2 | Correct | 51 ms | 62968 KB | Output is correct |
3 | Correct | 52 ms | 62968 KB | Output is correct |
4 | Correct | 51 ms | 63096 KB | Output is correct |
5 | Correct | 52 ms | 62968 KB | Output is correct |
6 | Correct | 52 ms | 63096 KB | Output is correct |
7 | Correct | 52 ms | 62972 KB | Output is correct |
8 | Correct | 53 ms | 63028 KB | Output is correct |
9 | Correct | 51 ms | 63096 KB | Output is correct |
10 | Correct | 52 ms | 62968 KB | Output is correct |
11 | Correct | 52 ms | 63096 KB | Output is correct |
12 | Correct | 52 ms | 63068 KB | Output is correct |
13 | Correct | 52 ms | 63092 KB | Output is correct |
14 | Correct | 52 ms | 63096 KB | Output is correct |
15 | Correct | 52 ms | 63032 KB | Output is correct |
16 | Correct | 52 ms | 63024 KB | Output is correct |
17 | Correct | 52 ms | 63096 KB | Output is correct |
18 | Correct | 52 ms | 63096 KB | Output is correct |
19 | Correct | 52 ms | 62948 KB | Output is correct |
20 | Correct | 51 ms | 62968 KB | Output is correct |
21 | Correct | 53 ms | 63096 KB | Output is correct |
22 | Correct | 51 ms | 62968 KB | Output is correct |
23 | Correct | 52 ms | 63096 KB | Output is correct |
24 | Correct | 52 ms | 63068 KB | Output is correct |
25 | Correct | 350 ms | 75108 KB | Output is correct |
26 | Correct | 373 ms | 74136 KB | Output is correct |
27 | Correct | 123 ms | 66740 KB | Output is correct |
28 | Correct | 176 ms | 69040 KB | Output is correct |
29 | Correct | 144 ms | 67440 KB | Output is correct |
30 | Correct | 197 ms | 68808 KB | Output is correct |
31 | Correct | 273 ms | 72168 KB | Output is correct |
32 | Correct | 251 ms | 70640 KB | Output is correct |
33 | Correct | 299 ms | 72036 KB | Output is correct |
34 | Correct | 251 ms | 72036 KB | Output is correct |
35 | Correct | 356 ms | 71632 KB | Output is correct |
36 | Correct | 376 ms | 71912 KB | Output is correct |
37 | Correct | 338 ms | 71376 KB | Output is correct |
38 | Correct | 358 ms | 75200 KB | Output is correct |
39 | Correct | 189 ms | 69436 KB | Output is correct |
40 | Correct | 256 ms | 71908 KB | Output is correct |
41 | Correct | 434 ms | 73444 KB | Output is correct |
42 | Correct | 439 ms | 75240 KB | Output is correct |
43 | Correct | 280 ms | 73956 KB | Output is correct |
44 | Correct | 398 ms | 81572 KB | Output is correct |
45 | Correct | 675 ms | 80900 KB | Output is correct |
46 | Correct | 425 ms | 81248 KB | Output is correct |
47 | Correct | 475 ms | 77684 KB | Output is correct |
48 | Correct | 499 ms | 81504 KB | Output is correct |
49 | Correct | 585 ms | 81052 KB | Output is correct |
50 | Correct | 396 ms | 75944 KB | Output is correct |