#P5517. [MtOI2019] 幻想乡数学竞赛

    ID: 4260 远端评测题 1000ms 128MiB 尝试: 0 已通过: 0 难度: 8 上传者: 标签>数学2019洛谷原创O2优化矩阵加速,矩阵优化生成函数线性递推,递推式

[MtOI2019] 幻想乡数学竞赛

Description

There exists a sequence {an}(n{0,1,2,,2641})\{ a_n\} (n\in \{ 0,1,2,\cdots ,2^{64}-1\} ).
Given $a_0=-3,a_1=-6,a_2=-12,a_n=3a_{n-1}+a_{n-2}-3a_{n-3}+3^n$.

  • Now you are given a non-negative integer nn. Let p=109+7p=10^{9}+7. Please compute anmodpa_n \bmod p.

  • Note: if an<0a_n<0, please output (anmodp+p)modp(a_n \bmod p+p)\bmod p.

To test your skills more thoroughly, Nitori prepared TT queries.

  • To reduce the amount of input and output to some extent, we generate the queries using the following code:
namespace Mker
{
//  Powered By Kawashiro_Nitori
//  Made In Gensokyo, Nihon
	#include<climits>
	#define ull unsigned long long
	#define uint unsigned int
	ull sd;int op;
	inline void init() {scanf("%llu %d", &sd, &op);}
	inline ull ull_rand()
	{
		sd ^= sd << 43;
		sd ^= sd >> 29;
		sd ^= sd << 34;
		return sd;
	}
	inline ull rand()
	{
		if (op == 0) return ull_rand() % USHRT_MAX + 1;
		if (op == 1) return ull_rand() % UINT_MAX + 1; 
		if (op == 2) return ull_rand();
	}
}

After calling Mker::init(), the value returned by your ii-th call to Mker::rand() is the nin_i of the ii-th query.

The constraints on opop are as follows:

  • If op=0op=0, then ni216n_i \leq 2^{16}.

  • If op=1op=1, then ni232n_i \leq 2^{32}.

  • If op=2op=2, then ni2641n_i \leq 2^{64}-1.

To reduce your output size, you only need to output the xor sum of the answers of all queries.

Input Format

The first line contains three integers: TT, seedseed, and opop.

Output Format

Output one integer: the xor sum of the answers to the TT queries.

142857 1145141919 0
562611141
142857 1145141919 1
894946216
142857 1145141919 2
771134436

Hint

Subtasks

png

Source

Lost Home 2019 League (MtOI2019) T4

Problem setter: disangan233

Problem tester: suwakow

Translated by ChatGPT 5