当前位置:网站首页>[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));
}
}
}
边栏推荐
猜你喜欢

Sword finger offer II 027 Palindrome linked list

C examples of using colordialog to change text color and fontdialog to change text font

Anaconda based module installation and precautions

Basic use of ActiveMQ in Message Oriented Middleware

Modeling and fault simulation of aircraft bleed system

时钟刻度盘的绘制

剑指offer刷题(中等等级)

CAN透传云网关CANIOT,CANDTU记录CAN报文远程收发CAN数据

Debugging mipi-dsi screen based on stm32mp157

网络模型——OSI模型与TCP/IP模型
随机推荐
共话云原生数据库的未来
数论模板啊
Pycharm的奇葩设定:取消注释后立马复制会带上#
电子学:第012课——实验 11:光和声
c#磁盘驱动器及文件夹还有文件类的操作
[deep learning lightweight backbone] 2022 edgevits CVPR
电子学:第009课——实验 7:研究继电器
Ph中和过程建模
50 pieces of professional knowledge of Product Manager (IV) - from problem to ability improvement: amdgf model tool
RMQ interval maximum subscript query, interval maximum
电子学:第011课——实验 10:晶体管开关
【补题】2021牛客暑期多校训练营4-n
Debugging mipi-dsi screen based on stm32mp157
初体验完全托管型图数据库 Amazon Neptune
Mining microbial dark matter -- a new idea
socket问题记录
Matlab code format one click beautification artifact
[daily training] 207 Class Schedule Card
【红旗杯?】补题
洛谷P3313 [SDOI2014]旅行(树链+边权转点权)