首页 > 其他分享 >『做题记录』P3599 Koishi Loves Construction

『做题记录』P3599 Koishi Loves Construction

时间:2023-12-06 22:24:34浏览次数:24  
标签:ch int sum 构造 Construction Loves P3599 Koishi equiv

P3599 Koishi Loves Construction

Description

  给定一下两种询问:

  • Task1:试判断能否构造并构造一个长度为 \(n\) 的 \(1\dots n\) 的排列,满足其 \(n\) 个前缀和在模 \(n\) 的意义下互不相同。
  • Task2:试判断能否构造并构造一个长度为 \(n\) 的 \(1\dots n\) 的排列,满足其 \(n\) 个前缀积在模 \(n\) 的意义下互不相同。

  如果有相应的构造,还需输出其中一种合法的构造。

Solution

Task1

  对题目进行分析,可以得到几个结论:

  • 不能有区间 \([L,R](L \neq 1)\) 的倍数,否则 \(sum_{L-1}\equiv sum_R \pmod n\)
  • 对于构造出的序列 \(a\) , \(a_1 = n\) ,否则 \(sum_i\equiv sum_{i-1} \pmod n\)
  • \(n\in even\cup 1\) ,因为对于 \(n\in odd\):

\[\sum_{i=2}^{n}a_i = \sum_{i=1}^{n-1}i = n\times\left(\frac{n-1}2\right)\equiv 0 \pmod n \]

从而不符合上面第一点的限制。

  接下来如果在考场上,可以先与大样例对拍,确认无误后就可以打暴搜找规律,在 \(n = 6\) 下可以找到这样一组解:
6 1 4 3 2 5
  通过这组解可以得到构造:

  1. 对于 \(i \in odd, a_i = n+1-i\) 。
  2. 对于 \(i \in even, a_i = i-1\) 。

Task2

  

Code

点击查看代码
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
#define mp make_pair
#define vi vector<int>
#define eb emplace_back
const int N = 1e5+5, MOD = 998244353, INF = 2e9;
inline int read() {
	register int x = 0, f = 1;
	register char ch = 0;
	while(ch < 48 || ch > 57) {
			ch = getchar();
			if (ch == '-') f = -1;
		}
	while(ch >= 48 && ch <= 57) x = x*10+(ch^48), ch = getchar();
	return f*x;
}

int n;

int powM(int x, int y) {
	int ret = 1;
	while (y) {
		if (y&1) ret = 1ll*ret*x%n;
		x = 1ll*x*x%n, y >>= 1;
	} return ret;
}

int pri[N], cntp;
bool np[N];
void sieve() {
	for (int i = 2; i <= 1e5; ++i) {
		if (!np[i]) pri[++cntp] = i;
		for (int j = 1; j <= cntp && i*pri[j] <= 1e5; ++j) {
			np[i*pri[j]] = true;
			if (i%pri[j] == 0) break;
		}
	}
}

void solve1() {
	if ((n&1)&&(n!=1)) return puts("0"), void();
	printf("2 ");
	for (int i = 1; i <= n; ++i)
		printf("%d ", i&1 ? n+1-i : i-1);
	puts("");
}

void solve2() {
	if (np[n] && n != 1 && n != 4) return puts("0"), void();
	if (n == 1) return puts("2 1"), void();
	if (n == 4) return puts("2 1 3 2 4"), void();
	printf("2 ");
	int tmp = 1, sum = 1;
	for (int i = 1; i <= n-1; ++i) {
		printf("%d ", tmp);
		tmp = 1ll*powM(sum, n-2)*(i+1)%n;
		sum = 1ll*sum*tmp%n;
	}
	printf("%d\n", n);
}

int main() {
	int opt, T;
	opt = read(), T = read();
	if (opt == 2) sieve();
	while (T--) {
		n = read();
		if (opt == 1) solve1();
		else solve2();
	}
	return 0;
}

Summary

  • 没有思路不要急,根据题目给出的性质进行推理出有用的信息
  • 想不到构造方法时,有时候可以暴力dfs寻找符合题意的解,从中找一种易于构造的序列类别进行构造。

标签:ch,int,sum,构造,Construction,Loves,P3599,Koishi,equiv
From: https://www.cnblogs.com/BlackCrow/p/17880663.html

