指针神教几大高手码风分析

指针神教几大高手码风分析

时间线较乱, 比如 mycall 在年轻的时候使用的 id 为 wild_donkey.

根据高手闯出名声的时间顺序大概是 一扶苏一女士 然后 mycall 然后 3f 然后 young_tea, 但 一扶苏一女士 是 mycall 的学姐, mycall 是 3f 的引路人 (并非教练, 只是加入指针神教的引路人, 3f 和 young_tea 的教练都是 lxcool), 3f 是 young_tea 的亲哥.

由于不可抗力因素, 我们隐去了所有高手的性别信息, 不进行展示.

os / 编辑器 / 编译器

一扶苏一女士

windows 10.

vscode + mingw w64 (based on gcc-14).

mycall

windows 11.

vscode + mingw w64 (based on gcc-9).

3f

windows 11.

vscode + mingw w64 (based on gcc-15).

young_tea

macos, ubuntu 24.04.

xcode + gcc-14; vi + gcc-14.

语言标准

一扶苏一女士

c++ 20.

mycall

c++ 14.

3f

c++ 14 但更偏向 c 99.

young_tea

gnu++ 20.

缩进

一扶苏一女士

\(2\) 空格缩进.

mycall

\(2\) 空格缩进.

3f

\(2\) 空格缩进.

young_tea

tab 缩进, 长度 \(8\).

运算符

一扶苏一女士

运算符两边加空格.

mycall

运算符两边加空格.

3f

运算符两边无空格.

young_tea

运算符两边无空格.

内存管理

一扶苏一女士

new / 内存池, 并不 delete.

mycall

内存池.

3f

calloc 而不是 malloc, 严格 free.

young_tea

new, 严格 delete.

异常处理

算法竞赛严禁使用.

花括号

一扶苏一女士

左花括号在行尾, 右花括号单独占一行.

mycall

左花括号在行尾, 右花括号单独占一行.

3f

左花括号在行尾, 右花括号单独占一行.

young_tea

左花括号在行尾, 右花括号在行首, 右花括号后缩进然后直接写一行代码.

存图结构 (无权图和有权图大同小异)

一扶苏一女士

vector<int> e[maxn];

mycall

struct Edge;
struct Node {
  Edge *Fst;
} N[200005];
struct Edge {
  Edge *Nxt;
  Node *To;
} E[400005], *cnte(E);

3f

typedef struct _edge {
  int y; ll z; _edge *nxt;
} edge;

edge E[M]{}, *cnte(E), *e[N]{};

void addedge(int x, int y, ll z) {
  (++cnte)->nxt = e[x]; e[x] = cnte;
  cnte->y = y; cnte->z = z;
}

young_tea

class	vtx{
public:
	std::vector<vtx*>to;
	void add_edge(vtx*);
}	v[ver];
void	vtx::add_edge(vtx *y){
	to.emplace_back(y);
}

缺省源

一扶苏一女士

#include <bits/stdc++.h>

using ll = long long;

#ifdef ONLINE_JUDGE
#define freopen(a, b, c)
#endif

namespace IPT {
  const int L = 1000000;
  char buf[L], *front=buf, *end=buf;
  char GetChar() {
    if (front == end) {
      end = buf + fread(front = buf, 1, L, stdin);
      if (front == end) return -1;
    }
    return *(front++);
  }
}

template <typename T>
inline void qr(T &x) {
  char ch = IPT::GetChar(), lst = ' ';
  while ((ch > '9') || (ch < '0')) lst = ch, ch=IPT::GetChar();
  while ((ch >= '0') && (ch <= '9')) x = (x << 1) + (x << 3) + (ch ^ 48), ch = IPT::GetChar();
  if (lst == '-') x = -x;
}

namespace OPT {
  char buf[120];
}

