跳到正文

个人记录

Tenderfoot's Coding Style

Tenderfoot约 12 分钟
原文
文章信息与版本

文章信息

发布
2021年9月9日
收录
2026年4月25日
更新
2026年11月16日
篇幅
约 12 分钟

版本

  1. v2当前
  2. v1
  1. 经常使用万能头文件 #include <bits/stdc++.h>(绝对不是好习惯)

  2. 经常使用标准命名空间 using namespace std(绝对不是好习惯)

  3. 经常 #define int long long(绝对不是好习惯)

  4. 经常使用快读快写

  5. 使用 AllmanAllman 风格,即左大括号换行

  6. 不吝啬地使用空格和换行

  7. 声明函数之前经常使用 static inline 等关键字

  8. 变量名除 idid 以外首字母均大写,多个单词命名时使用下划线连接且首字母大写,例如 Quick_Power、Add_Edge

  9. 除函数命名之外,如果变量或数组名字长度 ⩾4\geqslant 4,那么根据音节来缩写成三个字母,如 Bucket→Bkt,Father→FtrBucket\rightarrow Bkt,Father\rightarrow Ftr,除特殊且常用的变量如 Right,StartRight,Start 不缩写,Middle→Mid,Answer→AnsMiddle\rightarrow Mid,Answer\rightarrow Ans。树的数据结构常命名为 TT(即 TreeTree 缩写),图经常命名为 GG(即 GraphGraph 缩写),其它则按心情命名之

  10. 函数或变量命名重复时,在其前面加下划线以作区分

  11. 经常把数组开的过大(绝对不是好习惯)

  12. 需要用 pair 时经常用结构体来代替之

  13. 有时根据心情将数据结构或图上(树上)或一些奇怪的东西操作封装在类里或写在 namespace 里

  14. 不压行,需要换行时即换行 +Tab+Tab,大概可以做到每行长度不超过 8080 列

  15. 主函数写在 namespace 里

样例代码

C++
#include <bits/stdc++.h>

#define MAXN 10000010
#define Enter puts("")
#define Space putchar(' ')
#define int long long
#define lint __int128
#define Test puts("This is a Test")
#define Test_Begin Enter , puts("Test----------")
#define Test_End Enter , puts("-------------")

static constexpr const int INF(INT_MAX);
static constexpr const int Mod(1e9 + 7);

namespace IO
{
    static inline int const Read()
    {
        int Ans(0);
        char Ch = getchar() , Las = ' ';

        while(!isdigit(Ch))
        {
            if(Ch == '-')
                Las = Ch;

            Ch = getchar();
        }
        while(isdigit(Ch))
        {
            Ans = Ans * 10 + Ch - '0';
            Ch = getchar();
        }

        if(Las == '-')
            Ans = -Ans;

        return Ans;
    }

    template <typename T> static inline void const Write(T x)
    {
        if(x < 0)
            putchar('-') , x = -x;
        if(x >= 10)
            Write(x / 10);

        putchar(x % 10 + '0');
    }
}

using namespace IO;
using namespace std;

namespace Main
{

    namespace FILE
    {
        static inline void const FILE()
        {
            freopen("1.in" , "r" , stdin);
            freopen("reverse.out" , "w" , stdout);
        }
    }

    static int n , k;
    static int a[MAXN << 1];
    static char S[MAXN << 1];

    namespace Treap
    {
        struct Treap
        {
            int Val , Left_Son , Right_Son , Size , Key , Flip;
        };

        static Treap T[MAXN << 1];
        static int Num , Root , Cnt;
        static int V[MAXN << 1];

        static inline void const Push_Down(int x)
        {
            if(!T[x].Flip)
                return;

            T[T[x].Left_Son].Flip = !T[T[x].Left_Son].Flip;
            T[T[x].Right_Son].Flip = !T[T[x].Right_Son].Flip;
            T[x].Flip = 0;
            swap(T[x].Left_Son , T[x].Right_Son);
        }

        static inline void const Push_Up(int x)
        {
            T[x].Size = T[T[x].Left_Son].Size + T[T[x].Right_Son].Size + 1;
        }

        static inline int const Merge(int a , int b)
        {
            if(!a or !b)
                return a + b;

            if(T[a].Key < T[b].Key)
            {
                Push_Down(a);
                T[a].Right_Son = Merge(T[a].Right_Son , b);
                Push_Up(a);
                return a;
            }
            else
            {
                Push_Down(b);
                T[b].Left_Son = Merge(a , T[b].Left_Son);
                Push_Up(b);
                return b;
            }
        }

        static inline pair <int , int> Split(int a , int k)
        {
            pair <int , int> Temp;

            if(k == 0)
                return make_pair(0 , a);

            Push_Down(a);
            int Left_Son(T[a].Left_Son) , Right_Son(T[a].Right_Son);

            if(k == T[Left_Son].Size)
            {
                T[a].Left_Son = 0;
                Push_Up(a);
                return make_pair(Left_Son , a);
            }
            if(k == T[Left_Son].Size + 1)
            {
                T[a].Right_Son = 0;
                Push_Up(a);
                return make_pair(a , Right_Son);
            }
            if(k < T[Left_Son].Size)
            {
                Temp = Split(Left_Son , k);
                T[a].Left_Son = Temp.second;
                Push_Up(a);
                return make_pair(Temp.first , a);
            }
            if(k > T[Left_Son].Size + 1)
            {
                Temp = Split(Right_Son , k - T[Left_Son].Size - 1);
                T[a].Right_Son = Temp.first;
                Push_Up(a);
                return make_pair(a , Temp.second);
            }
        }

        static inline void const DFS(int x)
        {
            if(x == 0)
                return;

            if(T[x].Flip)
                Push_Down(x);

            DFS(T[x].Left_Son);
            V[++Cnt] = x;//cout << "Test: " << x << endl;
            DFS(T[x].Right_Son);
        }

        static inline void const Insert(int &Now , int x)
        {
            T[++Num].Val = x;
            T[Num].Key = rand();
            T[Num].Size = 1;
            Now = Merge(Now , Num);
        }
    }

    using namespace Treap;

    static inline signed const Main()
    {
        FILE :: FILE();
        n = Read() , k = Read();
        scanf("%s" , S + 1);

        for(int i(1); i <= n; i++)
            a[i] = S[i] - 'a' , Insert(Root , a[i]);

        // for(int i(1); i <= n; i++)
        //     Write(a[i]) , Space;
        //cout << Root << endl;
        while(k--)
        {
            // cout << Root << endl;
            int l(1) , r = Read();
            pair <int , int> Temp1 = Split(Root , l - 1);
            pair <int , int> Temp2 = Split(Temp1.second , r - l + 1);
            T[Temp2.first].Flip ^= 1;
            Root = Merge(Temp1.first , Temp2.first);
            Root = Merge(Root , Temp2.second);
            //
        }

        DFS(Root);
        // cout << Root;
        // for(int i(1); i <= Cnt; i++)
        //     Write(V[i]) , Space;

        for(int i(1); i <= Cnt; i++)
            printf("%c " , V[i] - 1 + 'a');
        Enter;

        return 0;

    }

}

signed main()
{
    return Main :: Main();
}

估计是最有辨识度的码了

原文