Skip to content
Snippets Groups Projects
Commit 3f16da49 authored by Bruno Freitas Tissei's avatar Bruno Freitas Tissei
Browse files

Small improvements

parent 8e93f6cd
No related branches found
No related tags found
No related merge requests found
...@@ -3,20 +3,22 @@ ...@@ -3,20 +3,22 @@
/// Complexity (Time): O(log n) /// Complexity (Time): O(log n)
/// Complexity (Space): O(1) /// Complexity (Space): O(1)
/// Returns x^n in O(log n) time struct BinaryExponentiation {
/// @param x number
/// @param n exponent
template <typename T>
T fast_pow(T x, ll n) {
T ans = 1;
while (n) { /// Returns x^n in O(log n) time
if (n & 1) /// @param x number
ans = ans * x; /// @param n exponent
ll fast_pow(ll x, ll n) {
ll ans = 1;
n >>= 1; while (n) {
x = x * x; if (n & 1)
} ans = ans * x;
n >>= 1;
x = x * x;
}
return ans; return ans;
} }
};
...@@ -4,7 +4,6 @@ ...@@ -4,7 +4,6 @@
/// Complexity (Space): O(1) /// Complexity (Space): O(1)
struct TernarySearch { struct TernarySearch {
const double EPS = 1e-6;
/// Unimodal function /// Unimodal function
double f(double x) { double f(double x) {
......
...@@ -32,13 +32,11 @@ int query(int idx) { ...@@ -32,13 +32,11 @@ int query(int idx) {
return sum; return sum;
} }
void update(int idx, int val) { void update(int idx, int val) {
for (; idx <= MAX; idx += (idx & -idx)) for (; idx <= MAX; idx += (idx & -idx))
tree[idx] += val; tree[idx] += val;
} }
int main() { int main() {
ios::sync_with_stdio(0); ios::sync_with_stdio(0);
cin.tie(0); cin.tie(0);
......
...@@ -48,7 +48,6 @@ int main() { ...@@ -48,7 +48,6 @@ int main() {
while (!Q.empty()) { while (!Q.empty()) {
elem curr = Q.front(); Q.pop(); elem curr = Q.front(); Q.pop();
cont[curr.fi.fi][curr.fi.se][curr.se.fi] = 1;
if (mat[curr.fi.fi][curr.fi.se] == '*') if (mat[curr.fi.fi][curr.fi.se] == '*')
return cout << curr.se.se << ende, 0; return cout << curr.se.se << ende, 0;
...@@ -63,14 +62,14 @@ int main() { ...@@ -63,14 +62,14 @@ int main() {
if (mat[x][y] >= 'A' && mat[x][y] <= 'G') { if (mat[x][y] >= 'A' && mat[x][y] <= 'G') {
if (msk & (1 << (mat[x][y] - 'A'))) { if (msk & (1 << (mat[x][y] - 'A'))) {
//cont[x][y][msk] = 1; cont[x][y][msk] = 1;
Q.push({{x, y}, {msk, curr.se.se + 1}}); Q.push({{x, y}, {msk, curr.se.se + 1}});
} }
} else { } else {
if (mat[x][y] >= 'a' && mat[x][y] <= 'g') if (mat[x][y] >= 'a' && mat[x][y] <= 'g')
msk |= (1 << (mat[x][y] - 'a')); msk |= (1 << (mat[x][y] - 'a'));
//cont[x][y][msk] = 1; cont[x][y][msk] = 1;
Q.push({{x, y}, {msk, curr.se.se + 1}}); Q.push({{x, y}, {msk, curr.se.se + 1}});
} }
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment