#include <bits/stdc++.h>
using namespace std;
int main() {
srand((unsigned)time(nullptr));
while (true) {
if (system("gen.exe > in.txt") != 0) return 1; // 生成数据
if (system("bf.exe < in.txt > ans.txt") != 0) return 1; // 暴力答案
if (system("sol.exe < in.txt > out.txt") != 0) return 1; // 你的答案
if (system("fc out.txt ans.txt > nul")) { // 对比输出
cout << "Wrong Answer on this case!\n";
break;
}
cout << "Accepted\n";
}
return 0;
}
外网弱智图片
不要觉得你一文不值
------------华丽的分割线
你的心脏:¥100w
你的眼角膜:¥10w
你的肾:¥35w
你的肝:¥195w
你的腰子:¥30w
——消费清单
[规则怪谈](https://www.luogu.com.cn/article/zn9htyf5
??=(?−1)(??−1+??−2)//错排公式
int find(int x)
{
if(a[x]==x) return x;
return a[x]=find(a[x]);
}
void join(int x,int y)
{
int xx=find(x);
int yy=find(y);
if(xx!=yy) a[xx]=yy;
return ;
} 并查集
一个很奇怪的东西
「仙鹤灵龟都滑倒」
「猜猜身后是何人」
单调队列
for(int i=1;i<=n;i++)
{
while(head<tail&&q[head]+k<=i) head++;
while(head<tail&&a[q[tail-1]]>a[i]) tail--;
q[tail]=i;
tail++;
if(i>=k) cout<<a[q[head]]<<" ";
}如何查看别人的主页 ,这是一篇文章,但是,如果你能看到这个链接,就说明你已经不用看了(嘿嘿,你已经学会看别人主页的方法了,所以我的这篇文章有什么用呢?嗯····对了!可以私信!)
------------从某个人的主页上截下来的
一个人,愿意用万两黄金换你,那是欲。
一个人,愿意用前程似锦换你,那是爱。
而一个人,愿意用二十年的年华,最好的岁月来换你,来等你。
且不吭声,不求回报,也不求结果。
那是傻。
放弃十五笔,坚持十六笔
而猝死是十七笔
那为什么我们还要坚持呢?
因为复活是十八笔
ST表
void cs()
{
LOG[1]=0;
for(int i=2;i<=n;i++) LOG[i]=LOG[i>>1]+1;
for(int i=1;i<=n;i++) mx[i][0]=a[i];
for(int i=1;i<=LOG[n];i++)
for(int j=1;j<=n;j++) mx[j][i]=max(mx[j][i-1],mx[j+(1<<(i-1))][i-1]);
}
int main()
{
cin>>n>>m;
for(int i=1;i<=n;i++) cin>>a[i];
cs();
for(int i=1;i<=m;i++)
{
int l=read();
int r=read();
int len=r-l+1;
int k=LOG[len];
cout<<max(mx[l][k],mx[r-(1<<k)+1][k])<<"\n";
}
} 倍增最值(树上)
num[x]=cnt,dep[x]=dep[fa]+1;
low[x][0]=fa;
for(int i=1;(1<<i)<=dep[x];i++)
{
low[x][i]=low[low[x][i-1]][i-1];
minn[x][i]=min(minn[x][i-1],minn[low[x][i-1]][i-1]);
}
for(int i=0;i<v[x].size();i++)
{
point p=v[x][i];
if(p.dao==fa) continue;
minn[p.dao][0]=p.val;
dfs(p.dao,x);
}LCA
倍增:
void tiao(int &x,int gao)
{
for(int i=14;i>=0;i--)
if(dep[low[x][i]]>=gao) x=low[x][i];
}
int lca(int x,int y)
{
if(dep[x]<dep[y]) swap(x,y);
tiao(x,dep[y]);
for(int i=14;i>=0;i--)
if(low[x][i]!=low[y][i]){x=low[x][i],y=low[y][i];}
if(x!=y) x=low[x][0];
return x;
}快读
#define getchar getchar_unlocked
inline int read()
{
int f=1,x=0;
char ch=getchar();
while(ch<'0'||ch>'9')
{
if(ch=='-'){f=-1;}
ch=getchar();
}
while(ch>='0'&&ch<='9'){ x=x*10+ch-48;ch=getchar();}
return x*f;
}快写
void out(long long x)
{
if(x<0) {putchar('-'),x=-x;}
if(x<10)putchar(x+'0');
else out(x/10),putchar(x%10+'0');
}for(int i=0;i<=t.length();i++)
{
if(i){for(int j=0;j<26;j++){delta[i][j]=delta[fail[i-1]][j];}}
if(i<t.length()){delta[i][t[i]-'a']=i+1;}
if(i&&i<t.length()){fail[i]=delta[fail[i-1]][t[i]-'a'];}
}//优化后的KMP
使用此网站,即可通过外星语十级考试
#include <iostream>
#include <string>
using namespace std;
int main()
{
string a = "123456123456";
cout << a.find_first_of("345",2) << endl;//a.find_first_of(x,y)表示从第y个字符起从前往后第一个是x这个字符的字符的位置(若x是字符串,则字符只需是x的任意一个字符即可)。
cout << a.find_first_of("345") << endl;//a.find_first_of(x)表示(从开头找,从前往后)第一个是x这个字符的字符的位置(若x是字符串,则字符只需是x的任意一个字符即可)。
cout << a.find_last_of("345",10) << endl;//a.find_last_of(x,y)表示从第y个字符起从后往前第一个是x这个字符的字符的位置(若x是字符串,则字符只需是x的任意一个字符即可)。
cout << a.find_last_of("345") << endl;//a.find_last_of(x)表示(从末尾找,从后往前)第一个是x这个字符的字符的位置(若x是字符串,则字符只需是x的任意一个字符即可)。
cout << a.find_first_not_of("345",2) << endl;//a.find_first_not_of(x,y)表示从第y个字符起从前往后第一个不是x这个字符的字符的位置(若x是字符串,则字符需要不是x的任意一个字符)。
cout << a.find_first_not_of("345") << endl;//a.find_first_not_of(x)表示(从开头找,从前往后)第一个不是x这个字符的字符的位置(若x是字符串,则字符需要不是x的任意一个字符)。
cout << a.find_last_not_of("345",2) << endl;//a.find_last_not_of(x,y)表示从第y个字符起从后往前第一个不是x这个字符的字符的位置(若x是字符串,则字符需要不是x的任意一个字符)。
cout << a.find_last_not_of("345") << endl;//a.find_last_not_of(x)表示(从末尾找,从后往前)第一个不是x这个字符的字符的位置(若x是字符串,则字符需要不是x的任意一个字符)。
cout << a.substr() << endl;//就是cout << a;
cout << a.substr(1,3) << endl;//a.substr(x,y)表示从下标为x起,长度为y的字符串
cout << a.substr(1) << endl;//a.substr(x)表示从下标为x起,一直到末尾的字符串
return 0;
}
最短路计数
q.push({s,0});
dis1[s]=0,ge1[s]=1;
while(!q.empty())
{
point jiu=q.top();
q.pop();
if(jiu.val>dis1[jiu.dao]){continue;}//过期
for(int i=0;i<v[jiu.dao].size();i++)
{
int p=v[jiu.dao][i];
if(dis1[p]<=dis1[jiu.dao]+1)
{
if(dis1[p]==dis1[jiu.dao]+1){ge1[p]+=ge1[jiu.dao];ge1[p]%=mod;}
continue;
}
ge1[p]=ge1[jiu.dao]%mod;
dis1[p]=dis1[jiu.dao]+1;
q.push({p,dis1[p]});
}
}