当前位置:网站首页>[red flag Cup] Supplementary questions
[red flag Cup] Supplementary questions
2022-06-25 08:05:00 【Mfy's little brother 1】
D. Lowbit
Enter an array a, Yes a Array has two operations
1.l,r : [ l , r ] [l,r] [l,r] The interval of a i + = l o w b i t ( a i ) a_i+=lowbit(a_i) ai+=lowbit(ai)
2.l,r : inquiry [l,r] Interval and , modulus 998244353
1 ≤ a i ≤ 998244352 1\leq{a_i}\leq{998244352} 1≤ai≤998244352
Ideas :
a number log n Time lowbit after , Will become 2 To the power of , Later lowbit, It's equivalent to multiplying by 2
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define lson rt<<1,l,mid
#define rson rt<<1|1,mid+1,r
const int maxn=2e5+5;
const ll mod=998244353;
const int N=5e5+5;
int t,n,q,vis[N];
ll tree[N],a[maxn],lz[N];
ll lowbit(ll x){
return x&(-x);
}
void build(int rt,int l,int r){
vis[rt]=tree[rt]=0;lz[rt]=1;
if(l==r){
tree[rt]=a[l];
if(a[l]==lowbit(a[l])){
vis[rt]=1;
}
return ;
}
int mid=(l+r)>>1;
build(lson);
build(rson);
if(vis[rt<<1]&&vis[rt<<1|1])vis[rt]=1;
tree[rt]=(tree[rt<<1]+tree[rt<<1|1])%mod;
}
void pushdown(int rt){
if(lz[rt]<=1)return;
tree[rt<<1]*=lz[rt];
tree[rt<<1]%=mod;
tree[rt<<1|1]*=lz[rt];
tree[rt<<1|1]%=mod;
lz[rt<<1]*=lz[rt];
lz[rt<<1]%=mod;
lz[rt<<1|1]*=lz[rt];
lz[rt<<1|1]%=mod;
lz[rt]=1;
}
void update(int rt,int l,int r,int x,int y){
if(x<=l&&r<=y&&vis[rt]){
tree[rt]*=2;
tree[rt]%=mod;
lz[rt]*=2;
lz[rt]%=mod;
return;
}
if(l==r&&l>=x&&l<=y){
tree[rt]+=lowbit(tree[rt]);
if(tree[rt]==lowbit(tree[rt])){
vis[rt]=1;tree[rt]%=mod;
}
return;
}
int mid=(l+r)>>1;
pushdown(rt);
if(x<=mid)update(lson,x,y);
if(y>mid)update(rson,x,y);
tree[rt]=(tree[rt<<1]+tree[rt<<1|1])%mod;
if(vis[rt<<1]&&vis[rt<<1|1])vis[rt]=1;
}
ll query(int rt,int l,int r,int x,int y){
if(x<=l&&r<=y)return tree[rt];
int mid=(l+r)>>1;
ll ans=0;
pushdown(rt);
if(x<=mid)ans=(ans+query(lson,x,y))%mod;
if(y>mid)ans=(ans+query(rson,x,y))%mod;
return ans;
}
int main(){
scanf("%d",&t);
while(t--){
scanf("%d",&n);
for(int i=1;i<=n;i++){
scanf("%lld",&a[i]);
}
build(1,1,n);
scanf("%d",&q);
while(q--){
int op,l,r;
scanf("%d%d%d",&op,&l,&r);
if(op==1){
update(1,1,n,l,r);
}
else printf("%lld\n",query(1,1,n,l,r));
}
}
}
边栏推荐
- Opencv minimum filtering (not limited to images)
- 不怕百战失利,就怕灰心丧气
- Application of can optical transceiver of ring network redundant can/ optical fiber converter in fire alarm system
- @The difference between resource and @autowired annotation, why recommend @resource?
- FM信号、调制信号和载波
- 取消word文档中某些页面的页眉
- Ubuntu18下登录mysql 5.7设置root密码
- 2265. number of nodes with statistical value equal to the average value of subtree
- Logu P2486 [sdoi2011] coloring (tree chain + segment tree + merging of intervals on the tree)
- Matlab code format one click beautification artifact
猜你喜欢

Force buckle 272 Closest binary search tree value II recursion

电子学:第008课——实验 6:非常简单的开关

静态网页服务器

allgero报错:Program has encountered a problem and must exit. The design will be saved as a .SAV file

DNS协议及其DNS完整的查询过程

CVPR 2022 Oral 2D图像秒变逼真3D物体

Matlab代码格式一键美化神器

挖掘微生物暗物质——新思路

Electronics: Lesson 013 - Experiment 14: Wearable pulsed luminaries

Sword finger offer II 027 Palindrome linked list
随机推荐
电子学:第010课——实验 8:继电振荡器
力扣 272. 最接近的二叉搜索树值 II 递归
Solving some interesting problems with recurrence of function
洛谷P6822 [PA2012]Tax(最短路+边变点)
黑点==白点(MST)
剑指offer刷题(中等等级)
【补题】2021牛客暑期多校训练营6-n
php数组函数大全
將數據導入到MATLAB
数论模板啊
图像超分综述:超长文一网打尽图像超分的前世今生 (附核心代码)
2160. minimum sum of the last four digits after splitting
电子学:第008课——实验 6:非常简单的开关
Black dot = = white dot (MST)
C WinForm panel custom picture and text
【补题】2021牛客暑期多校训练营4-n
2265. number of nodes with statistical value equal to the average value of subtree
Force buckle 272 Closest binary search tree value II recursion
Can bus working condition and signal quality "physical examination"
C # set up FTP server and realize file uploading and downloading