#include<bits/stdc++.h> using namespace std; #define Q 137 #define mod 19260817 #define Mod 20172101 #define ll long long ll hsh1[100010]; ll hsh2[100010]; ll m1[100010]; ll m2[100010]; char s[100010]; int q,u,v; int check(int l) { if(l==0) return 1; int valu,valv; valu=((hsh1[u+l-1]-hsh1[u-1]*m1[l])%mod+mod)%mod; valv=((hsh1[v+l-1]-hsh1[v-1]*m1[l])%mod+mod)%mod; if(valu!=valv) return 0; valu=((hsh2[u+l-1]-hsh2[u-1]*m2[l])%Mod+Mod)%Mod; valv=((hsh2[v+l-1]-hsh2[v-1]*m2[l])%Mod+Mod)%Mod; if(valu!=valv) return 0; return 1; } int main() { freopen("lcp.in","r",stdin); freopen("lcp.out","w",stdout); scanf("%s",s+1); scanf("%d",&q); int len=strlen(s+1); for(int i=1;i<=len;i++) { hsh1[i]=(hsh1[i-1]*Q+s[i]-'a')%mod; hsh2[i]=(hsh2[i-1]*Q+s[i]-'a')%Mod; } m1[0]=m2[0]=1; for(int i=1;i<=len;i++) {m1[i]=m1[i-1]*Q%mod;m2[i]=m2[i-1]*Q%Mod;} while(q--) { scanf("%d%d",&u,&v); if(u>v) swap(u,v); int l=0,r=len-v+1,mid; while(l<=r) { mid=(l+r)>>1; if(check(mid)) l=mid+1; else r=mid-1; } printf("%d ",l-1); } }
#include<bits/stdc++.h> using namespace std; int cnt,fst[100010],nxt[200010],to[200010],c[200010],lim[200010]; void link(int x,int y,int v,int li) { nxt[++cnt]=fst[x]; fst[x]=cnt; to[cnt]=y; c[cnt]=v; lim[cnt]=li; } struct Point { int id; int dis; bool operator < (const Point &a) const { return dis>a.dis; } }; int n,m; int a,b,c1,d; int dis[100010]; int vis[100010]; void dij() { priority_queue<Point>q; Point t; t.id=n;t.dis=0; q.push(t); dis[n]=0; while(!q.empty()) { int now=q.top().id; q.pop(); if(vis[now]) continue; vis[now]=1; for(int i=fst[now];i;i=nxt[i]) { if(dis[to[i]]>max(lim[i],dis[now]+c[i])) { dis[to[i]]=max(lim[i],dis[now]+c[i]); if(!vis[to[i]]) { t.id=to[i]; t.dis=dis[to[i]]; q.push(t); } } } } } int main() { freopen("spaceship.in","r",stdin); freopen("spaceship.out","w",stdout); scanf("%d%d",&n,&m); for(int i=1;i<=m;i++) { scanf("%d%d%d%d",&a,&b,&c1,&d); link(a,b,c1,d);link(b,a,c1,d); } memset(dis,127,sizeof(dis)); dij(); if(dis[1]==2139062143) printf("-1 "); else printf("%d ",dis[1]); }
T2炸了就不放上来了
100+30+100 rank1