RT,死活过不了 test 3,本来今晚就打的不好,结果全盘皆输了。
//Author:Leftist_G / Shunpower
//Spade Su & Xiao Bao
//Hey Left
//Just enjoy the loneliness
//Open a personal party always stay
#include <bits/stdc++.h>
#define ET return 0
#define fi first
#define se second
#define mp make_pair
#define pb emplace_back
#define ll long long
#define ull unsigned long long
#define inf INT_MAX
#define uinf INT_MIN
#define pii pair<int,int>
#define pll pair<ll,ll>
#define debug puts("--------Chery AK IOI--------");
#define Yes cout<<"Yes"<<endl;
#define No cout<<"No"<<endl;
#define pt puts("")
#define fr1(i,a,b) for(int i=a;i<=b;i++)
#define fr2(i,a,b) for(int i=a;i>=b;i--)
#define fv(i,p) for(int i=0;i<p.size();i++)
#define ld long double
#define il inline
#define ptc putchar
using namespace std;
const int N=3e5+10;
namespace Shun{
int lowbit(int x){
return x&-x;
}
template <typename T>
inline void read(T &x){
T s=0,w=1;
char ch=getchar();
while(ch<'0'||ch>'9'){
if(ch=='-'){
w=-1;
}
ch=getchar();
}
while(ch>='0'&&ch<='9'){
s=s*10+ch-'0';
ch=getchar();
}
x=s*w;
}
template <typename T>
inline void write(T x){
if(x<0){
putchar('-');
x=-x;
}
if(x>9){
write(x/10);
}
putchar(x%10+'0');
}
}
using namespace Shun;
int n,q;
string s;
int l,r;
set <int> geq,leq;
ll fac[N],inv[N];
const ll M=998244353;
ll qpow(ll b,ll p,ll k){
if(!p){
return 1;
}
ll d=qpow(b,p>>1,k);
if(p&1){
return d*d%k*b%k;
}
else{
return d*d%k;
}
}
void init(int n=300000){
fac[0]=1;
fr1(i,1,n){
fac[i]=1ll*fac[i-1]*i%M;
}
inv[n]=qpow(fac[n],M-2,M);
fr2(i,n-1,0){
inv[i]=1ll*inv[i+1]*(i+1)%M;
}
}
ll C(int n,int m){
return fac[n]*inv[m]%M*inv[n-m]%M;
}
struct BIT{
int k[N];
void insert(int p,int x){
while(p<=n){
k[p]+=x;
p+=lowbit(p);
}
}
int query(int p){
int ans=0;
while(p){
ans+=k[p];
p-=lowbit(p);
}
return ans;
}
} T;
void work(){
int per=r-l+1;
if(geq.size()&&leq.size()){
int x=*geq.begin(),y=*leq.begin();
if(min(x,y)!=2){
cout<<"0\n";
return;
}
int len=T.query(max(*geq.begin(),*leq.begin()));
assert(per>=len);
// cout<0<"!"<<len<<endl;
cout<<C(per,len)*fac[per-len]%M<<'\n';
}
else if(geq.size()){
if(*geq.begin()!=2){
cout<<"0\n";
}
else{
cout<<fac[per-1]<<'\n';
}
}
else if(leq.size()){
if(*leq.begin()!=2){
cout<<"0\n";
}
else{
cout<<fac[per-1]<<'\n';
}
}
else{
cout<<"0\n";
}
}
int main(){
#ifdef Griffin
freopen(".in","r",stdin);
freopen(".out","w",stdout);
#endif
init();
cin>>n>>q;
cin>>s;
s='@'+s;
l=1,r=n;
// cout<<inv[2]<<endl;
T.insert(1,1);
fr1(i,1,n-1){
if(s[i]=='>'){
r--;
geq.insert(i+1);
}
else if(s[i]=='<'){
l++;
leq.insert(i+1);
}
else{
T.insert(i+1,1);
}
}
work();
while(q--){
int idx;
char c;
cin>>idx>>c;
if(s[idx]=='<'){
leq.erase(idx+1);
if(c=='?'){
T.insert(idx+1,1);
}
l--;
}
if(s[idx]=='>'){
geq.erase(idx+1);
if(c=='?'){
T.insert(idx+1,1);
}
r++;
}
if(c=='<'){
leq.insert(idx+1);
if(s[idx]=='?'){
T.insert(idx+1,-1);
}
l++;
}
if(c=='>'){
geq.insert(idx+1);
if(s[idx]=='?'){
T.insert(idx+1,-1);
}
r--;
}
s[idx]=c;
// cout<<s<<" "<<l<<" "<<r<<endl;
work();
}
ET;
}
//ETERNAL LOVE FOR Zhang Junhao, Mu Zhicheng and Zuo Hang.
//ALL FOR Zhang Junhao.