2018牛客多校第十场

#include
#define ll long long
using namespace std;
const int p=998244353;
const int N=2e5+10;
int n,m,T,op,l,r,w,cnt;
struct orz{
    int x,pos,w;
}a[N];
ll fac[N],inv[N];
ll poww(ll x,int y)
{
    x%=p;
    ll ret=1;
    while (y)
    {
        if (y&1) ret=ret*x%p;
        x=x*x%p;
        y>>=1;
    }
    return ret;
}
void pre()
{
    fac[0]=1;
    for (int i=1;i=0;i--) inv[i]=inv[i+1]*(i+1)%p;
}
ll C(int a,int b)
{
    if (b>a||b<0) return 0;
    return fac[a]*inv[b]%p*inv[a-b]%p;
}
ll solve(int x,int y)
{
    ll ret=0;
    for (int i=1;i<=cnt;i++)
    {
        if (a[i].x<=x&&a[i].pos<=y)
            ret=(ret+C(x-a[i].x+y-a[i].pos-1,x-a[i].x-1)*(ll)a[i].w%p)%p;
    }
    return ret;
}
int main()
{
    scanf("%d",&T);
    pre();
    while (T--)
    {
        scanf("%d%d",&n,&m);
        int now=1;
        cnt=0;
        while (m--)
        {
            scanf("%d",&op);
            if (op==1)
            {
                scanf("%d%d%d",&l,&r,&w);
                cnt++; a[cnt].x=now-1; a[cnt].pos=l; a[cnt].w=w%p;
                cnt++; a[cnt].x=now-1; a[cnt].pos=r+1; a[cnt].w=-w%p;
            }
            else if (op==2) now++;
            else
            {
                scanf("%d%d",&l,&r);
                ll ans=((solve(now+1,r)-solve(now+1,l-1))%p+p)%p;
                printf("%lld\n",ans);
            }
        }
    }
    return 0;
}

 

 

你可能感兴趣的:(2018牛客多校第十场)