牛客网暑期ACM多校训练营(第十场)A(Rikka with Lowbit)


题目描述

Today, Rikka is going to learn how to use BIT to solve some simple data structure tasks. While studying, She finds there is a magic expression in the template of BIT. After searching for some literature, Rikka realizes it is the implementation of the function .

is defined on all positive integers. Let a1...am be the binary representation of x while a1 is the least significant digit, k be the smallest index which satisfies ak = 1. The value of is equal to 2k-1.

After getting some interesting properties of , Rikka sets a simple data structure task for you:

At first, Rikka defines an operator f(x), it takes a non-negative integer x. If x is equal to 0, it will return 0. Otherwise it will return or , each with the probability of .

Then, Rikka shows a positive integer array A of length n, and she makes m operations on it.

There are two types of operations:
1. 1 L R, for each index i ∈ [L,R], change Ai to f(Ai).
2. 2 L R, query for the expectation value of . (You may assume that each time Rikka calls f, the random variable used by f is independent with others.)

输入描述:

The first line contains a single integer t(1 ≤ t ≤ 3), the number of the testcases.

The first line of each testcase contains two integers n,m(1 ≤ n,m ≤ 105). The second line contains n integers Ai(1 ≤ Ai ≤ 108). 

And then m lines follow, each line contains three integers t,L,R(t ∈ {1,2}, 1 ≤ L ≤ R ≤ n).

输出描述:

For each query, let w be the expectation value of the interval sum, you need to output . 

It is easy to find that w x 2nm must be an integer.

输入

1
3 6
1 2 3
1 3 3
2 1 3
1 3 3
2 1 3
1 1 3
2 1 3

输出

1572864
1572864
1572864

题意:(签到题)给出一个数组,两种操作。

1,修改一个区间的数,如果a[i]=0,a[i]=0。否则有1/2几率变为a[i]+lowbit(a[i]),有1/2几率变为a[i]-lowbit(a[i])。

2,求区间期望和。

思路:因为是求期望所以每一个点上的数期望为(1/2)*(x+lowbit(x))+(1/2)*(x-lowbit(x))=x,期望相当于没变,那么题意也就转化成了只求最初的数组区间和了。(水题)

代码:

#include<bits/stdc++.h>
#define PI acos(-1)
#define ll long long
#define inf 0x3f3f3f3f
#define ull unsigned long long
using namespace std;
const ll mod=998244353;
ll sum[100005];
long long qpow(long long a,long long b)
{
    a=a%mod;
    long long ans=1;
    while(b)
    {
        if(b&1)
        {
            ans=(ans*a)%mod;
            b--;
        }
        b>>=1;
        a=a*a%mod;
    }
    return ans;
}
int main()
{
    int T;
    ll n,m;
    scanf("%d",&T);
    while(T--)
    {
        scanf("%lld%lld",&n,&m);
        sum[0]=0;
        for(int i=1;i<=n;i++)
        {
            ll x;
            scanf("%lld",&x);
            sum[i]=(sum[i-1]+x)%mod;
        }
        ll op,l,r;
        int y=m;
        while(y--)
        {
            scanf("%lld%lld%lld",&op,&l,&r);
            if(op==1) continue;
            else if(op==2)
            {
                ll ans=(sum[r]-sum[l-1])%mod;
                ans=ans*qpow(2,n*m)%mod;
                cout<<(ans+mod)%mod<<endl;
            }
        }
    }
}

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值