TLE 开O2 79PTS 求助
查看原帖
TLE 开O2 79PTS 求助
491007
凤凰工作室楼主2023/1/12 17:10
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
using namespace std;
#define int long long
string a,b;
int z[(int)4e7+5];
int qz,qp;
int la,lb;
inline string Read()
{
    string str;
    char s = getchar();
    while (s==' '||s =='\n'||s =='\r')
    {
        s=getchar();
    }
    while (s!=' '&&s!='\n'&&s!='\r')
    {
        str+=s;
        s=getchar();
    }
    return str;
}
void get_z(string c)
{
    int lc=c.length();
    z[0]=lc;
    for(register int i=1,l=0,r=0;i<lc;i++)
    {
        if(i<=r)z[i]=min(z[i-l],r-i+1);
        while(c[z[i]]==c[i+z[i]])z[i]++;
        if(i+z[i]-1>r)
        {
            l=i;
            r=i+z[i]-1;
        }
    }
}
signed main(void)
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    a=Read(),b=Read();
    lb=b.length(),la=a.length();
    get_z(b+a);
    qz^=1ll*(lb+1)*1;
	for(register int i=1;i<lb;i++)
	{
		qz^=1ll*(min(z[i],lb-i)+1)*(i+1);
	}
	cout<<qz<<endl;
	for(register int i=0;i<la;i++)
	{
		qp^=1ll*(min(z[i+lb],la-i)+1)*(i+1);
	}
	cout<<qp<<endl;
}
2023/1/12 17:10
加载中...