CF1886D
Spouter_27 · · 题解
不要高估 CF 网友的实力。当你想到一个巨麻烦的做法的时候,那就是你假了。
从前往后,每次将数插入排列中。
如果是 > 或 <,那么只能往两端插入,否则必须插到中间去。
所以如果有一个 ?,那么答案乘上它前面插入的数
最后特判一下答案是
#include<bits/stdc++.h>
namespace Spouter_27{
using namespace std;
typedef long long ll;
#define int long long
#define deb(x) cerr<<"Line: "<<__LINE__<<", "<<#x<<" = "<<x<<"; \n"
#define pii pair<ll,ll>
#define mp make_pair
#define fi first
#define se second
const ll N=3e5+10,mod=998244353;
inline ll read(){
ll a=0,x=1;
char c=getchar();
while(!isdigit(c)){
if(c=='-') x=-x;
c=getchar();
}
while(isdigit(c)){
a=a*10+c-'0';
c=getchar();
}
return a*x;
}
ll qpow(ll a,ll b){
ll ans=1,base=a;
while(b){
if(b&1) ans=ans*base%mod;
base=base*base%mod;
b>>=1;
}
return ans;
}
ll n,m,ans=1;
char s[N];
ll calc(){
if(s[2]!='?') return ans;
return 0;
}
signed main(){
n=read(),m=read();
scanf("%s",s+2);
for(int i=3;i<=n;i++){
if(s[i]=='?') (ans*=(i-2))%=mod;
}
printf("%lld\n",calc());
while(m--){
ll x=read()+1;
char c=getchar();
if(x!=2){
if(s[x]=='?') (ans*=qpow(x-2,mod-2))%=mod;
}
s[x]=c;
if(x!=2){
if(s[x]=='?') (ans*=(x-2))%=mod;
}
printf("%lld\n",calc());
}
return 0;
}
}signed main(){return Spouter_27::main();}