正文
增加 155 行删除 10 行
12345218 行未改动全部展开224225226227228229230231771 行未改动全部展开100310041005100610071008100910101011897 行未改动全部展开190919101911191219131914191519161917244 行未改动全部展开21622163216421652166216721682169217093 行未改动2264226522662267226822692270227140 行未改动231223132314231523162317231823192320232123222323232423252326232752 行未改动2380238123822383238423852386238723883 行未改动239223932394239523962397239823992400240152 行未改动245424552456245724582459246024612462450 行未改动全部展开# DATA STRUCTURE## 单调队列有些 dp 题要算 dp[i],注意单调性维护位置```cpp#include<bits/stdc++.h>218 行未改动全部展开```## 线段树### 微缩版(带 mod)```cpp/*1 区间每个元素加上 k771 行未改动全部展开```# GRAPH THEORY & TREE## LCA```cpp#include <bits/stdc++.h>using namespace std;897 行未改动全部展开```# STRING## KMP```cpp#include <bits/stdc++.h>using namespace std;244 行未改动全部展开return 0;}```# 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;}```***```cppc[0][0]=1;for(int i=1;i<=N;i++){3 行未改动c[i][j]=(c[i-1][j]+c[i-1][j-1])%mod;}}```## 卡特兰数```cppprintf("%d",c[2*n][n]-c[2*n][n-1]);```52 行未改动if(n==1) return ans;else return ans=ans/n*(n-1);}```# 杂项## 表达式求值支持 + - * / ^,正确的括号匹配。```cpp#include <bits/stdc++.h>450 行未改动全部展开12345218 行未改动全部展开224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366771 行未改动全部展开113811391140114111421143114411451146897 行未改动全部展开204420452046204720482049205020512052244 行未改动全部展开22972298229923002301230223032304230593 行未改动23992400240124022403240424052406240740 行未改动24482449245024512452245324542455245624572458245952 行未改动2512251325142515251625172518251925203 行未改动2524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254652 行未改动259926002601260226032604260526062607450 行未改动全部展开# 【数据结构 / 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 secondconst 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】## LCA```cpp#include <bits/stdc++.h>using namespace std;897 行未改动全部展开```# 【字符串 / String】## KMP```cpp#include <bits/stdc++.h>using namespace std;244 行未改动全部展开return 0;}```# 【数学 / 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;}```### 杨辉三角```cppc[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;}```## 卡特兰数```cppprintf("%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 行未改动全部展开