本文主要是介绍牛客网暑期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;
}
}
}
}
这篇关于牛客网暑期ACM多校训练营(第十场)A(Rikka with Lowbit)的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!