版本比较
【板子】
标题
增加 1 行删除 1 行
11猎奇-板子【板子】正文
增加 301 行删除 32 行
1234567721 行未改动全部展开7297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058061,090 行未改动全部展开1897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196427 行未改动19921993199419951996199719981999200020012002137 行未改动全部展开21402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812 行未改动228422852286228720212288228922902291229220262293229420282295229622972298229920332300230120352302230320372304230523062307230823092310231123122313204723142315204920502051205223162317231823192320232123222323206123242325232623272328232923302331233223332334233523362337233823392340234123422066206720682343234423452346207020712072234723482349235020742351235223532077207820792080208120822083208420852354235523562357208720882089235823592360236117 行未改动23792380238123822383238423852386238731 行未改动2419242024212422215424232424242524262427179 行未改动全部展开# DATA STRUCTURE## 单调队列有些 dp 题要算 dp[i],注意单调性维护位置```cpp#include<bits/stdc++.h>#define ll long long#define int long long721 行未改动全部展开 return 0;}
```## 离线二维数点
```cpp#include <bits/stdc++.h>using namespace std;#define ll long long#define db double#define pii pair<int,int>#define mp make_pair#define fi first#define se secondconst int N=2e6+10;const int M=2e6+10;struct node{ int x,id,val;};vector<node> v[N];int ans[M],a[N];int n,m;int cnt[N];
void add(int x){ for(;x<=N-5;x+=x&-x) cnt[x]++;}int ask(int x){ int ans=0; for(;x;x-=x&-x) ans+=cnt[x]; return ans; // ask 获得的是一个区间和 }
int main(){ ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin>>n>>m; for(int i=1;i<=n;i++) { cin>>a[i]; } for(int i=1;i<=m;i++) { int l,r,x; cin>>l>>r>>x; v[l-1].push_back({x,i,-1}); v[r].push_back({x,i,1}); } for(int i=1;i<=n;i++) { add(a[i]); for(int j=0;j<v[i].size();j++) { ans[v[i][j].id]+=v[i][j].val*ask(v[i][j].x); } } for(int i=1;i<=m;i++) { cout<<ans[i]<<endl; }
return 0;}
```
# GRAPH THEORY & TREE## LCA```cpp#include <bits/stdc++.h>1,090 行未改动全部展开}```
# MATH## 算术基本定理(唯一分解定理)```cpp#include <bits/stdc++.h>using namespace std;#define int long long#define db double#define pii pair<int,int>#define mp make_pair#define fi first#define se second
int p[103];int c[103];int calc(int x){
int cnt=0; for(int i=2;i<=sqrt(x);i++) { if(x%i==0) { p[++cnt]=i; c[cnt]=0; while(x%i==0) { x=x/i; c[cnt]++; } } } if(x>1) { p[++cnt]=x; c[cnt]=1; } for(int i=1;i<=cnt;i++) { cout<<p[i]<<"^"<<c[i]<<endl; }}
signed main(){ int sti=clock();
// freopen(".in","r",stdin);// freopen(".out","w",stdout); ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); int x; cin>>x; calc(x); // cerr<<1.0*(clock()-sti)/CLOCKS_PER_SEC<<endl; return 0;}
```
## 有理数取模```cpp#include<bits/stdc++.h>#define int long long 27 行未改动}```
## 排列组合
小的写上面!
$C(a, b) = \dfrac{a!}{b! (a-b)!} $
$P(a, b) = \dfrac{a!}{(a-b)!}$```cpp137 行未改动全部展开 else return ans=ans/n*(n-1);}```# 杂项## 表达式求值支持 + - * / ^,正确的括号匹配。```cpp#include <bits/stdc++.h>using namespace std;#define int long long#define ll long long#define db double#define pii pair<int,int>#define mp make_pair#define fi first#define se secondint p[130];bool isop(char c){ return c=='+'||c=='-'||c=='*'||c=='/'||c=='^';}int qpow(int a,int b){ int ans=1; while(b) { if(b&1) ans=ans*a; a=a*a; b>>=1; } return ans;}signed main(){ int sti=clock();
ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); string s; cin>>s; s='('+s+')'; p['+']=1;p['-']=1;p['*']=2;p['/']=2;p['^']=3; string ss=""; int ban=0; for(int i=0;i<s.size();i++) { if(s[i]=='+' || s[i]=='-') { if(ss.size()==0 || ss.back()=='(' || isop(ss.back()) ) { ss+='0'; } } ss+=s[i]; } s=ss; string ans=""; stack<char> st1; for(int i=0;i<s.size();i++) { if(isdigit(s[i])) { ans+=s[i]; if(i+1==s.size() || !isdigit(s[i+1])) { ans+='.'; } } else if(s[i]=='(') { st1.push(s[i]); } else if(s[i]==')') { while(!st1.empty() && st1.top()!='(') { ans+=st1.top(); st1.pop(); } if(!st1.empty()) { st1.pop(); } } else if(isop(s[i])) { while(!st1.empty() && st1.top()!='(') { if(p[st1.top()]>p[s[i]] || (p[st1.top()]==p[s[i]] && s[i]!='^')) { ans+=st1.top(); st1.pop(); } else break; } st1.push(s[i]); } } while(!st1.empty()) { if(st1.top()!='(') { ans+=st1.top(); } st1.pop(); } stack<int> st; int num=0; for(int i=0;i<ans.size();i++) { if(isdigit(ans[i])) { num=num*10+ans[i]-'0'; } else if(ans[i]=='.') { st.push(num); num=0; } else if(isop(ans[i])) { int b=st.top();st.pop(); int a=st.top();st.pop(); if(ans[i]=='+') st.push(a+b); if(ans[i]=='-') st.push(a-b); if(ans[i]=='*') st.push(a*b); if(ans[i]=='/') st.push(a/b); if(ans[i]=='^') st.push(qpow(a,b)); } } cout<<st.top();// cerr<<1.0*(clock()-sti)/CLOCKS_PER_SEC<<endl; return 0;}
```
## 矩阵快速幂```cpp#include<bits/stdc++.h>using namespace std;2 行未改动struct M{ long long c[101][101];} A, ANS;const int n=3;const int N = 3;
M operator * ( M &x, M &y){ M guo; for (int i = 1; i <= n; i++) for (int i = 1; i <= N; i++) { for (int j = 1; j <= n; j++) for (int j = 1; j <= N; j++) { guo.c[i][j] = 0; } } for (int i = 1; i <= n; i++) for (int i = 1; i <= N; i++) { for (int j = 1; j <= n; j++) for (int j = 1; j <= N; j++) { for (int k = 1; k <= n; k++) for (int k = 1; k <= N; k++) { guo.c[i][j] += x.c[i][k] * y.c[k][j] % Mod; guo.c[i][j] %= Mod; } } } return guo;}
M qpow(M A,ll m)M qpow(M A, ll m){ M ANS; ANS.c[1][1]=1; ANS.c[1][2]=1; ANS.c[1][3]=1; while (m > 0) { if (m & 1) ANS = ANS * A; A = A * A; m >>= 1; } return ANS;}
void init(){ ANS.c[1][1] = 1; ANS.c[1][2] = 1; ANS.c[1][3] = 1; A.c[1][1] = 0; A.c[1][2] = 0; A.c[1][3] = 1; A.c[2][1] = 1; A.c[2][2] = 0; A.c[2][3] = 0; A.c[3][1] = 0; A.c[3][2] = 1; A.c[3][3] = 1;}int main(){
int t; cin>>t; while(t--) int T; cin >> T; while (T--) { ll N; cin>>N; if (N <= 3) ll n; cin >> n; if (n <= 3) { cout<<1<<endl; cout << 1 << endl; continue; } A.c[1][1]=0; A.c[1][2]=0; A.c[1][3]=1; A.c[2][1]=1; A.c[2][2]=0; A.c[2][3]=0; A.c[3][1]=0; A.c[3][2]=1; A.c[3][3]=1; init(); M ANS = qpow(A, n - 3); cout << ANS.c[1][3] % Mod << endl;
M ANS=qpow(A,N-3); cout<<ANS.c[1][3]%Mod<<endl;
} return 0;}```17 行未改动 ans^=sum[x][y]-sum[u-1][y]-sum[x][v-1]+sum[u-1][v-1]; }```## 高精度注意实际位数,预防 MLE。```cpp#include <bits/stdc++.h>using namespace std;#define ll unsigned long long31 行未改动 return *this; } bign operator = (int num) { char s[20]; char s[maxn]; sprintf(s, "%d", num); *this = s; return *this; }179 行未改动全部展开