template <typename T>
inline void qw(T x, const char aft, const bool pt) {
  if (x < 0) {x = -x, putchar('-');}
  int top=0;
  do {OPT::buf[++top] = static_cast<char>(x % 10 + '0');} while (x /= 10);
  while (top) putchar(OPT::buf[top--]);
  if (pt) putchar(aft);
}

mycall

#include <bits/stdc++.h>
#define Wild_Donkey 0
#define foreplay for
#define wild while
using namespace std;
inline unsigned RD() {
  unsigned intmp(0);
  char rdch(getchar());
  while (rdch < '0' || rdch > '9') rdch = getchar();
  while (rdch >= '0' && rdch <= '9')
    intmp = (intmp << 3) + (intmp << 1) + rdch - '0', rdch = getchar();
  return intmp;
}
inline int RDsg() {
  int rdtp(0), rdsg(1);
  char rdch(getchar());
  while ((rdch < '0' || rdch > '9') && (rdch != '-')) rdch = getchar();
  if (rdch == '-') rdsg = -1, rdch = getchar();
  while (rdch >= '0' && rdch <= '9')
    rdtp = (rdtp << 3) + (rdtp << 1) + rdch - '0', rdch = getchar();
  return rdtp * rdsg;
}
unsigned m, n;
unsigned A, B, C, D, t;
unsigned Cnt(0), Ans(0), Tmp(0);
signed main() {
  // freopen(".in", "r", stdin);
  // freopen(".out", "w", stdout);
  //  t = RD();
  //  for (unsigned T(1); T <= t; ++T){
  //  Clr();
  return Wild_Donkey;
}

3f

#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;

typedef long long ll;
typedef unsigned ui;
typedef unsigned long long ull;
typedef pair <int, int> pii;
typedef pair <int, ll> pil;
typedef pair <ll, int> pli;
typedef pair <ll, ll> pll;
#define pb emplace_back
#define pob pop_back
#define mp make_pair
#define ft first
#define sd second
#define bg begin
#define ed end

const ll
INF(0x3F3F3F3F3F3F3F3FLL),
Inf(0xC0C0C0C0C0C0C0C0LL),
Mod(998244353LL);
const int
N(1 << 18), M(1 << 19),
Q(1 << 18), LogN(18 + 1);

signed main() {
  // freopen(".in", "r", stdin);
  // freopen(".out", "w", stdout);
  return strcmp("3Fnb!", "3Fnb!");
}

young_tea

#include<bits/stdc++.h>
using namespace std::string_literals;
using lf=double;
using ll=std::ptrdiff_t;
using ull=std::size_t;
using us=unsigned;
constexpr ll inf=0x3f3f3f3f3f3f3f3fl;
constexpr ll mod=0x3b800001l;
namespace	yt{
template<class t>auto nxt(void)->t
{t x;std::cin>>x;return x;}
template<class t>void err(t x,bool _)
{std::cerr<<x;if(_)std::cerr<<" ak wf!\n"s;else std::cerr<<" "s;}
}
/*
prob link:	
start think:	
term think:	
start code:	
term code:	
*/
auto	main(void)->signed{
//	std::freopen(".in","r",stdin);
//	std::freopen(".out","w",stdout);
	std::ios::sync_with_stdio(0);
	std::cin.tie(nullptr);
	std::cout.tie(nullptr);
	ll _=1;
//	_=yt::nxt<ll>();
	while(_--)
		solve();
	return 0;
}

线段树

一扶苏一女士

struct Node {
  Node *ls, *rs;
  int l, r;
  ll val, tag;

  Node(int L, int R, const std::vector<ll> &a) : l(L), r(R), val(0), tag(0) {
    if (L != R) {
      int M = (L + R) >> 1;
      ls = new Node(L, M, a);
      rs = new Node(M + 1, R, a);
      pushup();
    } else {
      ls = rs = nullptr;
      val = a[L];
    }
  }

