嘿嘿嘿 我是大傻子 你也是
C++字典树
#include<bits/stdc++.h>
#define rn return
#define ios ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
using namespace std;
using ll=long long;
const int N=3e6+10;
ll t;
ll n,q;
string s;
ll tr[N][65],ct[N],x;
void init()
{
for(int i=0;i<=x;i++)for(int j=0;j<=122;j++)tr[i][j]=0;
for(int i=0;i<=x;i++)ct[i]=0;
x=0;
}
ll get(char c)
{
if(c>='A'&&c<='Z')return c-'A';
else if(c>='a'&&c<='z')return c-'a'+26;
else return c-'0'+52;
}
void ist(string s)
{
ll p=0;
ll ln=s.size();
for(int i=0;i<ln;i++)
{
ll c=get(s[i]);
if(!tr[p][c])tr[p][c]=++x;
p=tr[p][c];
ct[p]++;
}
}
int find(string s)
{
ll p=0;
ll ln=s.size();
for(int i=0;i<ln;i++)
{
ll c=get(s[i]);
if(!tr[p][c])rn 0;
p=tr[p][c];
}
rn ct[p];
}
int main()
{
ios
rn 0;
}
C++快读
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
ll n,a,s;
int r()
{
ll f=1,k=0;
char c=getchar_unlocked();
while(c<'0'||c>'9')
{
if(c=='-')f=-1;
c=getchar_unlocked();
}
while(c>='0'&&c<='9')
{
k=k*10+c-'0';
c=getchar_unlocked();
}
return k*f;
}
void w(ll x)
{
if(x<0)putchar('-'),x=-x;
if(x<10)putchar(x+'0');
else w(x/10),putchar(x%10+'0');
}
int main()
{
return 0;
}
C++并查集模板题
#include<bits/stdc++.h>
using namespace std;
const int N=2e5+10;
int x,y,z;
int fa[N];
int n,m;
int find(int x)
{
if(fa[x]==x)return x;
else return fa[x]=find(fa[x]);
}
int main()
{
cin>>n>>m;
for(int i=1;i<=n;i++)fa[i]=i;
while(m--)
{
cin>>z>>x>>y;
if(z==1)
{
x=find(x),y=find(y);
if(x==y)continue;
fa[x]=y;
}
else
{
x=find(x),y=find(y);
if(x==y)cout<<"Y\n";
else cout<<"N\n";
}
}
}
C++manacher
#include<bits/stdc++.h>
#define ios ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)
using namespace std;
using ll=long long;
const int N=3e7+10;
string s;
string t="#";
ll id,r,mx,idx;
ll n,mir;
ll p[N];
int main()
{
ios;
cin>>s;
for(char c:s)
{
t+=c;
t+='#';
}
n=t.length();
for(int i=0;i<n;i++)
{
mir=2*id-i;
if(i<=r)p[i]=min(r-i,p[mir]);
while(i-p[i]>=0&&i+p[i]<n)
{
if(t[i+p[i]]==t[i-p[i]])p[i]++;
else break;
}
if(i+p[i]>r)
{
id=i;
r=i+p[i];
}
if(p[i]>mx)
{
mx=p[i];
idx=i;
}
}
cout<<mx-1;
return 0;
}