当前位置:网站首页>【红旗杯?】补题
【红旗杯?】补题
2022-06-25 06:43:00 【mfy的1号小迷弟】
D. Lowbit
输入一个数组a,对a数组有两种操作
1.l,r : [ l , r ] [l,r] [l,r]区间的 a i + = l o w b i t ( a i ) a_i+=lowbit(a_i) ai+=lowbit(ai)
2.l,r :询问[l,r]区间和,取模998244353
1 ≤ a i ≤ 998244352 1\leq{a_i}\leq{998244352} 1≤ai≤998244352
思路:
一个数log n 次lowbit后,会变成2的次方,以后再lowbit,就相当于乘以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));
}
}
}
边栏推荐
- 1464. 数组中两元素的最大乘积
- CAN总线工作状况和信号质量“体检”
- Insert and sort the linked list [dummy unified operation + broken chain core - passive node]
- 1742. 盒子中小球的最大数量
- 1742. maximum number of small balls in the box
- Terms and concepts related to authority and authentication system
- Misunderstanding of switching triode
- WinForm实现窗口始终在顶层
- MySQL简单权限管理
- TCP与UDP
猜你喜欢

使用Adobe Acrobat Pro调整PDF页面为统一大小

This article uses pytorch to build Gan model!

搞清信息化是什么,让企业转型升级走上正确的道路

Anaconda based module installation and precautions

【深度学习 轻量型backbone】2022 EdgeViTs CVPR

环网冗余式CAN/光纤转换器的CAN光端机在消防火灾联网报警系统中的应用

权限、认证系统相关名词概念

SCM Project Training

417-二叉树的层序遍历1(102. 二叉树的层序遍历、107.二叉树的层次遍历 II、199.二叉树的右视图、637.二叉树的层平均值)

ts环境搭建
随机推荐
[Video] ffplay uses MJPEG format to play USB camera
C get the version number of exe - file version and assembly version
用函数的递归来解决几道有趣的题
Vscode is good, but I won't use it again
NPM install reports an error: gyp err! configure error
新版USBCAN卡CAN分析仪的CAN&CANFD综合测试分析软件LKMaster主要功能介绍
机器学习笔记 - 时间序列的线性回归
基于RBAC 的SAAS系统权限设计
Force deduction 76 questions, minimum covering string
一文了解 | 革兰氏阳性和阴性菌区别,致病差异,针对用药
AttributeError: ‘Upsample‘ object has no attribute ‘recompute_ scale_ factor‘
Can bus working condition and signal quality "physical examination"
个人域名和企业域名的区别
Different paths ii[dynamic planning improvement for DFS]
Analysis of kinsing dual platform mining family virus
[single chip microcomputer project training] multipoint temperature wireless acquisition system based on nRF905
Atlassian Confluence 远程代码执行漏洞(CVE-2022-26134漏洞分析与防护
Usememo simulation usecallback
MySQL简单权限管理
Analysis and utilization of Microsoft Office Word remote command execution vulnerability (cve-2022-30190)