E. Side Transmutations
Http://codeforces.com/contest/1065/problem/E
Test instructions
A string of length n, the character set is a, and how many different strings are asked. Two strings are the same:
- In the given array B, find a number b[i], set k=b[i]
- 1~k, flips the string with n-k+1~n, and then swaps the position. The newly formed string is equal to the original string.
Analysis:
Consider only one b[i] effect, then for a string, divided into three paragraphs, the front K, the back K, the middle. The middle part is $a^{n-k-k}$, and then look at how many kinds of strings are formed on both sides, making these all different.
Left K and right K all the strings, 22 combinations, plus the middle part, form a string. The string is then equal to the string after the operation, so they should be counted only once, so the line is divided by 2. However, after some string manipulation, like the original, these will not form an equivalent string, so do not need to divide by 2, counted once.
Left K total scheme number $a^{k}$, on both sides 22 combination $a^{k+k}$. After the operation of the same string as the original $a^{k}$, indicating the left K randomly selected, the right of the k is the left inverted. Then the first part is $\frac{a^{k+k}-a^{k}}{2}$, plus the second part of $a^{k}$, merged $\frac{a^{k} \times (A^{k} + 1)}{2}$.
Then consider increasing the impact of a B, then the middle part, can not be selected on the previous, for $a^{n-k-k}$, so first of all, regardless of the middle, only consider the two sides. Because B[i] adds B[i+1]-b[i] characters to both sides of the next event. Then this b[i] is combined in the way above, there will be some new strings formed. Then multiply these and finally multiply the middle part. It's $a^{n-b[m]-b[m]}$.
Code:
1#include <cstdio>2#include <algorithm>3#include <cstring>4#include <cmath>5#include <iostream>6#include <cctype>7#include <Set>8#include <vector>9#include <queue>Ten#include <map> One #defineFi (s) freopen (S, "R", stdin); A #defineFo (s) freopen (S, "w", stdout); - using namespacestd; -typedefLong LongLL; the -InlineintRead () { - intx=0, f=1;CharCh=getchar (); for(;! IsDigit (CH); Ch=getchar ())if(ch=='-') f=-1; - for(; isdigit (ch); Ch=getchar ()) x=x*Ten+ch-'0';returnx*F; + } - + Const intN =200005; A ConstLL mod =998244353; at - ll KSM (ll A, ll b) { -LL res =1; - while(b) { - if(B &1) Res = res * A%MoD; -A = a * a%MoD; inb >>=1; - } to returnRes; + } - the LL B[n]; * $ intMain () {Panax Notoginseng intn = Read (), M =read (); -LL A =read (); the for(intI=1; i<=m; ++i) B[i] =read (); +LL ans =1, Inv2 = KSM (2, MoD-2); A for(intI=1; i<=m; ++i) { theLL L = b[i]-b[i-1]; +LL tmp =KSM (A, L); -Ans = ans * tmp% mod * (tmp +1) %MoD; $Ans = ans * inv2%MoD; $ } -Ans = ans * KSM (A, N-b[m]-b[m])%MoD; -cout <<ans; the return 0; -}
CF 1065 E. Side transmutations