版本比较
【板子】
正文
增加 155 行删除 10 行
112345218 行未改动全部展开224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366771 行未改动全部展开1138113911401141100711421143114411451146897 行未改动全部展开2044204520462047191320482049205020512052244 行未改动全部展开229722982299230021662301230223032304230593 行未改动23992400240124022403240424052406240740 行未改动244824492450245123162452245324542455232123222323245624572458245952 行未改动25122513251425152384251625172518251925203 行未改动2524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254652 行未改动2599260026012602245826032604260526062607450 行未改动全部展开# DATA STRUCTURE# 【数据结构 / Data Structure】## 单调队列有些 dp 题要算 dp[i],注意单调性维护位置```cpp#include<bits/stdc++.h>218 行未改动全部展开
```
## 线段树### 清新版```cpp/*1 区间每个元素加上 k2 区间每个元素乘上 k4 输出区间和MADE BY SKYx*/
#include <bits/stdc++.h>using namespace std;#define ll long long// int->ll may useful#define db double#define pii pair<int,int>#define mp make_pair#define fi first#define se second
const int N=1e5+5;int n, q, x, y, k;struct node{ int l,r; int s,add,mul;
} tr[N<<2];
void build(int c,int l,int r){ auto &t=tr[c]; t.l=l; t.r=r; t.add=t.s=0; t.mul=1; if(l==r) { cin>>t.s; return; } int mid=(l+r)/2; build(c*2,l,mid); build(c*2+1,mid+1,r); t.s=(tr[c*2].s+tr[c*2+1].s); }
void pushdown(int c){ auto &t=tr[c]; if(t.mul!=1 || t.add!=0) { for(int i=0; i<2; i++) { auto &u=tr[c*2+i]; u.s=(u.s*t.mul+t.add*(u.r-u.l+1)); u.mul=u.mul*t.mul; u.add=(u.add*t.mul+t.add); } t.mul=1; t.add=0; }}void update(int c, int L, int R, int type, int v){ auto &t=tr[c]; if(R<t.l || t.r<L) return; if(L<=t.l && t.r<=R) { if (type==1) { t.s=(t.s+v*(t.r-t.l+1)); t.add=(t.add+v); } if (type==2) { t.s=t.s*v; t.mul=t.mul*v; t.add=t.add*v; } return; } pushdown(c); update(c*2,L,R,type,v); update(c*2+1,L,R,type,v); tr[c].s=(tr[c*2].s+tr[c*2+1].s);}
int query(int c, int L, int R){ auto &t=tr[c]; if(R<t.l || t.r<L) return 0; if(L<=t.l && t.r<=R) return t.s; pushdown(c); return (query(c*2,L,R)+query(c*2+1,L,R));}
signed main(){ ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin>>n>>q; build(1,1,n);
while (q--) { int op; cin>>op; if (op == 1) { cin>>x>>y>>k; update(1,x,y,1,k); } if (op == 2) { cin>>x>>y>>k; update(1,x,y,2,k); } if (op == 4) { cin>>x>>y; cout<<query(1,x,y)<<'\n'; } } return 0;}/*
*/```
### 微缩版(带 mod)```cpp/*1 区间每个元素加上 k771 行未改动全部展开
```
# GRAPH THEORY & TREE# 【图论树论 / Graph Theory & Tree】## LCA```cpp#include <bits/stdc++.h>using namespace std;897 行未改动全部展开
```
# STRING# 【字符串 / String】## KMP```cpp#include <bits/stdc++.h>using namespace std;244 行未改动全部展开 return 0;}```
# MATH# 【数学 / Math】## 算术基本定理(唯一分解定理)```cpp#include <bits/stdc++.h>using namespace std;93 行未改动
$C(a, b) = \dfrac{a!}{b! (a-b)!} $
$P(a, b) = \dfrac{a!}{(a-b)!}$### 逆元与阶乘```cpp#include <bits/stdc++.h>using namespace std;#define int long long40 行未改动 for(int i=N-11;i>=1;i--) { inv[i]=inv[i+1]*(i+1)%mod; }
// cerr<<1.0*(clock()-sti)/CLOCKS_PER_SEC<<endl; return 0;}
```
```cpp#include <bits/stdc++.h>52 行未改动 cout<<p(x,y)<<endl; return 0;}```***### 杨辉三角```cpp c[0][0]=1; for(int i=1;i<=N;i++) {3 行未改动 c[i][j]=(c[i-1][j]+c[i-1][j-1])%mod; } }```### 暴力展开```cppint C(int n,int k){ int res=1;
for(int i=1;i<=k;i++) { res=res*(n-k+i)/i; } return res;}```
## 卡特兰数```cpp printf("%d",c[2*n][n]-c[2*n][n-1]);```52 行未改动 if(n==1) return ans; else return ans=ans/n*(n-1);}```# 杂项# 【杂项 / Others】## 表达式求值支持 + - * / ^,正确的括号匹配。```cpp#include <bits/stdc++.h>450 行未改动全部展开