You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* we let dp(i) be the expected number of operations assuming we only need to deal with the prefix from the i-th least significant bit onwards,
3
+
* assuming that the i-th least significant bit is now 1.
4
+
*
5
+
* When considering dp(i), either we do the ceil or the floor.
6
+
* - If we do the floor, we need to skip forward to the next 1. For all the zeros between, it doesn't matter which operation we do.
7
+
* - If we do the ceil, we need to skip forward to the next 0, and treat if as if it is a 1. All the 1s in between will turn into 0s so the operations don't matter.
8
+
*
9
+
* The base cases is when i=n-1 and i=n, which is 0 since the number will already be <= 1
10
+
*
11
+
* Time: O(n), Space: O(n)
12
+
*/
13
+
#pragma GCC optimize("Ofast")
14
+
#pragma GCC optimize("unroll-loops")
15
+
#include<algorithm>
16
+
#include<array>
17
+
#include<cassert>
18
+
#include<iostream>
19
+
#include<print>
20
+
21
+
usingnamespacestd;
22
+
23
+
typedeflonglong ll;
24
+
#definefast_cin() \
25
+
ios_base::sync_with_stdio(false); \
26
+
cin.tie(NULL); \
27
+
cout.tie(NULL);
28
+
29
+
constexpr ll MOD = 1e9 + 7;
30
+
structmint {
31
+
ll x;
32
+
constexprmint(ll xx) : x(xx) {}
33
+
constexprmint() : x(0) {}
34
+
constexpr mint operator+(mint b) const { returnmint((x + b.x) % MOD); }
35
+
constexpr mint operator-(mint b) const { returnmint((x - b.x + MOD) % MOD); }
36
+
constexpr mint operator*(mint b) const { returnmint((x * b.x) % MOD); }
37
+
constexpr mint operator/(mint b) const { return *this * invert(b); }
0 commit comments