链接:https://ac.nowcoder.com/acm/contest/148/A

来源:牛客网

Rikka with Lowbit

时间限制:C/C++ 5秒,其他语言10秒

空间限制:C/C++ 262144K,其他语言524288K

64bit IO Format: %lld

题目描述

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 x & (-x)x&(−x) in the template of BIT. After searching for some literature, Rikka realizes it is the implementation of the function \text{lowbit(x)}lowbit(x).

\text{lowbit}(x)lowbit(x) 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 \text{lowbit}(x)lowbit(x) is equal to 2k-1.

After getting some interesting properties of \text{lowbit}(x)lowbit(x), 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 x-\text{lowbit}(x)x−lowbit(x) or x+\text{lowbit}(x)x+lowbit(x), each with the probability of \frac{1}{2}

2

1



.

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 \sum_{i=L}^R A_i∑

    i=L

    R



    A

    i



    . (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 (w \times 2^{nm}) \mod 998244353(w×2

nm

)mod998244353.

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

示例1

输入

复制

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对数字的期望根本就不会改变,于是就是一个裸的区间查询(用前缀和都可以做)(记得取模)。

细节见代码:

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <vector>
#include <iomanip>
#define ALL(x) (x).begin(), (x).end()
#define rt return
#define dll(x) scanf("%I64d",&x)
#define xll(x) printf("%I64d\n",x)
#define sz(a) int(a.size())
#define all(a) a.begin(), a.end()
#define rep(i,x,n) for(int i=x;i<n;i++)
#define repd(i,x,n) for(int i=x;i<=n;i++)
#define pii pair<int,int>
#define pll pair<long long ,long long>
#define gbtb ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define MS0(X) memset((X), 0, sizeof((X)))
#define MSC0(X) memset((X), '\0', sizeof((X)))
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define eps 1e-6
#define gg(x) getInt(&x)
#define chu(x) cout<<"["<<#x<<" "<<(x)<<"]"<<endl
using namespace std;
typedef long long ll;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
ll powmod(ll a,ll b,ll MOD){ll ans=1;while(b){if(b%2)ans=ans*a%MOD;a=a*a%MOD;b/=2;}return ans;}
inline void getInt(int* p);
const int maxn=100010;
const int inf=0x3f3f3f3f;
/*** TEMPLATE CODE * * STARTS HERE ***/ ll tree[maxn]; ll a[maxn]; int n,m;
int lowbit(int x)
{
return x&(-x);
}
const ll mod=998244353ll;
void add(int id,ll x)
{
while(id<=n)
{
tree[id]=(tree[id]+x)%mod;
id+=lowbit(id);
}
}
ll ask(int id)
{
ll res=0ll;
while(id)
{
res=(res+tree[id])%mod;
id-=lowbit(id);
}
return res;
}
int main()
{
//freopen("D:\\common_text\\code_stream\\in.txt","r",stdin);
//freopen("D:\\common_text\\code_stream\\out.txt","w",stdout);
gbtb;
int t;
cin>>t;
while(t--)
{
MS0(tree);
cin>>n>>m;
repd(i,1,n)
{
cin>>a[i];
add(i,a[i]);
}
ll ans;
int op,l,r;
repd(i,1,m)
{
cin>>op>>l>>r;
if(op==1)
{
continue;
}
ans=(ask(r)-ask(l-1)+mod)%mod;
ans=(ans*powmod(2ll,1ll*n*m,mod))%mod;
cout<<ans<<endl;
}
} return 0;
} inline void getInt(int* p) {
char ch;
do {
ch = getchar();
} while (ch == ' ' || ch == '\n');
if (ch == '-') {
*p = -(getchar() - '0');
while ((ch = getchar()) >= '0' && ch <= '9') {
*p = *p * 10 - ch + '0';
}
}
else {
*p = ch - '0';
while ((ch = getchar()) >= '0' && ch <= '9') {
*p = *p * 10 + ch - '0';
}
}
}

2018牛客网暑期ACM多校训练营(第十场)A Rikka with Lowbit (树状数组)的更多相关文章

  1. 2018牛客网暑期ACM多校训练营(第二场)J Farm(树状数组)

    题意 n*m的农场有若干种不同种类作物,如果作物接受了不同种类的肥料就会枯萎.现在进行t次施肥,每次对一个矩形区域施某种类的肥料.问最后枯萎的作物是多少. 分析 作者:xseventh链接:https ...

  2. 牛客网暑期ACM多校训练营(第二场)J farm (二维树状数组)

    题目链接: https://www.nowcoder.com/acm/contest/140/J 思路: 都写在代码注释里了,非常好懂.. for_each函数可以去看一下,遍历起vector数组比较 ...

  3. 2018牛客网暑期ACM多校训练营(第二场):discount(基环树DP)

    题意:有N个不同的商品,每个商品原价是Pi元,如果选择打折,可以减少Di元.  现在加一种规则,每个商品有一个友好商品Fai,如果i用原价买,则可以免费买Fai. 现在问买到所有物品的最小价格. 思路 ...

  4. 2018牛客网暑期ACM多校训练营(第二场)I- car ( 思维)

    2018牛客网暑期ACM多校训练营(第二场)I- car 链接:https://ac.nowcoder.com/acm/contest/140/I来源:牛客网 时间限制:C/C++ 1秒,其他语言2秒 ...

  5. 2018牛客网暑期ACM多校训练营(第一场)D图同构,J

    链接:https://www.nowcoder.com/acm/contest/139/D来源:牛客网 同构图:假设G=(V,E)和G1=(V1,E1)是两个图,如果存在一个双射m:V→V1,使得对所 ...

  6. 2018 牛客网暑期ACM多校训练营(第一场) E Removal (DP)

    Removal 链接:https://ac.nowcoder.com/acm/contest/139/E来源:牛客网 题目描述 Bobo has a sequence of integers s1, ...

  7. 2018牛客网暑期ACM多校训练营(第一场)B Symmetric Matrix(思维+数列递推)

    题意 给出一个矩阵,矩阵每行的和必须为2,且是一个主对称矩阵.问你大小为n的这样的合法矩阵有多少个. 分析 作者:美食不可负064链接:https://www.nowcoder.com/discuss ...

  8. 2018牛客网暑期ACM多校训练营(第二场) J - farm - [随机数哈希+二维树状数组]

    题目链接:https://www.nowcoder.com/acm/contest/140/J 时间限制:C/C++ 4秒,其他语言8秒 空间限制:C/C++ 262144K,其他语言524288K ...

  9. 牛客网暑期ACM多校训练营(第一场) - J Different Integers(线段数组or莫队)

    链接:https://www.nowcoder.com/acm/contest/139/J来源:牛客网 时间限制:C/C++ 2秒,其他语言4秒 空间限制:C/C++ 524288K,其他语言1048 ...

  10. 2018牛客网暑期ACM多校训练营(第二场) A - run - [DP]

    题目链接:https://www.nowcoder.com/acm/contest/140/A 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 131072K,其他语言262144K ...

随机推荐

  1. DeepFaceLab参数详解之Batch-Size的使用和取值!

    Batch-Size简称BS. 这是一个非常常见的参数,所有模型都具备的一个参数. 这其实是深度学习中的一个基础概念.要说理论可以说出一大堆,大家可以先简单的理解为一次处理的图片张数.为了防止吓跑小白 ...

  2. Ubuntu 16.04下安装sublime Text的插件

    Sublime Text是什么: 它是一款具有代码高亮.语法提示.自动完成且反应快速的编辑器软件,不仅具有华丽的界面,还支持插件扩展机制,用她来写代码,绝对是一种享受.相比于难于上手的Vim,浮肿沉重 ...

  3. React之父子组件之间传值

    1.新增知识点 /** React中的组件: 解决html 标签构建应用的不足. 使用组件的好处:把公共的功能单独抽离成一个文件作为一个组件,哪里里使用哪里引入. 父子组件:组件的相互调用中,我们把调 ...

  4. flask包request搭建微服务(模拟测试桩)

    from flask import Flask,requestimport json app=Flask(__name__)@app.route('/outsideWeb/integration/qr ...

  5. Dart学习笔记-变量常量数据类型

    变量和常量 1.变量的定义 main() { var t_str = 'hello world'; var t_num = 123456; String t_str2 = '你好,我很高兴'; int ...

  6. java.lang.ClassNotFoundException: org.apache.commons.collections.FastHashMap

    七月 26, 2017 1:52:15 上午 org.apache.catalina.core.StandardWrapperValve invoke严重: Servlet.service() for ...

  7. MariaDB 连接查询,视图,事物,索引,外键

    1.连接查询 --创建学生表 create table students ( id int unsigned not null auto_increment primary key, name var ...

  8. SSH整合项目----在线商城

    1.1 网上商城需求分析 1.1.1    前台:用户模块. 注册: * JS非空校验.(不是必须) * Struts2数据校验:在注册Action类同一包下新建UserAction-user_reg ...

  9. shadow使用方法

    cd shadow/resource/examples for d in shadow.data/host/*client*: do grep "transfer-complete" ...

  10. 【HANA系列】SAP UI5上传图片 用XSJS存储在HANA中的方法

    公众号:SAP Technical 本文作者:matinal 原文出处:http://www.cnblogs.com/SAPmatinal/ 原文链接:[HANA系列]SAP UI5上传图片 用XSJ ...