-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathSTL_MACRO.h
More file actions
173 lines (129 loc) · 3.35 KB
/
STL_MACRO.h
File metadata and controls
173 lines (129 loc) · 3.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
/*
* STL_macros.h
*
* Created on: Dec 15, 2012
* Author: fmarecki
*/
#ifndef STL_MACROS_H_
#define STL_MACROS_H_
#include <inttypes.h>
#include <cmath>
#include <cassert>
#include <iostream>
#include <fstream>
#include <sstream>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <algorithm>
#include <iterator>
#include <cstdlib>
#include <queue>
#include <stack>
#include <bitset>
#include <cstring>
using namespace std;
//Integer types
typedef uint64_t ulint;
typedef int64_t lint;
typedef uint32_t uint;
typedef uint16_t usint;
typedef uint8_t uchar;
//containers
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;
typedef vector<pii> vii;
typedef set<int> si;
typedef multiset<int> mi;
typedef list<int> li;
typedef vector<string> vs;
//traversing macros (use google style guide)
#define REP(i,n) for(int i=0;i<(n);++i)
#define REP1(i,n) for(int i=1;i<(n);++i)
#define FOR(i,l,u) for(int i=l;i<(u);++i)
//use `decltype` in >VC2010
#define TR(c,i) for(__typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define ALL(c) (c).begin(),(c).end()
#define SS size()
#define SET_MIN(v,nv) if ((v) > (nv)) (v)=(nv);
#define SET_MAX(v,nv) if ((v) < (nv)) (v)=(nv);
//shortcuts
#define PB push_back
#define MP make_pair
#define TOP(s) (*s.begin() ) //no range checking
#define POP(s) s.erase(s.begin()) //no range checking
#define PUSH(s,k) s.insert( (k) )
//#define PRESENT(c,x) ((c).find(x) != (c).end())
//#define CPRESENT(c,x) (find(ALL(c),x) != (c).end())
const int INF = 1e9;
//Arithmetics
// 1/5 --> 1; 5/5-->1; 6/5-->2
inline int CeilDiv(int a, int b) {
int r = (a % b)? 1: 0;
return a / b + r; /// !!!! standard stuff == (a+b-1)/b;
}
//Returns (-1)^k
inline int SIGN(int k) {
return (k % 2)? -1 : 1;
}
inline void EEE() {
printf("\n");
}
inline void assign_less(int *reg, int val) {
if (val < *reg) *reg = val;
}
template <typename T>
void PrintContainer(const T w) {
printf("{");
TR(w, i) {
if (*i != INF)
printf("%i, ", *i);
else
printf("-, ");
}
printf("\b\b}\n");
}
#define PrintMatrix(G,N,M) \
REP(i,N) { \
printf("[%2i] ",i); \
REP(j,N) \
printf("%3d", (G[i][j]==INF)?-1:G[i][j]); \
EEE(); \
}
#define PrintDMatrix(G,N,M) \
REP(i,N) { \
printf("[%2i] ",i); \
REP(j,N) \
printf("%3.2f ", (G[i][j]==INF)?-1:G[i][j]); \
EEE(); \
}
void PrintBit(uint H) {
REP(i, 32) {
int no = H;
int bit = 31-i%32;
bool val = no & (1<<bit);
printf("%i%s%s",val,(i+1)%8==0?" ":"",(i+1)%32==0?"| ":"");
}
EEE();
}
void PrintBit(ulint H) {
REP(i, 64) {
ulint no = H;
int bit = 63 - i%64;
bool val = (no & (1UL<<bit));
// printf("(%i),", bit);
printf("%i%s%s", val, ((i+1)%8==0)?" ":"",(i+1)%64==0?"| ":"");
}
// EEE();
}
uint lrot32(uint x, uint n) {
return ((x << n) | (x >> (32-n)));
}
uint rrot32(uint x, uint n) {
return ((x >> n) | (x << (32-n)));
}
//Returns lowest byte of a pointer.
inline uint32_t Lptr(void *ptr) { return (uint64_t)(ptr) & 0xfff;}
#endif /* STL_MACROS_H_ */