正文
增加 168 行删除 10 行
4 行未改动56789101112131415161718192021222324252627283 行未改动323334353637383940414243444546474846 行未改动9596979899100101102186 行未改动全部展开2892902912922932942952962977 行未改动30530630730830931031131248 行未改动361362363364365366367368369112 行未改动全部展开48248348448548648748848932 行未改动522523524525526527528529530817 行未改动全部展开4 行未改动~~非全部原创(可能也没有原创)~~~~别问为什么zsyun_Cg这么懒~~目前26模板,持续更新中,可借走模板,但不许说是自己的## 模板集::::success[代码框架]```cpp#include<bits/stdc++.h>#define ll long longusing namespace std;const int N=1e5+10,M=1e3+10;int main(){//freopen(".in","r",stdin);//freopen(".out","w",stdout);//ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);return 0;}```3 行未改动```cpp#include<bits/stdc++.h>#define ll long longusing namespace std;const int N=1e5+10,M=1e3+10;const int MOD_1=998244353,MOD_2=1e9+7,MOD_3=1e9+9;const int INV2_1=499122177,INV2_2=500000004,INV2_3=500000005;int main(){//freopen(".in","r",stdin);//freopen(".out","w",stdout);ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);return 0;}```46 行未改动:::::::::::success[背包DP]:::success[01背包]186 行未改动全部展开```cpp//建队//初始化//入队第一个元素//while循环知道队列为空//判断//更新//入队```7 行未改动模板在下面快速幂里a/b%MOD=a*(b在模MOD下的逆元)%MOD::::::::success[快速幂]48 行未改动}ll inv(ll a,ll mod){//快速幂求逆元return qpow(a,mod-2,mod);}ll zuhe(ll n,ll m,ll mod){/组合数if(m>n){return 0;}ll num=1,den=1;112 行未改动全部展开}```::::::::success[并查集]```cppint fa[200005],h[200005];32 行未改动}```::::::::success[链世前向星]```cpp#include<bits/stdc++.h>#define ll long long817 行未改动全部展开4 行未改动56789101112131415161718192021222324252627283 行未改动32333435363738394041424344454647484950515253545556575859606162636446 行未改动111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181186 行未改动全部展开3683693703713723733743753767 行未改动38438538638738838939039139239348 行未改动442443444445446447448449450112 行未改动全部展开56356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664732 行未改动680681682683684685686687688817 行未改动全部展开4 行未改动~~非全部原创(可能也没有原创)~~~~别问为什么zsyun_Cg这么懒~~目前29模板,持续更新中,可借走模板,但不许说是自己的## 模板集::::success[代码框架]```cpp#include<bits/stdc++.h>#define ll long longusing namespace std;const int N=1e6+10,M=1e3+10;int main(){//ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);//freopen(".in","r",stdin);//freopen(".out","w",stdout);return 0;}```3 行未改动```cpp#include<bits/stdc++.h>#define ll long long#define endl '\n'using namespace std;const int N=1e6+10,M=1e3+10;const int MOD_1=998244353,MOD_2=1000000000+7,MOD_3=1000000000+9;const int INV2_1=499122177,INV2_2=500000004,INV2_3=500000005;bool ctrl_debug(int fin){static bool f=1;if(fin==3) return f;else f=bool(fin);return 1;}//控制debug,1为输出,0为不输出template<typename T>void debug(T a){if(ctrl_debug(3)){cout<<"debug: "<<a<<'\n';//↓本地不报错,评测机报错//system("pause");}return;}int main(){ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);//freopen(".in","r",stdin);//freopen(".out","w",stdout);ctrl_debug(1);return 0;}```46 行未改动:::::::::::success[对拍]:::success[随机数生成器]```cpp#include<bits/stdc++.h>#define ll long longusing namespace std;const int N=1e6+10,M=1e3+10;int main(){ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);//freopen(".in","r",stdin);//freopen(".out","w",stdout);srand(time(0));cout<<rand()%100<<" "<<rand()%100<<"\n";//输出两个100以内的随机数return 0;}```* 先在前面调用`srand(time(0));`* 然后用`rand()%n`生成随机数,n-1为最大值::::::success[对拍器]```cpp#include<bits/stdc++.h>#define ll long longusing namespace std;const int N=1e6+10,M=1e3+10;int main(){ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);//freopen(".in","r",stdin);//freopen(".out","w",stdout);ll t=0;while(1){cout<<"test: "<<t++<<"\n";system("随机数生成器.exe > data.in");system("暴力代码.exe < data.in > std.out");system("待测代码.exe < data.in > ab.out");if(system("fc std.out ab.out > diff.log")){cout<<"WA\n";break;}cout<<"AC\n";}return 0;}```* 代码中所有 `.exe`均为`.cpp`文件编译产生的可执行文件* 四个`.cpp`须在同一目录下* 运行对拍器会生成4个文件,两`.out`文件为两个程序的输出,`.in`为本组随机样例,`diff`文件为两个`.out`的集合:::[例示](https://www.luogu.com.cn/problem/U746695)::::::::success[背包DP]:::success[01背包]186 行未改动全部展开```cpp//建队//初始化//入队第一个元素//while循环直到队列为空//判断//更新//入队```7 行未改动模板在下面快速幂里a/b%MOD=a*(b在模MOD下的逆元)%MOD相当于在整除+取模意义下的倒数(主要与正常倒数区分)::::::::success[快速幂]48 行未改动}ll inv(ll a,ll mod){//快速幂求逆元return qpow(a,mod-2,mod);}ll zuhe(ll n,ll m,ll mod){//组合数if(m>n){return 0;}ll num=1,den=1;112 行未改动全部展开}```::::::::success[LIS最长上升子序列]```cpp#include<bits/stdc++.h>#define ll long longusing namespace std;const int N=5e3+10,M=1e3+10;int n,a[N],dp[N],ma=INT_MIN;//dp[i]为LIS长度为i时结尾的最小值bool cheak(int mid,int x){return mid>=x;}int main(){//freopen(".in","r",stdin);//freopen(".out","w",stdout);ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);cin>>n;for(int i=1;i<=n;i++){cin>>a[i];}for(int i=1;i<=n;i++){dp[i]=INT_MAX;}for(int i=1;i<=n;i++){int l=1,r=n,mid=0;while(l<=r){//二分找到最优的修改位置mid=(l+r)>>1;if(cheak(dp[mid],a[i])==1){r=mid-1;}else{l=mid+1;}}ma=max(ma,l);dp[l]=min(a[i],dp[l]);for(int j=1;j<=n;j++){//cout<<dp[j]<<" ";}//cout<<"\n"<<i<<" "<<l<<"\n";}cout<<ma;return 0;}```::::::::success[最大子段和]太简单,不做介绍```cpp#include<bits/stdc++.h>#define ll long longusing namespace std;const int N=1e6+10,M=1e3+10;ll n,sum=0,ma=INT_MIN;int main(){//freopen(".in","r",stdin);//freopen(".out","w",stdout);ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);cin>>n;for(int i=1,x;i<=n;i++){cin>>x;sum+=x;ma=max(ma,sum);if(sum<=0){sum=0;}}cout<<ma;return 0;}```::::::::success[并查集]```cppint fa[200005],h[200005];32 行未改动}```::::::::success[链式前向星]```cpp#include<bits/stdc++.h>#define ll long long817 行未改动全部展开