
ACM手写模板
自己在练习中写的常用模板
Tenshi0x0
有顶天
展开
-
【数据结构】LCT
为了方便自己阅读,将部分代码贴到 优快云 上。模板题#include<bits/stdc++.h>using namespace std;inline void read(int &x) { int s=0;x=1; char ch=getchar(); while(ch<'0'||ch>'9') {if(ch=='-')x=-1;ch=getchar();} while(ch>='0'&&ch<='9'原创 2021-11-25 00:33:59 · 627 阅读 · 0 评论 -
Splay 板子
#include<iostream>#include<cstdio>#include<cstring>#include<algorithm>using namespace std;const int INF=0x3f3f3f3f;inline int read(){ int s=0,w=1; char ch=getchar(); while(ch<'0'||ch>'9'){if(ch=='-')w=-1;ch=ge原创 2021-04-05 19:26:18 · 108 阅读 · 0 评论 -
归并排序板子
#include<iostream>using namespace std;const int N=1e5+5;int a[N], tmp[N];void merge_sort(int a[],int l,int r){ if(l>=r) return; // the length of the range no more than 1, then return int mid=l+r>>1; merge_sort(a,l,mid), merge_sort(a原创 2021-04-05 19:25:32 · 104 阅读 · 0 评论 -
LCA板子
#include<bits/stdc++.h>using namespace std;const int N=5e5+5, M=20;inline int read(){ int s=0,w=1; char ch=getchar(); while(ch<'0'||ch>'9'){if(ch=='-')w=-1;ch=getchar();} while(ch>='0'&&ch<='9') s=s*10+ch-'0',ch=原创 2021-03-04 21:45:55 · 276 阅读 · 1 评论 -
实现求前n个数素数的个数以及得到相应的素数表
#pragma GCC optimize("O3")#include<bits/stdc++.h>using namespace std;#define SET0(a) memset(a,0,sizeof(a))#define FOR(i,a,b) for(int i=(a);i<=(b);i++)#define DWN(i,a,b) for(int i=(a);i>=(b);i--)#define INF 0x3f3f3f3ftypedef long long ll.原创 2021-01-08 17:04:30 · 263 阅读 · 0 评论 -
实现素性测试、整数分解、约数枚举
#pragma GCC optimize("O3")#include<bits/stdc++.h>using namespace std;#define SET0(a) memset(a,0,sizeof(a))#define FOR(i,a,b) for(int i=(a);i<=(b);i++)#define DWN(i,a,b) for(int i=(a);i>=(b);i--)#define INF 0x3f3f3f3ftypedef long long ll.原创 2021-01-08 16:53:39 · 109 阅读 · 0 评论 -
【ACM模板】手写栈、队列
手写栈const int N = 2e5 + 5;struct Stack{ int a[N]; int tot = 0; void push(int x) { a[tot++] = x; } int pop() { int ret = a[tot - 1]; a[--tot] = 0; return ret; } int size() {原创 2021-01-08 11:32:33 · 155 阅读 · 0 评论 -
【ACM模板】快速幂
ll fpow(ll x,ll p){ ll res=1; for(;p;p>>=1,x=x*x%mod) if(p&1)res=res*x%mod; return res%mod;}原创 2020-10-18 21:06:56 · 116 阅读 · 0 评论 -
【ACM模板】exgcd
int x,y;void exgcd(int a,int b){ if(b==0) {x=1,y=0;return;} exgcd(b,a%b); int temp=x; x=y; y=temp-a/b*y;}原创 2020-12-05 16:42:44 · 107 阅读 · 0 评论 -
【ACM模板】gcd
int gcd(int a,int b){ if(b==0) return a; return gcd(b,a%b);}原创 2020-12-05 16:13:38 · 127 阅读 · 0 评论 -
【ACM模板】链式前向星 存图 枚举每个结点连接的点 dfs bfs
//链式前向星 存图 枚举每个结点连接的点 dfs //四个结点的有向完全图(例子)#pragma GCC optimize("O3")#include<bits/stdc++.h>using namespace std;#define SET0(a) memset(a,0,sizeof(a))#define FOR(i,a,b) for(int i=(a);i<=(b);i++)#define DWN(i,a,b) for(int i=(a);i>=(b);i--).原创 2020-12-04 11:35:14 · 120 阅读 · 0 评论