结构体
结构体 struct point { int sum; int cnt; bool operator <(const point &b) const{ if(sum==b.sum)return cnt<b.cnt; else return sum<b.sum; //这是按照你的要求进行排序 ...
结构体 struct point { int sum; int cnt; bool operator <(const point &b) const{ if(sum==b.sum)return cnt<b.cnt; else return sum<b.sum; //这是按照你的要求进行排序 ...
归并排序 //使用分治的思想,将所有的过程都分解成两个,在结束排序之后,我们返回,然后就可以进行排序 #include <bits/stdc++.h> using namespace std; const int N = 1e6+7; int s[N]; void merge_sort(int l,int r) { if(l>=r)return ; int...
快速排序 // 链接:https://www.acwing.com/problem/content/787/ #include <bits/stdc++.h> using namespace std; /* 快速排序的思想是根据分治处理的 每次将他分解成两个区域,知道区域的长度为1 然后将两个有序区域进行合并 */ const int N = 1e6+7; int s[N]; ...
一维前缀和 #include <bits/stdc++.h> using namespace std; const int N = 1e6+6; const int M = 3e5+7; #define ll long long #define en '\n' #define debug cout<<"------" #define fast ios::sync_w...
最小表示法 #include<bits/stdc++.h> using namespace std; const int N = 1e6+7; int s[N]; int n; int get_ans() { int i=0,j=1,k=0; while(i<n&&j<n) { if(s[i+k]==s[j+...
KMP #include <bits/stdc++.h> using namespace std; const int N = 1e6+7; int nx[N]; int main() { string s1,s2; cin>>s1>>s2; for(int i=1,j=0;s2[i];i++) { while(j&&s2[i]...
快速幂 ll qsm(ll x,ll y) { ll ans=1; while(y) { if(y&1)ans=ans*x; x=x*x; y>>=1; } return ans; }
素数筛 #include <bits/stdc++.h> using namespace std; const int N =1e6+7; int vis[N],prime[N]; int main() { int n,c=0; scanf("%d",&n); for(int i=2;i<=n;i++) { if(!...
克鲁斯卡尔算法 #include <iostream> #include <cstring> #include <algorithm> using namespace std; const int N = 100010; int p[N];//保存并查集 struct E{ int a; int b; int w; b...
题目描述 给出n个数,m次询问,给出l,r的最大值/最小值,时间复杂度要求低 code #include <bits/stdc++.h> using namespace std; const int N = 1e6 + 7, M = 22; int n, m, f[N][M], lg[N]; void init() { for (int j = 1; j <= ...