This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
int next_binary_power(int x) { | |
return 1 << (32 - __builtin_clz(x - 1)); | |
} | |
struct SegmentTree { | |
vector<int> nodes; | |
SegmentTree(int size) : nodes(next_binary_power(size) * 2, INT_MAX) {} | |
int query(int left, int right) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <cstdio> | |
#include <cstdlib> | |
#include <cassert> | |
#include <algorithm> | |
#include <vector> | |
#include <utility> | |
#include <set> | |
using namespace std; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
max(-x,-y) = -min(x,y) | |
min(-x,-y) = -max(x,y) | |
abs(x) = abs(-x) | |
abs(x) = max(x,-x) = -min(x,-x) | |
abs(x*a) = if (a >= 0) abs(x)*a | |
(a < 0) -abs(x)*a | |
// basically any commutative operation | |
min(x,y) + max(x,y) = x + y |