2020杭电多校第二场The Oculus

第六题:The Oculus

题目:

Let’s define the Fibonacci sequence F1,F2,… as F1=1,F2=2,Fi=Fi−1+Fi−2 (i≥3).

It’s well known that every positive integer x has its unique Fibonacci representation (b1,b2,…,bn) such that:

· b1×F1+b2×F2+⋯+bn×Fn=x.

· bn=1, and for each i (1≤i<n), bi∈{0,1} always holds.

· For each i (1≤i<n), bi×bi+1=0 always holds.

For example, 4=(1,0,1), 5=(0,0,0,1), and 20=(0,1,0,1,0,1) because 20=F2+F4+F6=2+5+13.

There are two positive integers A and B written in Fibonacci representation, Skywalkert calculated the product of A and B and written the result C in Fibonacci representation. Assume the Fibonacci representation of C is (b1,b2,…,bn), Little Q then selected a bit k (1≤k<n) such that bk=1 and modified bk to 0.

It is so slow for Skywalkert to calculate the correct result again using Fast Fourier Transform and tedious reduction. Please help Skywalkert to find which bit k was modified.

思路

双哈希

代码

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef unsigned long long ull;


const int N=2e6+9;
const int mod=1e9+7;
const int mod1=1e9+9;
ll c[N];
ll fib[N],fib1[N];

int main()
{
	fib[1]=1,fib[2]=2;
	fib1[1]=1,fib1[2]=2;
	for(int i=3;i<N;i++)
	{
		fib[i]=(fib[i-1]+fib[i-2])%mod;
		fib1[i]=(fib1[i-1]+fib1[i-2])%mod1; 
	}
	int T;
	cin>>T;
	while(T--)
	{
		int n,m,t;
		scanf("%d",&n);
		ll ans1=0,ans11=0,ans2=0,ans22=0,ans3=0,ans33=0;
		for(int i=1;i<=n;i++)
		{
			ll x;
			scanf("%lld",&x);
			if(x)
			{
				ans1=(ans1+fib[i])%mod;
				ans11=(ans11+fib1[i])%mod1;
			}
		}
		scanf("%d",&m);
		for(int i=1;i<=m;i++)
		{
			ll x;
			scanf("%lld",&x);
			if(x)
			{
				ans2=(ans2+fib[i])%mod;
				ans22=(ans22+fib1[i])%mod1;
			}
		}
		scanf("%d",&t);
		for(int i=1;i<=t;i++)
		{
			scanf("%lld",&c[i]);
			if(c[i])
			{
				ans3=(ans3+fib[i])%mod;
				ans33=(ans33+fib1[i])%mod1;
			}
		}
		ans2=(ans2*ans1)%mod;
		ans22=(ans22*ans11)%mod1;
		
		
		for(int i=1;i<=t;i++)
		{
			ll ans=ans3,anss=ans33;
			
			if(!c[i])
			{
				ans=(ans+fib[i])%mod;
				anss=(anss+fib1[i])%mod1;
				if(ans2==ans&&ans22==anss)
				{
					printf("%d\n",i);
					break;
				}
			}
			
		}
	}
	return 0;
}

猜你喜欢

转载自blog.csdn.net/qq_44828887/article/details/107546246