跳到正文

个人记录

C++11适用的OI模板

zhuziyue321约 9 分钟
原文
文章信息与版本

文章信息

收录
2025年12月12日
更新
2025年12月12日
篇幅
约 9 分钟

版本

  1. v1当前
C++
#include<bits/stdc++.h>
using namespace std;
template<typename T>struct is_basic_string:false_type{};
template<typename...Args>struct is_basic_string<basic_string<Args...>>:true_type{};
namespace detail{
    template<typename It>void output_array(ostream&,It,It);
    template<typename T,int N>typename enable_if<N+1==tuple_size<T>::value>::type tuple_helper(ostream&,const T&);
    template<typename T,int N>typename enable_if<N+1!=tuple_size<T>::value>::type tuple_helper(ostream&,const T&);
}
template<typename Cont>typename enable_if<is_same<decltype(begin(declval<Cont>())),decltype(end(declval<Cont>()))>::value&&!is_basic_string<Cont>::value,ostream&>::type operator<<(ostream&x,const Cont&y){detail::output_array(x,begin(y),end(y));return x;}
template<typename T,int N>typename enable_if<!__is_char<T>::value,ostream&>::type operator<<(ostream&x,const T(&y)[N]){detail::output_array(x,y,y+N);return x;}
template<typename T1,typename T2>ostream&operator<<(ostream&x,const pair<T1,T2>&y){x<<'('<<y.first<<',';x<<y.second<<')';return x;}
template<typename...Args>typename enable_if<sizeof...(Args),ostream&>::type operator<<(ostream&x,const tuple<Args...>&y){x<<'(';detail::tuple_helper<tuple<Args...>,0>(x,y);x<<')';return x;}
ostream&operator<<(ostream&x,const tuple<>&y){x<<"()";return x;}
namespace detail{
    template<typename It>void output_array(ostream&x,It first,It last){x<<'[';if(first!=last){x<<*first;while(++first!=last){x<<','<<*first;}}x<<']';}
    template<typename T,int N>typename enable_if<N+1==tuple_size<T>::value>::type tuple_helper(ostream&x,const T&y){x<<get<N>(y);}
    template<typename T,int N>typename enable_if<N+1!=tuple_size<T>::value>::type tuple_helper(ostream&x,const T&y){x<<get<N>(y)<<',';tuple_helper<T,N+1>(x,y);}
}
template<typename T>void debug(const T&x){cerr<<x;}
template<typename T,typename...Args>void debug(const T&x,const Args&...args){cerr<<x;cerr.put(',');debug(args...);}
#define debug_color "\033[33m"
#ifdef debug_color
#define debug_color_wrapper(...) {cerr<<debug_color;__VA_ARGS__;cerr<<"\033[0m";}
#else
#define debug_color_wrapper(...) {__VA_ARGS__;}
#endif // debug_color
#ifdef ONLINE_JUDGE
#define debug(...)
#define debug_if(...)
#define debug_assert(...)
#define debug_array(...)
#else
#define debug(...) debug_color_wrapper(cerr<<#__VA_ARGS__"=";debug(__VA_ARGS__);cerr<<'\n';)
#define debug_if(cond,...) if(cond){debug(__VA_ARGS__);}
#define debug_assert(cond,...) if(!(cond)){cerr<<"Debug assertion failed["<<__LINE__<<"]:"#cond"\n";debug(__VA_ARGS__);abort();}
#define debug_array(arr,first,last) debug_color_wrapper(cerr<<#arr"["<<first<<':'<<last<<"]=";detail::output_array(cerr,begin(arr)+first,begin(arr)+last);cerr<<'\n';)
#endif // ONLINE_JUDGE
#define mod 998244353
#define eps 1e-8
#define fi first
#define se second
#define pb emplace_back
#define pu emplace
#define int long long
#define double long double
#ifdef int
#define inf 1000000000000000000ll
#else
#define inf 1000000000
#endif // int
#define vi vector<int>
#define pii pair<int,int>
#define all(cont) cont.begin(),cont.end()
#define lowbit(x) ((x)&-(x))
#define sleep(x) std::this_thread::sleep_for(std::chrono::milliseconds(x))
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define per(i,a,b) for(int i=(a);i>=(b);i--)
#define rep_(i,a,b) for(int i=(a);i<(b);i++)
#define per_(i,a,b) for(int i=(a);i>(b);i--)
#define Rep(i,a,b) for(int i=(a),i##end=(b);i<=i##end;i++)
#define Per(i,a,b) for(int i=(a),i##end=(b);i>=i##end;i--)
#define Rep_(i,a,b) for(int i=(a),i##end=(b);i<i##end;i++)
#define Per_(i,a,b) for(int i=(a),i##end=(b);i>i##end;i--)
bool bg;
#define N
void mian(int argt){
}
bool ed;
signed main(){
    #ifdef ONLINE_JUDGE
    //freopen(".in","r",stdin);
    //freopen(".out","w",stdout);
    #else
    freopen("1.in","r",stdin);
    //freopen(".out","w",stdout);
    auto program_begin=chrono::high_resolution_clock::now();
    #endif // ONLINE_JUDGE
    int T=1;
    //cin>>T;
    rep(i,1,T){
        mian(i);
    }
    #ifndef ONLINE_JUDGE
    auto program_end=chrono::high_resolution_clock::now();
    debug_color_wrapper(cerr<<"Time="<<chrono::duration_cast<chrono::milliseconds>(program_end-program_begin).count()<<"ms\nMemory="<<fixed<<setprecision(6)<<(&ed-&bg)/1048576.0<<"MB\n";)
    #endif // ONLINE_JUDGE
}
原文