首页 > 编程语言 >C++ namespace User_Unauthorized version 1.0.0 is officially released

C++ namespace User_Unauthorized version 1.0.0 is officially released

时间:2023-10-05 19:11:26浏览次数:59  
标签:std typedef 1.0 Unauthorized tparam namespace param T1 mod

Code
namespace User_Unauthorized {
    /**
     * @brief This is a header file for competitive programming.
     * @author User-Unauthorized
     * @version 1.0.0
     * @date 2023-10-5
     */

    typedef long long valueType;
    typedef std::vector<valueType> ValueVector;
    typedef std::vector<ValueVector> ValueMatrix;
    typedef std::vector<ValueMatrix> ValueCube;
    typedef std::map<valueType, valueType> ValueMap;
    typedef std::set<valueType> ValueSet;
    typedef std::pair<valueType, valueType> ValuePair;
    typedef std::vector<ValuePair> PairVector;
    typedef std::vector<PairVector> PairMatrix;
    typedef std::vector<PairMatrix> PairCube;
    typedef std::map<ValuePair, valueType> PairMap;
    typedef std::set<ValuePair> PairSet;
    typedef std::vector<bool> bitset;
    typedef std::vector<bitset> BitMatrix;
    typedef std::vector<BitMatrix> BitCube;
    typedef long double realType;
    typedef std::vector<realType> RealVector;
    typedef std::vector<RealVector> RealMatrix;
    typedef std::vector<RealMatrix> RealCube;
    typedef std::pair<realType, realType> RealPair;
    typedef std::vector<RealPair> RealPairVector;
    typedef std::vector<RealPairVector> RealPairMatrix;
    typedef std::vector<RealPairMatrix> RealPairCube;
    typedef std::mt19937 Engine;
    typedef std::uniform_int_distribution<valueType> Distribution;
    typedef unsigned long long hashType;
    typedef std::vector<hashType> HashVector;
    typedef std::vector<HashVector> HashMatrix;
    typedef std::vector<HashMatrix> HashCube;
    typedef std::map<hashType, valueType> HashMap;
    typedef std::set<hashType> HashSet;

    namespace ModOper {
        /**
         * @brief This is a set of functions for fast processing of operations under the meaning of taking modulus in competitive programming.
         * @author User-Unauthorized
         * @version 1.0.0
         * @warning Please note that the parameter types of these functions must be integer types, otherwise a compilation error will occur.
         * */

        valueType MOD; // mod value

        /**
         * @brief This is a macro for whether to ensure that the parameters passed in are integers in the range [0, MOD), if it cannot be guaranteed, the value of this macro should be true, otherwise unexpected results may occur.
         */
#define ModOperSafeModOption false

        /**
         * @brief This function can increase the value of a by b.
         * @tparam T1 
         * @tparam T2 
         * @tparam T3 
         * @param a 
         * @param b 
         * @param mod 
         */
        template<typename T1, typename T2, typename T3 = valueType>
        void Inc(T1 &a, T2 b, const T3 &mod = MOD) {
#if ModOperSafeModOption
            a %= mod;
            b %= mod;

            if (a < 0)
                a += mod;

            if (b < 0)
                b += mod;
#endif // ModOperSafeModOption

            a = a + b;

            if (a >= mod)
                a -= mod;
        }

        /**
         * @brief This function can decrease the value of a by b.
         * @tparam T1 
         * @tparam T2 
         * @tparam T3 
         * @param a 
         * @param b 
         * @param mod 
         */
        template<typename T1, typename T2, typename T3 = valueType>
        void Dec(T1 &a, T2 b, const T3 &mod = MOD) {
#if ModOperSafeModOption
            a %= mod;
            b %= mod;

            if (a < 0)
                a += mod;

            if (b < 0)
                b += mod;
#endif // ModOperSafeModOption

            a = a - b;

            if (a < 0)
                a += mod;
        }

        /**
         * @brief This function can calculate the sum of a and b.
         * @tparam T1 
         * @tparam T2 
         * @tparam T3 
         * @param a 
         * @param b 
         * @param mod 
         * @return T1 
         */
        template<typename T1, typename T2, typename T3 = valueType>
        T1 sum(T1 a, T2 b, const T3 &mod = MOD) {
#if ModOperSafeModOption
            a %= mod;
            b %= mod;

            if (a < 0)
                a += mod;

            if (b < 0)
                b += mod;
#endif // ModOperSafeModOption

            return a + b >= mod ? a + b - mod : a + b;
        }

        /**
         * @brief This function can calculate the difference of a and b.
         * @tparam T1 
         * @tparam T2 
         * @tparam T3 
         * @param a 
         * @param b 
         * @param mod 
         * @return T1 
         */
        template<typename T1, typename T2, typename T3 = valueType>
        T1 sub(T1 a, T2 b, const T3 &mod = MOD) {
#if ModOperSafeModOption
            a %= mod;
            b %= mod;

            if (a < 0)
                a += mod;

            if (b < 0)
                b += mod;
#endif // ModOperSafeModOption

            return a - b < 0 ? a - b + mod : a - b;
        }

        /**
         * @brief This function can calculate the product of a and b.
         * @tparam T1 
         * @tparam T2 
         * @tparam T3 
         * @param a 
         * @param b 
         * @param mod 
         * @return T1 
         */
        template<typename T1, typename T2, typename T3 = valueType>
        T1 mul(T1 a, T2 b, const T3 &mod = MOD) {
#if ModOperSafeModOption
            a %= mod;
            b %= mod;

            if (a < 0)
                a += mod;

            if (b < 0)
                b += mod;
#endif // ModOperSafeModOption

            return (long long) a * b % mod;
        }

