日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

2018牛客网暑期ACM多校训练营(第十场)ARikka with Lowbit (树状数组)

發(fā)布時間:2023/12/18 编程问答 27 豆豆
生活随笔 收集整理的這篇文章主要介紹了 2018牛客网暑期ACM多校训练营(第十场)ARikka with Lowbit (树状数组) 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

鏈接:https://ac.nowcoder.com/acm/contest/148/A
來源:牛客網(wǎng)

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 L R, for each index i ∈ [L,R], change Ai to f(Ai).
  • 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
    輸入
    復(fù)制
    1
    3 6
    1 2 3
    1 3 3
    2 1 3
    1 3 3
    2 1 3
    1 1 3
    2 1 3
    輸出
    復(fù)制
    1572864
    1572864
    1572864

    題意:

    思路:

    分析會發(fā)現(xiàn)操作1對數(shù)字的期望根本就不會改變,于是就是一個裸的區(qū)間查詢(用前綴和都可以做)(記得取模)。

    細(xì)節(jié)見代碼:

    #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';}} }

    轉(zhuǎn)載于:https://www.cnblogs.com/qieqiemin/p/11261667.html

    總結(jié)

    以上是生活随笔為你收集整理的2018牛客网暑期ACM多校训练营(第十场)ARikka with Lowbit (树状数组)的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

    如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。

    主站蜘蛛池模板: 精品一区二区免费视频 | a中文在线| 国产1区2区3区4区 | a猛片 | 亚洲三级在线播放 | 国产精品无码一区二区桃花视频 | 免费的黄色网 | 91香蕉嫩草| 操操操爽爽爽 | 欧美精品成人久久 | a∨鲁丝一区鲁丝二区鲁丝三区 | 亚洲av无码国产精品久久不卡 | 亚洲一区二区三区日韩 | 亚洲国产精品久久久久久 | 日本精品视频一区二区三区 | 久久九九久久九九 | 中文字幕无码精品亚洲资源网久久 | 女人叫床高潮娇喘声录音mp3 | 午夜久久剧场 | www.香蕉视频 | 亚洲成人精选 | 午夜福利理论片在线观看 | 成人黄色片免费看 | 无套内谢大学处破女www小说 | 久久激情婷婷 | 伊人亚洲精品 | 久久精品一区二区三区不卡牛牛 | 2019中文字幕在线免费观看 | 一级片免费网址 | 青草一区二区 | 激情在线视频 | 91av一区 | 狠狠插影院 | 成人免费视频视频 | 日韩一区二区三区视频在线观看 | 午夜免费精品 | av秋霞| 激情小说中文字幕 | 国产色无码精品视频国产 | 成年人看的网站 | 亚洲女人初尝黑人巨大 | 亚洲精品国产欧美在线观看 | www.色啪啪.com | 国产精品色在线网站 | 国产在线网址 | 国产毛片av | 成人久久电影 | 制服丝袜影音先锋 | 午夜影院免费体验区 | 欧美a在线观看 | 91成人精品国产刺激国语对白 | 黄网站免费大全入口 | 欧美中日韩在线 | yw视频在线观看 | 性国产精品 | 日本激情电影 | 成人免费av在线 | 韩国激情呻吟揉捏胸视频 | 欧美一级高潮片 | 午夜影视在线观看 | 91看片在线观看 | 久久久国产精华液 | 久久精品一二三区 | 成人性色生活片 | 中文字幕在线观看线人 | 男人插女人免费视频 | 夫妻性生活自拍 | 五月婷婷激情视频 | 免费高清毛片 | 新狠狠干 | 综合色婷婷 | 人人爽爽人人 | 日韩av一区二区三区在线 | 黑白配高清国语在线观看 | 二区三区不卡 | 影音先锋男人天堂 | 欧美日韩六区 | 午夜激情福利电影 | 亚洲a中文字幕 | 最新中文字幕在线观看 | 啪啪网站大全 | 日韩中文字幕2019 | 特一级黄色 | 成人免费视频一区 | 国产成人三级在线播放 | 伊人网综合网 | 欧美日韩一区二区三区不卡 | 久久久精品人妻一区二区三区色秀 | 99在线播放 | 在线看免费av| 美女av一区二区 | 男人操女人逼逼视频 | 影音先锋亚洲成aⅴ人在 | 8090理论片午夜理伦片 | 欧美日韩成人一区 | 日韩精品――色哟哟 | 深夜福利免费在线观看 | 在线不卡中文字幕 | 免费一区视频 |