  inline bool inRange(int L, int R) { return L <= l && r <= R; }
  inline bool outRange(int L, int R) { return l > R || L > r; }
  inline void pushup() { val = ls->val + rs->val; }
  inline void pushdown() {
    if (tag) {
      ls->makeTag(tag);
      rs->makeTag(tag);
      tag = 0;
    }
  }
  inline void makeTag(ll k) {
    val += (r - l + 1) * k;
    tag += k;
  }

  void upd(int L, int R, ll k) {
    if (inRange(L, R)) {
      makeTag(k);
    } else if (!outRange(L, R)) {
      pushdown();
      ls->upd(L, R, k);
      rs->upd(L, R, k);
      pushup();
    }
  }
  
  ll qry(int L, int R) {
    if (inRange(L, R)) return val;
    if (outRange(L, R)) return 0;
    pushdown();
    // std::cerr << l << ' ' << r << val << '\n';
    return ls->qry(L, R) + rs->qry(L, R);
  }
};

mycall

struct SgNode {
  unsigned long long Val, Tag;
  SgNode *L, *R;
} SgN[400005], *cntn(SgN);
void Udt(SgNode *x) {
  x->Val = 0;
  if (x->L) {
    x->Val += x->L->Val;
  }
  if (x->R) {
    x->Val += x->R->Val;
  }
  return;
}
void SgBld(SgNode *x, const int &l, const int &r) {
  x->Tag = 0;
  if (l == r) {
    x->Val = a[l];
    x->L = x->R = NULL;
    return;
  }
  x->L = ++cntn;
  x->R = ++cntn;
  int mid((l + r) >> 1);
  SgBld(x->L, l, mid);
  SgBld(x->R, mid + 1, r);
  Udt(x);
  return;
}
inline bool Irg(const int &nl, const int &nr, const int &l, const int &r) {
  return nl >= l && nr <= r;
}
inline bool Org(const int &nl, const int &nr, const int &l, const int &r) {
  return nr < l || nl > r;
}
void PsDw(SgNode *x, const int &l, const int &r) {
  if (x->Tag) {
    if (l != r) {
      int mid((l + r) >> 1);
      x->L->Val += x->Tag * (mid - l + 1);
      x->R->Val += x->Tag * (r - mid);
      x->L->Tag += x->Tag;
      x->R->Tag += x->Tag;
    }
    x->Tag = 0;
  }
  return;
}
void SgChg(SgNode *x, const int &l, const int &r, const int &yl, const int &yr,
           const unsigned long long &yv) {
  // printf("SgChg %d %d %d %d\n", x - SgN, l, r, x->Val);
  if (Org(l, r, yl, yr)) {
    return;
  }
  if (l == r) {
    x->Val += yv;
    return;
  }
  if (Irg(l, r, yl, yr)) {
    x->Tag += yv;
    x->Val += (r - l + 1) * yv;
    x->Tag %= Mod;
    x->Val %= Mod;
    return;
  }
  int mid((l + r) >> 1);
  if (!x) {
    x = NULL;
  }
  PsDw(x, l, r);
  if (!x->L) {
    x->L = NULL;
  }
  SgChg(x->L, l, mid, yl, yr, yv);
  if (!x->R) {
    x->R = NULL;
  }
  SgChg(x->R, mid + 1, r, yl, yr, yv);
  Udt(x);
  return;
}
long long SgQry(SgNode *x, const int &l, const int &r, const int &yl,
                const int &yr) {
  if (Org(l, r, yl, yr)) {
    return 0;
  }
  if (Irg(l, r, yl, yr)) {
    return x->Val;
  }

  PsDw(x, l, r);
  int mid((l + r) >> 1);
  return (SgQry(x->L, l, mid, yl, yr) + SgQry(x->R, mid + 1, r, yl, yr)) % Mod;
}

3f

typedef struct _node{
	int ls,rs;
	ll val,tag;
}node;

int N,Q;
int rt,cntt;
node tr[NN<<2];
int x,y;
ll k;

