T1:
线性基模板
#include<bits/stdc++.h>
using namespace std;
#define cs const
#define re register
#define pb push_back
#define pii pair<int,int>
#define ll unsigned long long
#define y1 shinkle
#define fi first
#define se second
#define bg begin
namespace IO{
cs int RLEN=1<<20|1;
inline char gc(){
static char ibuf[RLEN],*ib,*ob;
(ib==ob)&&(ob=(ib=ibuf)+fread(ibuf,1,RLEN,stdin));
return (ib==ob)?EOF:*ib++;
}
inline int read(){
char ch=gc();
int res=0;bool f=1;
while(!isdigit(ch))f^=ch=='-',ch=gc();
while(isdigit(ch))res=(res*10)+(ch^48),ch=gc();
return f?res:-res;
}
inline ll readll(){
char ch=gc();
ll res=0;bool f=1;
while(!isdigit(ch))f^=ch=='-',ch=gc();
while(isdigit(ch))res=(res*10)+(ch^48),ch=gc();
return f?res:-res;
}
inline char readchar(){
char ch=gc();
while(isspace(ch))ch=gc();
return ch;
}
inline int readstring(char *s){
int top=0;char ch=gc();
while(isspace(ch))ch=gc();
while(!isspace(ch)&&ch!=EOF)s[++top]=ch,ch=gc();
s[top+1]='\0';return top;
}
}
using IO::read;
using IO::readll;
using IO::readstring;
using IO::readchar;
template<typename tp>inline void chemx(tp &a,tp b){(a<b)?(a=b):0;}
template<typename tp>inline void chemn(tp &a,tp b){(a>b)?(a=b):0;}
cs int N=1000005,M=65;
struct Bas{
ll bs[M];int dep[M];
void insert(ll k,int t){
for(int i=63;~i&&k;i--)if((k>>i)&1){
if(!bs[i]){bs[i]=k,dep[i]=t;return;}
if(dep[i]<t){
swap(bs[i],k),swap(dep[i],t);
}
k^=bs[i];
}
}
ll query(int t){
ll res=0;
for(int i=63;~i;i--)if(dep[i]>=t){
if(!((res>>i)&1)&&bs[i])res^=bs[i];
}return res;
}
};
Bas a[N];
int dep[N],n,m;
int main(){
n=read(),m=read();
for(int i=1;i<=n;i++){
int f=read();ll v=readll();
dep[i]=dep[f]+1,a[i]=a[f],a[i].insert(v,dep[i]);
}
while(m--){
int op=read(),u=read();
if(op==0){
int d=dep[u]-read();
cout<<a[u].query(d)<<'\n';
}
else{
ll v=readll();n++;
dep[n]=dep[u]+1,a[n]=a[u],a[n].insert(v,dep[n]);
}
}return 0;
}
T2:
二分答案
k
k
k,然后每个串每个长度
k
k
k的子串前
k
−
1
k-1
k−1连向后
k
−
1
k-1
k−1个
只需要判是否有环即可
求答案拓扑排序后贪心即可
#include<bits/stdc++.h>
using namespace std;
#define cs const
#define re register
#define pb push_back
#define pii pair<int,int>
#define ll long long
#define y1 shinkle
#define fi first
#define se second
#define bg begin
namespace IO{
cs int RLEN=1<<20|1;
inline char gc(){
static char ibuf[RLEN],*ib,*ob;
(ib==ob)&&(ob=(ib=ibuf)+fread(ibuf,1,RLEN,stdin));
return (ib==ob)?EOF:*ib++;
}
inline int read(){
char ch=gc();
int res=0;bool f=1;
while(!isdigit(ch))f^=ch=='-',ch=gc();
while(isdigit(ch))res=(res*10)+(ch^48),ch=gc();
return f?res:-res;
}
inline ll readll(){
char ch=gc();
ll res=0;bool f=1;
while(!isdigit(ch))f^=ch=='-',ch=gc();
while(isdigit(ch))res=(res*10)+(ch^48),ch=gc();
return f?res:-res;
}
inline char readchar(){
char ch=gc();
while(isspace(ch))ch=gc();
return ch;
}
inline int readstring(char *s){
int top=0;char ch=gc();
while(isspace(ch))ch=gc();
while(!isspace(ch)&&ch!=EOF)s[++top]=ch,ch=gc();
s[top+1]='\0';return top;
}
}
using IO::read;
using IO::readll;
using IO::readstring;
using IO::readchar;
typedef unsigned long long ull;
template<typename tp>inline void chemx(tp &a,tp b){(a<b)?(a=b):0;}
template<typename tp>inline void chemn(tp &a,tp b){(a>b)?(a=b):0;}
cs ull bas=97;
cs int N=200005;
ull pw[N];
ull *s[N];
char*str[N];
int len[N];
inline ull query(int id,int l,int r){
return s[id][r]-s[id][l-1]*pw[r-l+1];
}
int n,m,k,tot,id[N],ps[N],in[N],pre[N],d[N];
char S[N];
unordered_map<ull,int>mp;
vector<int>e[N];
inline bool comp(int u,int v){
int l=0,r=k,res=-1,pu=ps[u]-k+2,pv=ps[v]-k+2;
while(l<=r){
int mid=(l+r)>>1;
if(query(id[u],pu,pu+mid)==query(id[v],pv,pv+mid))
l=mid+1,res=mid;
else r=mid-1;
}
return str[id[u]][pu+res+1]<str[id[v]][pv+res+1];
}
inline int topsort(int flag){
int num=0;queue<int> q;
for(int i=1;i<=tot;i++)if(!in[i])q.push(i),d[i]=0;
while(q.size()){
int u=q.front();q.pop();
num++;
for(int v:e[u]){
if(flag){
if(d[v]<d[u]+1||(d[v]==d[u]+1&&comp(u,pre[v]))){
d[v]=d[u]+1,pre[v]=u;
}
}
in[v]--;if(!in[v])q.push(v);
}
}return num;
}
char ans[N];
inline void getans(){
if(tot==0){
for(int i=1;i<k;i++)ans[i]='a';ans[k]='\0';
cout<<ans+1<<'\n';return;
}
int mxp=0,len=0;
for(int i=1;i<=tot;i++)if(!mxp||(d[mxp]<d[i]||(d[mxp]==d[i]&&comp(i,mxp))))mxp=i;
assert(mxp);
for(int i=k-1;i;i--)ans[++len]=str[id[mxp]][ps[mxp]-i+1];
mxp=pre[mxp];
while(mxp){
ans[++len]=str[id[mxp]][ps[mxp]];
mxp=pre[mxp];
}ans[len+1]='\0';
cout<<ans+1<<'\n';
}
inline bool check(int _k,int flag=0){
k=_k;
for(int i=1;i<=tot;i++)e[i].clear(),in[i]=pre[i]=d[i]=0;
tot=0;mp.clear();
for(int i=1;i<=n;i++){
for(int j=1;j+k-1<=len[i];j++){
ull x=query(i,j,j+k-2),y=query(i,j+1,j+k-1);
int u,v;
if(!mp.count(x)){
mp[x]=(u=++tot),id[u]=i,ps[u]=j+k-2;
}else u=mp[x];
if(!mp.count(y)){
mp[y]=(v=++tot),id[v]=i,ps[v]=j+k-1;
}else v=mp[y];
e[v].pb(u),in[u]++;
}
}
int sz=topsort(flag);
if(!flag)return sz!=tot;
getans();return 0;
}
inline void solve(){
n=read();int sm=1;
for(int i=1;i<=n;i++){
len[i]=readstring(S);
sm+=len[i];
s[i]=new ull[len[i]+1];
str[i]=new char[len[i]+2];
memcpy(str[i],S,sizeof(char)*(len[i]+1));
for(int j=1;j<=len[i];j++)
s[i][j]=s[i][j-1]*bas+S[j]-'a'+1;
}
int l=1,r=sm,res=sm;
while(l<=r){
int mid=(l+r)>>1;
if(check(mid))l=mid+1;
else r=mid-1,res=mid;
}cout<<res<<'\n';
check(res,1);
}
int main(){
#ifdef Stargazer
freopen("lx.in","r",stdin);
// freopen("my.out","w",stdout);
#endif
pw[0]=1;
for(int i=1;i<N;i++)pw[i]=pw[i-1]*bas;
int T=read();
while(T--)solve();
return 0;
}
T3:
留下了没有数理基础的泪水
可以简单列出式子
∫
a
b
d
∗
∣
cos
(
x
r
)
cos
(
x
+
d
r
)
−
1
∣
d
x
\int_{a}^bd*|\frac{\cos(\frac{x}{r})}{\cos(\frac{x+d}{r})}-1|\mathrm{d}x
∫abd∗∣cos(rx+d)cos(rx)−1∣dx
∫
a
b
cos
(
x
/
r
)
cos
(
(
x
+
d
)
/
r
)
d
x
=
c
o
s
(
y
−
d
/
r
)
cos
(
y
)
d
x
=
cos
(
d
/
r
)
+
sin
(
d
/
r
)
∫
tan
(
(
x
+
d
)
/
r
)
\int_{a}^b\frac{\cos(x/r)}{\cos((x+d)/r)}dx=\frac{cos(y-d/r)}{\cos(y)}dx\\ =\cos(d/r)+\sin(d/r)\int\tan((x+d)/r)
∫abcos((x+d)/r)cos(x/r)dx=cos(y)cos(y−d/r)dx=cos(d/r)+sin(d/r)∫tan((x+d)/r)
有
ln
(
cos
(
x
)
)
′
=
−
tan
(
x
)
\ln(\cos(x))'=-\tan(x)
ln(cos(x))′=−tan(x)
=
cos
(
d
/
r
)
−
sin
(
d
/
r
)
ln
(
cos
(
(
d
+
x
)
/
r
)
)
/
r
=\cos(d/r)-\sin(d/r)\ln(\cos((d+x)/r))/r
=cos(d/r)−sin(d/r)ln(cos((d+x)/r))/r
主要是来卡精度,还有用和差化积卡三角函数的精度
注意有可能转很多圈,每一圈都要分开算
二分上下界积分
似乎
s
t
d
std
std还有锅,感觉有毒,咕了咕了