Monocarp and the Set(大于小于问号)

题目

题意

给一个数字n,表示一个排列长度为n。
给一个数字m,表示m此操作
给一个字符串s,只包含><?

有一个空集合,最开始往里面加入一个数字。
然后按照字符串s往里加数字,
1.>表示加入的数字比当前集合所有数字大,
2.<表示加入的数字比当前集合所有的数字小,
3.?表示不是最大也不是最小

求每次更改完,插入数字的方案数目

解法

倒着看字符串s,假设此时已经插入了x个数字(包括当前即将被插入的数字),并且当前位置是>,那么,当前被插入的数字选法唯一,如果是?,那么当前数字可以有x-2种选法(不可以选最大和最小)。

代码

#include<bits/stdc++.h>
using namespace std;
const int N=1e6+5;
typedef long long ll;
typedef double db;
ll a[N];
ll n;
const ll mol=998244353;
ll m;
ll qmi(ll a,ll b) {
	ll res=1;
	while(b) {
		if(b&1)
			res=res*a%mol;
		a=a*a%mol;
		b>>=1;
	}
	return res;
}
void solve() {
	cin>>n>>m;
	string s;
	cin>>s;
	ll ans=1;
	for(int i=1; i<s.size(); i++) {
		if(s[i]=='?') {
			ans=ans*i%mol;
		}
	}
	if(s[0]=='?'){
		cout<<0<<endl;
	}
	else
		cout<<ans<<endl;
	while(m--) {
		int pos;
		char ss;
		cin>>pos>>ss;
		pos--;
		if(pos!=0) {
			if(s[pos]=='?'&&ss!='?') {//少一个?
				ans=ans*qmi(pos,mol-2)%mol;
			} else if(s[pos]!='?'&&ss=='?') {//多一个?
				ans=ans*pos%mol;
			}
		}

		s[pos]=ss;
		if(s[0]=='?') {
			cout<<0<<endl;
		} else {
			cout<<ans<<endl;
		}
	}

}

int main() {
	int t=1;
//	cin>>t;
	while(t--)
		solve();
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值