-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTemplete.cpp
More file actions
223 lines (189 loc) · 4.05 KB
/
Templete.cpp
File metadata and controls
223 lines (189 loc) · 4.05 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
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
#include <bits/stdc++.h>
#include <iomanip>
#define DEBUG 1
using namespace std;
typedef long long LL;
typedef long double LD;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;
typedef pair<LD, LD> PLDLD;
typedef vector<int> VI;
typedef vector<LL> VLL;
typedef vector<char> VB;
#define FOR(i,a,b) for(int i=(a);i<(int)(b);++i)
#define REP(i,n) FOR(i,0,n)
#define CLR(a) memset((a), 0 ,sizeof(a))
#define ALL(a) a.begin(),a.end()
#define UNQ(a) a.erase(std::unique(ALL(a)),a.end());
#define endl "\n"
const LD EPS=1e-10;
const long long INFLL=(LL)(1e9)*(LL)(1e9);
const int INF=1e9+7;
template<class T>
void chmin(T& a, const T b)
{
if(a>b)
a=b;
}
template<class T>
void chmax(T& a, const T b)
{
if(a<b)
a=b;
}
const LL powLL(const LL p, const LL q)
{
LL t=1;
for(int i=0;i<q;i++)
t*=p;
return t;
}
template <typename T>
struct has_iter
{
private:
template <typename U>
static constexpr true_type check(typename U::iterator*);
template <typename U>
static constexpr false_type check(...);
public:
static constexpr bool value = decltype(check<T>(nullptr))::value;
};
template<typename T, typename U = typename T::iterator>
void print(const T& container)
{
auto&& first=begin(container), last=end(container);
auto&& back=prev(last);
for(auto e=first; e!=last; e=next(e))
cout<<*e<<" \n"[e==back];
}
extern void* enabler;
template<typename Head, typename enable_if<!has_iter<Head>::value>::type*& = enabler>
void print(const Head& head)
{
cout<<head<<endl;
}
template<> void print<string>(const string& container)
{
cout<<container<<endl;
}
template<typename Head, typename... Tail>
void print(const Head& head, const Tail&... tail)
{
cout<<head<<" ";
print(tail...);
}
template<typename... Args>
void printd(const Args&... args)
{
#ifdef DEBUG
print(args...);
#endif
}
template<typename Head>
void input(Head& head)
{
cin>>head;
}
template<typename Head, typename... Tail>
void input(Head& head, Tail&... tail)
{
cin>>head;
input(tail...);
}
void io_speedup()
{
cin.tie(0);
cout.tie(0);
ios::sync_with_stdio(false);
}
template<typename T>
istream& operator >> (istream& is, vector<T>& vec)
{
for(T& x: vec) is >> x;
return is;
}
template<typename T, typename U>
istream& operator >> (istream& is, pair<T, U>& t)
{
is>>t.first>>t.second;
return is;
}
template<int N, typename... Ts, typename enable_if<N == sizeof...(Ts)-1>::type*& = enabler>
void tuple_in(istream &is, tuple<Ts...> &t)
{
is>>get<N>(t);
}
template<int N, typename... Ts, typename enable_if<N < sizeof...(Ts)-1>::type*& = enabler>
void tuple_in(istream &is, tuple<Ts...> &t)
{
is>>get<N>(t);
tuple_in<N+1, Ts...>(is, t);
}
template<typename... Ts>
istream& operator >> (istream& is, tuple<Ts...>& t)
{
tuple_in<0, Ts...>(is, t);
return is;
}
template<typename T, typename U>
ostream& operator << (ostream& os, const pair<T, U>& t)
{
os<<'('<<t.first<<", "<<t.second<<')';
return os;
}
template<int N, typename... Ts, typename enable_if<N == sizeof...(Ts)-1>::type*& = enabler>
void tuple_out(ostream &os,const tuple<Ts...> &t)
{
os<<get<N>(t);
}
template<int N, typename... Ts, typename enable_if<N < sizeof...(Ts)-1>::type*& = enabler>
void tuple_out(ostream &os,const tuple<Ts...> &t)
{
os<<get<N>(t)<<", ";
tuple_out<N+1, Ts...>(os, t);
}
template<typename... Ts>
ostream& operator << (ostream& os, const tuple<Ts...>& t)
{
os<<'(';
tuple_out<0, Ts...>(os, t);
os<<')';
return os;
}
template<typename T>
vector<T> read(int n)
{
vector<T> t(n);
cin>>t;
return t;
}
template<typename T>
T read()
{
T t;
cin>>t;
return t;
}
template<typename Head, typename... Tail>
struct vector_demensions
{
using type=vector<typename vector_demensions<Tail...>::type>;
};
template<typename Head>
struct vector_demensions<Head> { using type=Head; };
template<typename T>
vector<T> make_vectors(int size, T val)
{
return vector<T>(size, val);
}
template<typename T=int, typename... Args>
auto make_vectors(int size, Args... tail)
-> typename vector_demensions<Args..., T>::type
{
auto val=make_vectors<T>(forward<Args>(tail)...);
return vector<decltype(val)>(size, val);
}
int main()
{
}