F.Infinite String Comparision

签到

#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pi acos(-1)
#define sc(a) scanf("%d",&a)
#define pf printf
#define vi vector<int>
const int N=1e5+10;
const int mod=1e9+7;
int n,m;
char a[N],b[N];
//int na[N],nb[N];
int main()
{
    while(~scanf("%s%s",a,b))
    {
        n=strlen(a),m=strlen(b);
        /*memset(na,0,sizeof na);
        memset(nb,0,sizeof nb);
        for(int i=2,j=0;i<=n;i++)
        {
            while(j&&a[j+1]!=a[i])j=na[j];
            if(a[j+1]==a[i])j++;
            na[i]=j;
        }
        for(int i=2,j=0;i<=n;i++)
        {
            while(j&&b[j+1]!=b[i])j=nb[j];
            if(b[j+1]==b[i])j++;
            nb[i]=j;
        }

        int x,y;
        if(n<m){

        }*/
        int x=2*max(n,m),flag=2;
        for(int i=0;i<x;i++)
        {
            if(a[i%n]<b[i%m])
            {
                flag=1;
                break;
            }
            else if(a[i%n]>b[i%m])
            {
                flag=3;
                break;
            }
        }
        if(flag==1)
            printf("<\n");
        else if(flag==2)
            printf("=\n");
        else
            printf(">\n");
    }
    return 0;
}

J.Easy Integration

前缀和维护

#include<iostream>
#include<string.h>
#define ll long long
#define pi acos(-1)
using namespace std;
const ll mod=998244353;
const int maxn=2e6+5;
ll a[maxn];
ll ksm(ll x)
{
	ll ans=1,n=mod-2;
	while(n)
	{
		if(n%2)
			ans*=x,ans%=mod;
		n/=2;
		x*=x;
		x%=mod;
	}
	return ans;
}
int main()
{
	int n;
	ll x;
	a[0]=1;
	for(int i=1;i<=2000003;i++)
	{
		a[i]=a[i-1]*i;
		a[i]%=mod;
	}
	while(~scanf("%d",&n))
	{
		x=a[n]*a[n];
		x%=mod;
		cout<<(x*ksm(a[2*n+1]))%mod<<endl;
	}
	return 0; 
}