void push_up(int p){
	tr[p].val=tr[tr[p].ls].val+tr[tr[p].rs].val;
}

void push_down(int p,int l,int r){
	if(tr[p].tag==0LL){
		return;
	}
	int m=l+r>>1;
	if(tr[p].ls==0){
		tr[p].ls=++cntt;
	}
	if(tr[p].rs==0){
		tr[p].rs=++cntt;
	}
	tr[tr[p].ls].val+=tr[p].tag*(m-l+1);
	tr[tr[p].ls].tag+=tr[p].tag;
	tr[tr[p].rs].val+=tr[p].tag*(r-m);
	tr[tr[p].rs].tag+=tr[p].tag;
	tr[p].tag=0LL;
}

void update(int *p,int l,int r){
	if(*p==0){
		*p=++cntt;
	}
	if(x<=l&&r<=y){
		tr[*p].val+=k*(r-l+1);
		tr[*p].tag+=k;
		return;
	}
	int m=l+r>>1;
	push_down(*p,l,r);
	if(x<=m){
		update(&tr[*p].ls,l,m);
	}
	if(m<y){
		update(&tr[*p].rs,m+1,r);
	}
	push_up(*p);
}

void query(int p,int l,int r){
	if(p==0){
		return;
	}
	if(x<=l&&r<=y){
		k+=tr[p].val;
		return;
	}
	int m=l+r>>1;
	push_down(p,l,r);
	if(x<=m){
		query(tr[p].ls,l,m);
	}
	if(m<y){
		query(tr[p].rs,m+1,r);
	}
}

young_tea

class	tree{
	tree *ld,*rd;
	ll f,g,v,t;
public:
	void push_up(void);
	void push_down(void);
	tree(ll,ll,ll*);
	~tree(void);
	void update(ll,ll,ll);
	auto query(ll,ll,ll)->ll;
};
void	tree::push_up(void){
	v=ld->v+rd->v;
}
void	tree::push_down(void){
	if(t==0)
		return;
	ld->t+=t,rd->t+=t;
	ld->v+=t*(ld->g-ld->f+1);
	rd->v+=t*(rd->g-rd->f+1);
	t=0;
}
tree::tree(ll p,ll q,ll *a){
	f=p,g=q,v=t=0;
	if(f==g){
		v=a!=nullptr?a[f]:0;
		return;
	}	ld=new tree(f,f+g>>1,a);
	rd=new tree((f+g>>1)+1,g,a);
	push_up();
}
tree::~tree(void){
	if(ld!=nullptr)
		delete ld,
		ld=nullptr;
	if(rd!=nullptr)
		delete rd,
		rd=nullptr;
}
void	tree::update(ll p,ll q,ll k){
	if(p<=f&&g<=q){
		t+=k;
		v+=k*(g-f+1);
		return;
	}	push_down();
	if(p<=ld->g)
		ld->update(p,q,k);
	if(rd->f<=q)
		rd->update(p,q,k);
	push_up();
}
auto	tree::query(ll p,ll q,ll yy=0)->ll{
	if(p<=f&&g<=q)
		return v+yy*(g-f+1);
	ll ct=0;
	if(p<=ld->g)
		ct+=ld->query(p,q,yy+t);
	if(rd->f<=q)
		ct+=rd->query(p,q,yy+t);
	return ct;
}

指针哲学 (由 young_tea 总结, 不实之处请提出)

一扶苏一女士

管理数据结构, 但并不用于管理图.

mycall

离谱的指针.

3f

我哥的指针哲学就是个 dick, 用指针当成引用, 举例就是刚才那个该死的线段树.

young_tea

我用指针管理数据结构和图的顶点, 莫队也是适合使用指针维护区间, 因为莫队可以说是一种双指针.

posted @ 2025-12-28 12:34  young_tea  阅读(28)  评论(0)    收藏  举报