相关文章

  • Natural Image Reconstruction from fMRI using Deep Learning: A Survey
    NaturalImageReconstructionfromfMRIusingDeepLearning:ASurveyZarinaRakhimberdina1,3,QuentinJodelet1,3,XinLiu2,3,∗,TsuyoshiMurata1,3一句话概括:介绍了各种自然图像重构方法(生成模型和非生成模型)以及评价指标,并提出了综合评价各模型的方法。介绍fMR......
  • Educational Codeforces Round 157 (Rated for Div. 2) D. XOR Construction
    题目链接题意给你\(n-1\)个整数\(a_1,a_2,\dots,a_{n-1}\)。你的任务是构造一个数组\(b_1,b_2,\dots,b_n\),使得:从\(0\)到\(n-1\)的每个整数都在\(b\)中出现一次;对于从\(1\)到\(n-1\)的每个\(i\),\(b_i\oplusb_{i+1}=a_i\)(其中\(\oplus\)表示......
  • P3708 koishi的数学题(取模转化减法)
    \(\displaystylef(x)=\sum_{i=1}^nx\bmodi\)对于一个i,枚举k对于[xk,x(k+1)),中的数,贡献的形式都为a[i]-i*k直接差分维护即可#include<cstdio>#include<algorithm>#include<cstring>#include<cmath>#include<map>#include<vector>#defineA......
  • koishi的数学题
    koishi的数学题题目描述Koishi在Flandre的指导下成为了一名数学大师,她想了一道简单的数学题。输入一个整数$n$,设$\displaystylef(x)=\sum_{i=1}^nx\bmodi$,你需要输出$f(1),f(2),\ldots,f(n)$。按照套路,Koishi假装自己并不会做这道题,就来求你帮忙辣。输入格......
  • Codeforces Round 865 (Div. 2) B. Grid Reconstruction
    给一个\(2\timesn\)的网格,且\(n\)是偶数。你需要将\(1\sim2\timesn\)填入这个网格。一条路径是从\((1,1)\)开始,每次只能向右或向下,到\((2,n)\)结束时,所经过的位置。按经过点的顺序标号,一两条路径的代价是\(cost=a_1-a_2+a_3-a_4+\cdots=\sum_{i=1......
  • [JOISC 2021 Day2] 道路の建設案 (Road Construction)
    [JOISC2021Day2]道路の建設案(RoadConstruction)题意给定图上\(n\)个点,求前\(k\)小曼哈顿距离点对距离。题解很好的一道题。首先有一个\(O(nlog^2n)\)的做法,个人感觉还是很有启发性的。一般对于第\(k\)小的处理方法是二分,二分第\(k\)小的距离是多少。然后统......
  • C#教程 - 元组与解构(Tuples and Deconstruction )
    C#教程-元组与解构(TuplesandDeconstruction) 更新记录转载请注明出处:2022年9月24日发布。2022年9月10日从笔记迁移到博客。元组(tuples)说明#注意:C#7.0可用注意:元组不可以声明为静态类型作用:元组常用于传递和返回多个值;匿名类型可以做的,Tuples基本都可以完成元组是......
  • Rethinking Point Cloud Registration as Masking and Reconstruction论文阅读
    RethinkingPointCloudRegistrationasMaskingandReconstruction2023ICCV*GuangyanChen,MeilingWang,LiYuan,YiYang,YufengYue*;ProceedingsoftheIEEE/CVFInternationalConferenceonComputerVision(ICCV),2023,pp.17717-17727paper:Rethin......
  • 论文阅读:iterator zero-shot llm prompting for knowledge graph construction
    Abstract知识图谱,一种相互连接和可解释的结构。生成需要更多的人力、领域知识、并需要适用于不同的应用领域。本论文提出借助LLM,通过0-shot和外部知识不可知的情况下生成知识图谱。主要贡献:迭代的prompting提取最终图的相关部分0-shot,不需要examples一个可扩展的解决方案,......
  • more and more construction problem,what should i do ?
    一些构造CF1464FShowingOff显然原图连边会形成若干内向基环树森林,所有在同一个环上的点\(S\)是相同的,注意到原图是二分图,因此所有环都是偶环。一个重要观察是,我们可以让所有环的长度都是2,因为总可以把长度\(>2\)的环拆成若干个二元环,而且在\(S_{i,j}\geq2\)的限制......