        /**
         * @brief This function can make the value of a multiply b.
         * @tparam T1 
         * @tparam T2 
         * @tparam T3 
         * @param a 
         * @param b 
         * @param mod 
         * @return T1 
         */
        template<typename T1, typename T2, typename T3 = valueType>
        void Mul(T1 &a, T2 b, const T3 &mod = MOD) {
#if ModOperSafeModOption
            a %= mod;
            b %= mod;

            if (a < 0)
                a += mod;

            if (b < 0)
                b += mod;
#endif // ModOperSafeModOption

            a = (long long) a * b % mod;
        }

        /**
         * @brief This function can calculate the b-th power of a, and the time complexity is log b.
         * @tparam T1 
         * @tparam T2 
         * @tparam T3 
         * @param a 
         * @param b 
         * @param mod 
         * @return T1 
         */
        template<typename T1, typename T2, typename T3 = valueType>
        T1 pow(T1 a, T2 b, const T3 &mod = MOD) {
#if ModOperSafeModOption
            a %= mod;
            b %= mod;

            if (a < 0)
                a += mod;

            if (b < 0)
                b += mod;
#endif // ModOperSafeModOption

            T1 result = 1;

            while (b > 0) {
                if (b & 1)
                    Mul(result, a, mod);

                Mul(a, a, mod);
                b = b >> 1;
            }

            return result;
        }
    } // namespace ModOper
} // namespace User_Unauthorized

标签:std,typedef,1.0,Unauthorized,tparam,namespace,param,T1,mod
From: https://www.cnblogs.com/User-Unauthorized/p/namespace-User_Unauthorized_1_0_0.html

相关文章

  • SAP UI5 里 Namespace,Class 和 Enum 的区别
    SAPUI5是一种用于构建企业级Web应用程序的前端开发框架,它提供了丰富的UI组件和工具,以便开发者可以轻松创建现代、响应式和高性能的应用程序。在SAPUI5的API文档中,我们可以找到不同类型的树节点,包括Namespace、Class和Enum。下图的C代表Class,N代表Namespace,E代表Enum.......
  • 【11.0】Fastapi的OAuth2.0的授权模式
    【一】OAuth2.0的授权模式授权码授权模式(AuthorizationCodeGrant)隐式授权模式(ImplicitGrant)密码授权模式(ResourceOwnerPasswordCredentialsGrant)客户端凭证授权模式(ClientCredentialsGrant)【二】密码授权模式【1】FastAPI的OAuth2PasswordBearer说明......
  • 【1.0】引入
    【一】为什么新秀FastAPI火成这样介绍FastAPI有哪些突出特点,浏览官网文档中的Feasures一览【二】FastAPI的突出特点性能优越开发效率提升200%~300%直接减少约40%的人为BUG直观易学易用经简代码/代码重复率低自带API交互文档,开发成果随时交付API......
  • Linux常用命令本地查询工具:LinuxStudy 1.0
    最近在学习Linux,上千的命令整理了一下,随用随查,也分享给需要的小伙伴。语言平台为C#framework4.7.1,旧系统可能需要更新平台。程序开源,可关注https://gitee.com/windtrace/linux-study新版本。目前收集了www.linuxcool.comhttps://github.com/jaywcjlove/linux-command两个......
  • 【Sword系列】Vulnhub靶机Bob_v1.0.1 writeup
    个人博客地址:  http://www.sword-blogs.com/下载地址:https://www.vulnhub.com/entry/bob-101,226/信息搜集扫描IP地址扫描端口及端口信息访问80端口并没有发现有用的信息扫描目录看到有熟悉的robots.txt,访问看一下发现了dev_shell.php,可以执行一些简单的命令,但是不......
  • Hadoop 1.0.2 安装 使用 单机模式 Hadoop_1
    装完的HDFS用IE打开访问,查看其磁盘使用情况:http://192.168.33.10:50070/dfshealth.jsp step1.为Hadoop增加用户,记住设定的密码 Java代码 1.$sudoaddgrouphadoop2.$sudoadduser--ingrouphadoophduserstep2.ssh的安装与设置 由于Hadoop......
  • C语言学习日记1.0
    大学第一节c语言课结束感慨良多啊,我不太善于总结和表达,请各位见谅。第一节课就学习了hello,world简单程序的运行和c语言的特点:1、兼具高级语言的优点和对低级语言对硬件的操作能力,具有高级语言的高层抽象和良好的可移植性等优点。2、数据类型和运算符丰富3、它是完全模块化和......
  • 【1.0】Pandos初识
    【一】Pandas是什么Pandas是一个开源的第三方Python库,从Numpy和Matplotlib的基础上构建而来,享有数据分析“三剑客之一”的盛名(NumPy、Matplotlib、Pandas)。Pandas已经成为Python数据分析的必备高级工具,它的目标是成为强大、灵活、可以支持任何编程语言的数据分析工具......
  • scheduler,kube-controller-manager 报server returned HTTP status 401 Unauthorized
    现象:K8S组件报serverreturnedHTTPstatus401Unauthorized,看apiserver 日志有很多Unabletoauthenticatetherequest"err="[x509:certificatehasexpiredorisnotyet 1、分析:是因为集群证书更新了,然而使用kubectldeletepods方式去重启组件是没生效的,需要通过......
  • Android Failed to resolve: com.github.PhilJay:MPAndroidChart:v3.1.0
    2022.3.1版本修改settings.gradledependencyResolutionManagement{repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)repositories{maven{url"https://jitpack.io"}//Addthisrepositoryjcenter()//orotherrep......