- mod
10^9+7—> const int MOD = 1e9 + 7; or static constexpr int MOD = 1000000007;!!!not 10e9
- Faster operation to select larger/smaller:
min(a,b); max(a,b);
- Faster operation to swap:
swap(vec[a], vec[b]);
- Sort:
sort(vec.begin(), vec.end()); in descending: sort(vec.begin(), vec.end(), greater<int>());
- int to str:
int n = to_string(str);
- To pass pointer:
// 1. by reference argument
void fun(int& a){
a = 1;
}
int main(){
int a;
fun(a);
}
// 2. by pointer argument
void fun(int* a){
*a = 1;
}
int main(){
int a;
fun(&a);
}
- int range: -INT_MAX-1 ~ INT_MAX
- case statement:
switch(n){
case '1':
//something here
//continue
break; //essential!
case '2':
//something here
//continue
break;
default:
//sth
break;
}
- data type:
int // 32 bits, -2^31 ~ 2^31 -1, ~10^10
long // 32~64 bits
long long // 64 bits, ~10^19
- compare with pair: two factors compare:
pair<int, int> mx{};
for (auto& d : dimensions) {
int x = d[0], y = d[1];
mx = max(mx, pair(x * x + y * y, x * y));
}