杭州CCPC Master of GCD

本文介绍了一种使用差分技巧处理区间更新问题的高效算法,并通过一个具体的编程实例展示了如何运用差分思想解决区间操作的问题。文章包括了快速幂运算、最小值计算及最终结果的求解过程。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

差分

#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;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值