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

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

时间线较乱, 比如 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 89.

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;

#define f1(var, lt, gt, add) for (int var = lt; var <= gt; var += add)
#define f2(var, gt, lt, add) for (int var = gt; var >= lt; var -= add)
#define ll long long
#define us unsigned
#define real double
#define endl "\n"
#define pii pair <int, int>
#define pil pair <int, ll>
#define pli pair <ll, int>
#define pll pair <ll, ll>
#define pb emplace_back
#define pob pop_back
#define mp make_pair
#define ft first
#define sd second
#define bg begin
#define ed end
#define INF 0x3F3F3F3F3F3F3F3FLL
#define Inf 0x3F3F3F3F
#define Mod 998244353
#define N 200001
#define M N*2

template
<typename T>
void read(T *x) {
  char f = 1, ch;
  *x = 0;
  ch = getchar();
  while (ch < '0' || '9' < ch) {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while ('0' <= ch && ch <= '9') {
    *x = (*x << 3) + (*x << 1) + (ch - '0');
    ch = getchar();
  }
  *x *= f;
  return;
}

template
<typename T, typename... Ts>
void read(T *x, Ts *...y) {
  read(x);
  read(y...);
  return;
}

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;
auto nxt(void){ll x;std::cin>>x;return x;}
/*
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;
//	_=nxt();
	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

#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;
auto nxt(void){ll x;std::cin>>x;return x;}
#ifndef	tea_h
#define	tea_h
#include<bits/stdc++.h>
namespace yt{
template<class ty>
class tea{
	ty *x;
public:
	tea(void);
	tea(tea&)=delete;
	tea(const tea&)=delete;
	tea(tea&&);
	tea(ty);
	template<class...args>
	tea(args&&...);
	~tea(void);
	auto operator=(tea&)=delete;
	auto operator=(const tea&)=delete;
	auto operator=(tea&&);
	void push(ty);
	template<class...args>
	void emplace(args&&...);
	void pop(void);
	auto empty(void);
	auto is_valid(void);
	auto operator->(void);
};
template<class ty>
tea<ty>::tea(void){
	x=nullptr;
}
template<class ty>
tea<ty>::tea(tea &&y){
	x=y.x;
	y.x=nullptr;
}
template<class ty>
tea<ty>::tea(ty arg){
	x=new ty(arg);
}
template<class ty>
template<class...args>
tea<ty>::tea(args&&...arg){
	x=new ty(std::forward<args>(arg)...);
}
template<class ty>
tea<ty>::~tea(void){
	pop();
}
template<class ty>
auto	tea<ty>::operator=(tea &&y){
	if(this==&y)
		return is_valid();
	pop();
	x=y.x;
	y.x=nullptr;
	return is_valid();
}
template<class ty>
void	tea<ty>::push(ty arg){
	pop();
	x=new ty(arg);
}
template<class ty>
template<class...args>
void	tea<ty>::emplace(args&&...arg){
	pop();
	x=new ty(std::forward<args>(arg)...);
}
template<class ty>
void	tea<ty>::pop(void){
	if(x==nullptr)
		return;
	delete x;
	x=nullptr;
}
template<class ty>
auto	tea<ty>::empty(void){
	return x==nullptr;
}
template<class ty>
auto	tea<ty>::is_valid(void){
	return x!=nullptr;
}
template<class ty>
auto	tea<ty>::operator->(void){
	return x;
}
}
#endif
/*
prob link:	https://vjudge.net/problem/%E6%B4%9B%E8%B0%B7-P13825
start think:	
term think:	
start code:	
term code:	
*/
class	tree{
	yt::tea<tree>ld,rd;
	ll f,g;
	ull v,t;
public:
	tree(ll,ll);
	void push_up(void);
	void push_down(void);
	void update(ll,ll,ull);
	auto query(ll,ll,ull);
};
tree::tree(ll p,ll q){
	f=p,g=q;
	v=(p+q)*(q-p+1)>>1,t=0;
}
void	tree::push_up(void){
	v=ld->v+rd->v;
}
void	tree::push_down(void){
	if(ld.empty())
		ld.emplace(f,f+g>>1);
	if(rd.empty())
		rd.emplace((f+g>>1)+1,g);
	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;
}
void	tree::update(ll p,ll q,ull 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,ull yy){
	if(p<=f&&g<=q)
		return v+yy*(g-f+1);
	push_down();
	ull 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;
}
void	solve(void){
	ll n=nxt(),q=nxt();
	yt::tea<tree>rt(1,n);
	while(q--){
		ll op=nxt();
		if(op==1){
			ll x=nxt(),y=nxt();
			ull z=nxt();
			rt->update(x,y,z);
		}else	if(op==2){
			ll x=nxt(),y=nxt();
			std::cout<<rt->query(x,y,0)<<"\n"s;
		}else	std::cerr<<"i ak wf!\n"s;
	}	rt.pop();
}
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;
//	_=nxt();
	while(_--)
		solve();
	return 0;
}

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

一扶苏一女士

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

mycall

离谱的指针.

3f

c 89 的统治比中世纪更加黑暗, 指针和引用的界限被模糊离散.

本该使用 int &p 的地方却使用了 int *p, 我的评价是傻逼.

young_tea

用智能指针管理数据结构, 用裸指针管理图论, 莫队也是适合使用指针维护区间, 因为莫队可以说是一种双指针.

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