update template and debugger

This commit is contained in:
ShazidMahsrafi 2024-04-30 16:50:37 +06:00
parent 8f472939de
commit cfcd860bf0
2 changed files with 32 additions and 29 deletions

View File

@ -11,7 +11,7 @@ using namespace std;
#define sz(x) (int)(x).size() #define sz(x) (int)(x).size()
#define yes cout << "YES" << endl #define yes cout << "YES" << endl
#define no cout << "NO" << endl #define no cout << "NO" << endl
#define FAST (ios_base:: sync_with_stdio(false),cin.tie(NULL)); #define FAST (ios_base::sync_with_stdio(false), cin.tie(nullptr));
ll pow(ll x,ll y,ll m=1e9+7){ll ans=1;x%=m;while(y){if(y&1)ans=(ans*x)%m;x=(x*x)%m;y>>=1;}return ans;} ll pow(ll x,ll y,ll m=1e9+7){ll ans=1;x%=m;while(y){if(y&1)ans=(ans*x)%m;x=(x*x)%m;y>>=1;}return ans;}
void solve() void solve()
@ -22,7 +22,11 @@ void solve()
signed main() signed main()
{ {
FAST; FAST;
int TC = 1; int TCS = 1;
// cin >> TC; // cin >> TC;
while (TC--) solve(); for (int TC = 1; TC <= TCS; ++TC)
{
// cout<<"Case "<<TC<<": ";
solve();
}
} }

31
debug.h
View File

@ -3,8 +3,7 @@ namespace __DEBUG_UTIL__
{ {
using namespace std; using namespace std;
template <typename T> template <typename T>
concept is_iterable = requires(T &&x) { begin(x); } && concept is_iterable = requires(T &&x) { begin(x); } && !is_same_v<remove_cvref_t<T>, string>;
!is_same_v<remove_cvref_t<T>, string>;
void print(const char *x) { cerr << x; } void print(const char *x) { cerr << x; }
void print(char x) { cerr << "\'" << x << "\'"; } void print(char x) { cerr << "\'" << x << "\'"; }
void print(bool x) { cerr << (x ? "T" : "F"); } void print(bool x) { cerr << (x ? "T" : "F"); }
@ -13,10 +12,10 @@ namespace __DEBUG_UTIL__
{ /* Overloaded this because stl optimizes vector<bool> by using { /* Overloaded this because stl optimizes vector<bool> by using
_Bit_reference instead of bool to conserve space. */ _Bit_reference instead of bool to conserve space. */
int f = 0; int f = 0;
cerr << '{'; cerr << '[';
for (auto &&i : v) for (auto &&i : v)
cerr << (f++ ? "," : "") << (i ? "T" : "F"); cerr << (f++ ? "," : "") << (i ? "T" : "F");
cerr << "}"; cerr << "]";
} }
template <typename T> template <typename T>
void print(T &&x) void print(T &&x)
@ -35,23 +34,23 @@ namespace __DEBUG_UTIL__
else else
{ /* Normal Iterable */ { /* Normal Iterable */
int f = 0; int f = 0;
cerr << "{"; cerr << "[";
for (auto &&i : x) for (auto &&i : x)
cerr << (f++ ? "," : ""), print(i); cerr << (f++ ? "," : ""), print(i);
cerr << "}"; cerr << "]";
} }
else if constexpr (requires { x.pop(); }) /* Stacks, Priority Queues, Queues */ else if constexpr (requires { x.pop(); }) /* Stacks, Priority Queues, Queues */
{ {
auto temp = x; auto temp = x;
int f = 0; int f = 0;
cerr << "{"; cerr << "[";
if constexpr (requires { x.top(); }) if constexpr (requires { x.top(); })
while (!temp.empty()) while (!temp.empty())
cerr << (f++ ? "," : ""), print(temp.top()), temp.pop(); cerr << (f++ ? "," : ""), print(temp.top()), temp.pop();
else else
while (!temp.empty()) while (!temp.empty())
cerr << (f++ ? "," : ""), print(temp.front()), temp.pop(); cerr << (f++ ? "," : ""), print(temp.front()), temp.pop();
cerr << "}"; cerr << "]";
} }
else if constexpr (requires { x.first; x.second; }) /* Pair */ else if constexpr (requires { x.first; x.second; }) /* Pair */
{ {
@ -80,9 +79,9 @@ namespace __DEBUG_UTIL__
cerr.write(names, i) << " = "; cerr.write(names, i) << " = ";
print(head); print(head);
if constexpr (sizeof...(tail)) if constexpr (sizeof...(tail))
cerr << " || ", printer(names + i + 1, tail...); cerr << " | ", printer(names + i + 1, tail...);
else else
cerr << "]\n"; cerr << "\n";
} }
template <typename T, typename... V> template <typename T, typename... V>
void printerArr(const char *names, T arr[], size_t N, V... tail) void printerArr(const char *names, T arr[], size_t N, V... tail)
@ -92,16 +91,16 @@ namespace __DEBUG_UTIL__
cerr << names[i]; cerr << names[i];
for (i++; names[i] and names[i] != ','; i++) for (i++; names[i] and names[i] != ','; i++)
; ;
cerr << " = {"; cerr << " = [";
for (size_t ind = 0; ind < N; ind++) for (size_t ind = 0; ind < N; ind++)
cerr << (ind ? "," : ""), print(arr[ind]); cerr << (ind ? "," : ""), print(arr[ind]);
cerr << "}"; cerr << "]";
if constexpr (sizeof...(tail)) if constexpr (sizeof...(tail))
cerr << " || ", printerArr(names + i + 1, tail...); cerr << " | ", printerArr(names + i + 1, tail...);
else else
cerr << "]\n"; cerr << "\n";
} }
} }
#define dbg(...) std::cerr << __LINE__ << ": [", __DEBUG_UTIL__::printer(#__VA_ARGS__, __VA_ARGS__) #define dbg(...) std::cerr << __LINE__ << ": ", __DEBUG_UTIL__::printer(#__VA_ARGS__, __VA_ARGS__)
#define dbgArr(...) std::cerr << __LINE__ << ": [", __DEBUG_UTIL__::printerArr(#__VA_ARGS__, __VA_ARGS__) #define dbgArr(...) std::cerr << __LINE__ << ": ", __DEBUG_UTIL__::printerArr(#__VA_ARGS__, __VA_ARGS__)