Skip to content

Instantly share code, notes, and snippets.

@waterlink
Created September 10, 2013 00:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save waterlink/6503326 to your computer and use it in GitHub Desktop.
Save waterlink/6503326 to your computer and use it in GitHub Desktop.
acm snippet
// snippet
// includes
#include <cstdio>
#include <string>
#include <algorithm>
#include <cmath>
#include <map>
#include <cstring>
#include <iostream>
#include <vector>
using namespace std;
// constants
#define inf 1000000000
#define eps 1e-5
#define maxn 10010
#define maxx 10010
#define PI 3.14159256
// modules
#define M1 13987621
#define M2 119473123
#define M3 49
#define M4 53
#define M5 127
#define M6 257
#define M7 7
#define M8 13
#define M9 17
#define M10 19
#define M11 23
#define M12 31
#define M13 29
// switches
#define I64d true
// types
#define ll long long
// handies
#define ii pair < int, int >
#define m_ii(a, b) make_pair(a, b)
#define iii pair < int, ii >
#define m_iii(a, b, c) m_ii(a, m_ii(b, c))
#define iiii pair < ii, ii >
#define m_iiii(a, b, c, d) m_ii(m_ii(a, b), m_ii(c, d))
// io helpers
int read_int(){
int res;
scanf("%d", &res);
return res;
}
double read_double() {
double res;
scanf("%lf", &res);
return res;
}
int read_int_from(const char* from) {
int res;
FILE* f = fopen(from, "r");
fscanf(f, "%d", &res);
fclose(f);
return res;
}
void read_ints(int* a, int n){
for (int i = 0; i < n; ++i){
scanf("%d", a + i);
}
}
void read_doubles(double* a, int n){
for (int i = 0; i < n; ++i){
scanf("%lf", a + i);
}
}
void read_all_ints(int* a, int &n){
n = 0;
while (scanf("%d", a + n) > 0) ++n;
}
void for_each(int* begin, int* end, void (*fun)(int)) {
for (; begin != end; ++begin) fun(*begin);
}
void print(int x){
printf("%d\n", x);
}
void print_d(double x) {
printf("%lf\n", x);
}
void print_l(long long x){
if (I64d) {
printf("%I64d\n", x);
} else {
printf("%lld\n", x);
}
}
void print_s(char* s){
printf("%s\n", s);
}
void print_to(const char* fname, int x) {
FILE* f = fopen(fname, "w");
fprintf(f, "%d\n", x);
fflush(f);
fclose(f);
}
bool in_range(int value, int a, int b) {
return value >= a && value < b;
}
int pwr_by_mod(int n, int a, int mod) {
if (a == 0) {
return 1;
}
int r = 1;
if (a % 2) r = n % mod;
r = r * pwr_by_mod(n * n % mod, a / 2, mod) % mod;
return r;
}
int gcd(int a, int b) {
while (a) { a ^= b ^= a ^= b %= a; }
return b;
}
int lcm(int a, int b) {
return a / gcd(a, b) * b;
}
ii get_gcd_vector(int a, int b) {
int g = gcd(abs(a), abs(b));
return m_ii(a / g, b / g);
}
ii negate_vector(ii v) {
return m_ii(-v.first, -v.second);
}
ll labs(ll x) {
if (x < 0) return -x;
return x;
}
int fenwick_get(int* B, int x) {
int res = 0;
for (int i = x; i > 0; i -= i & -i) {
res += B[i];
}
return res;
}
int fenwick_add(int* B, int N, int x, int v) {
for (int i = x; i < N; i += i & -i) {
B[i] += v;
}
}
// /snippet
int main(){
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment