杭州CCPC Master of GCD

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/Pandauncle/article/details/79964265

差分

#include<bits/stdc++.h>
using namespace std;
typedef long long int LL;
const int N=100000+10;
#define Mod 998244353
#define INF 1<<31-1
LL c2[N],c3[N];
LL ans2[N],ans3[N];
LL quick_power(LL a,LL b)
{
    LL ans=1;
    a = a%Mod;
    while(b>0)
    {
        if(b%2 == 1)
        ans =ans*a%Mod;
        b =b/2;
        a =a*a% Mod;
    }
    return ans%Mod;
}
LL min1(LL a,LL b)
{
    if(a>b)
        return b;
    else
        return a;
}
int main()
{
    int t;
    scanf("%d",&t);
    while(t--)
    {
        LL n,m;
        scanf("%lld%lld",&n,&m);
        for(int i=1;i<=n+9;i++)
        {
            c2[i]=0;
            c3[i]=0;
            ans2[i]=0;
            ans3[i]=0;
        }
        LL l,r,q;
        for(int i=1;i<=m;i++)
        {
            scanf("%lld%lld%lld",&l,&r,&q);
            if(q==2)
            {
                c2[l]++;
                c2[r+1]--;
            }
            else
            {
                c3[l]++;
                c3[r+1]--;
            }
        }
        for(int i=1;i<=n;i++)
        {
            ans2[i]=ans2[i-1]+c2[i];
            ans3[i]=ans3[i-1]+c3[i];
        }
      /*  for(int i=1;i<=n;i++)
        {
            printf("%d ",ans2[i]);
        }
        cout<<endl;
        for(int i=1;i<=n;i++)
        {
            printf("%d ",ans3[i]);
        }
        cout<<endl;*/
        LL x=0,y=0,mi2=INF,mi3=INF;
        for(int i=1;i<=n;i++)
        {
            mi2=min(mi2,ans2[i]);
            mi3=min(mi3,ans3[i]);
        }
       // printf("%d\n",x);
        LL sum=((quick_power(2,mi2)%Mod)*(quick_power(3,mi3)%Mod))%Mod;
        printf("%lld\n",sum);
    }
    return 0;
}
阅读更多
想对作者说点什么?

博主推荐

换一批

没有更多推荐了,返回首页