序列取反问题
题解
讨论
查看他人的提交
题号:NC202431
时间限制:C/C++/Rust/Pascal 4秒,其他语言8秒
空间限制:C/C++/Rust/Pascal 256 M,其他语言512 M
64bit IO Format: %lld
题目描述
有
个牛牛排成一排,从头到尾编号为
到
,牛牛们都有一个可爱值,对于牛牛
,记它的可爱值为
,
,特别地,我们令
。这次我们的任务是把牛牛全部变成快乐的牛牛,起初所有牛牛都不快乐,每次我们从不快乐的牛牛中等概率选择一个,设选出来的是
,把编号
到
中的不快乐的牛牛全部变成快乐的牛牛,一次这样的操作记为1步。问让全部不
快乐的牛牛都变成快乐的牛牛的期望步数。
由于牛牛们都很有特色,所以对于任意
,均满足条件:若
,则
,
这两个条件一定满足其中1个。
答案对998244353取模。
设答案为
,其中
,输出
,要求
为满足
的最小整数。
输入时,给出数
,
将以数组
的形式给出,详细见样例。
示例1
输入
复制
5,[5,4,3,4,5]
5,[5,4,3,4,5]
返回值
复制
665496238
665496238
说明
答案为8/3,在对998244353取模的情况下是665496238
示例2
输入
复制
6,[6,4,3,4,6,6]
6,[6,4,3,4,6,6]
返回值
复制
3
3
备注:
n<=200000,i<=ai<=n
序列取反问题
返回全部题目
列表加载中...
import java.util.*; public class Solution { /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param n int整型 * @param a int整型一维数组 * @return int整型 */ public int ret (int n, int[] a) { // write code here } }
class Solution { public: /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param n int整型 * @param a int整型vector * @return int整型 */ int ret(int n, vector
& a) { // write code here } };
# # 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 # # # @param n int整型 # @param a int整型一维数组 # @return int整型 # class Solution: def ret(self , n , a ): # write code here
using System; using System.Collections.Generic; class Solution { /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param n int整型 * @param a int整型一维数组 * @return int整型 */ public int ret (int n, List
a) { // write code here } }
/** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param n int整型 * @param a int整型一维数组 * @return int整型 */ function ret( n , a ) { // write code here } module.exports = { ret : ret };
# # 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 # # # @param n int整型 # @param a int整型一维数组 # @return int整型 # class Solution: def ret(self , n , a ): # write code here
package main /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param n int整型 * @param a int整型一维数组 * @return int整型 */ func ret( n int , a []int ) int { // write code here }
/** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param n int整型 * @param a int整型一维数组 * @param aLen int a数组长度 * @return int整型 */ int ret(int n, int* a, int aLen ) { // write code here }
# # 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 # # # @param n int整型 # @param a int整型一维数组 # @return int整型 # class Solution def ret(n, a) # write code here end end
object Solution { /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param n int整型 * @param a int整型一维数组 * @return int整型 */ def ret(n: Int,a: Array[Int]): Int = { // write code here } }
object Solution { /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param n int整型 * @param a int整型一维数组 * @return int整型 */ fun ret(n: Int,a: IntArray): Int { // write code here } }
import java.util.*; public class Solution { /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param n int整型 * @param a int整型一维数组 * @return int整型 */ public int ret (int n, int[] a) { // write code here } }
/** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param n int整型 * @param a int整型一维数组 * @return int整型 */ export function ret(n: number, a: number[]): number { // write code here }
public class Solution { /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param n int整型 * @param a int整型一维数组 * @return int整型 */ func ret ( _ n: Int, _ a: [Int]) -> Int { // write code here } }
struct Solution{ } impl Solution { fn new() -> Self { Solution{} } /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param n int整型 * @param a int整型一维数组 * @return int整型 */ pub fn ret(&self, n: i32, a: Vec
) -> i32 { // write code here } }
5,[5,4,3,4,5]
665496238
6,[6,4,3,4,6,6]
3