# 正题

## 题目大意

k k 级偏值定义为它所有子串的 k − 1 k-1 级偏值的和。

r-3r-2r-1rr+1
11100
12333
136912

## c o d e code

#include<cstdio>
#include<cstring>
#include<algorithm>
#include<stack>
#define ll long long
using namespace std;
const ll N=2e6+10,XJQ=998244353;
ll n,k,ans,fac[N],inv[N];
char s[N];stack<int> S;
ll power(ll x,ll b){
ll ans=1;
while(b){
if(b&1)ans=ans*x%XJQ;
x=x*x%XJQ;b>>=1;
}
return ans;
}
ll G(ll n,ll m){
if(n<=0||m<0)return 0;
n=n+m-1;return fac[n]*inv[m]%XJQ*inv[n-m]%XJQ;
}
ll solve(ll l,ll r,bool op){
ll ans=1;
if(op)l=n-l+1,r=n-r+1,swap(l,r);
ans=(G(r,k)-G(l-1,k)+XJQ)%XJQ;
return ans;
}
int main()
{
scanf("%lld%lld",&n,&k);
ll lim=max(n,k);fac[0]=inv[0]=1;
for(ll i=1;i<=2*lim;i++){
fac[i]=fac[i-1]*i%XJQ;
inv[i]=power(fac[i],XJQ-2);
}
scanf("%s",s+1);
for(ll i=1;i<=n;i++){
if(s[i]=='(')S.push(i);
else{
if(!S.empty()){
ans=(ans+solve(1,S.top(),0)*solve(S.top(),i-1,1)%XJQ)%XJQ;
S.pop();
}
else ans=(ans+solve(1,i,0)*solve(i,n,1)%XJQ)%XJQ;
}
}
while(!S.empty())S.pop();
for(ll i=n;i>=1;i--){
if(s[i]==')')S.push(i);
else{
if(!S.empty()){
ans=(ans+solve(S.top(),n,1)*solve(i+1,S.top(),0)%XJQ)%XJQ;
S.pop();
}
else ans=(ans+solve(1,i,0)*solve(i,n,1)%XJQ)%XJQ;
}
}
printf("%lld",ans);
}

09-04 1万+

05-10 4704
04-16 3110
10-04 995
04-17 1292