当前位置:网站首页>【红旗杯?】补题
【红旗杯?】补题
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));
}
}
}
边栏推荐
- NSIS silent installation vs2013 runtime
- @Resource和@Autowired注解的不同,为什么推荐@Resource?
- What are the benefits of reserving process edges for PCB production? 2021-10-25
- CAN透传云网关CANIOT,CANDTU记录CAN报文远程收发CAN数据
- VSCode很好,但我以后不会再用了
- 2265. number of nodes with statistical value equal to the average value of subtree
- Force deduction 76 questions, minimum covering string
- C#获取exe的版本号-文件版本and程序集版本
- Three Siemens fire-fighting hosts fc18 are equipped with can optical transceiver for optical fiber redundant ring network networking test
- 神经网络与深度学习-3- 机器学习简单示例-PyTorch
猜你喜欢
随机推荐
Atlas conflict Remote Code Execution Vulnerability (cve-2022-26134 vulnerability analysis and protection
Vscode is good, but I won't use it again
Sword finger offer II 027 Palindrome linked list
Find out what informatization is, and let enterprises embark on the right path of transformation and upgrading
Force deduction 76 questions, minimum covering string
产品经理专业知识50篇(四)-从问题到能力提升:AMDGF模型工具
Terms and concepts related to authority and authentication system
Five causes of PCB board deformation and six solutions 2021-10-08
【日常训练】207. 课程表
Invalid Navicat scheduled task
Knowledge sharing 𞓜 conventional laminated structure of six layer PCB
一次弄清楚 Handler 可能导致的内存泄漏和解决办法
Atlassian confluence漏洞分析合集
LeetCode_哈希表_中等_454.四数相加 II
Hisilicon 3559 sample parsing: Vio
Linux上oracle和mysql的启动,关闭,重启
php入门基础记录
ffmpeg+SDL2实现音频播放
VSCode很好,但我以后不会再用了
This article uses pytorch to build Gan model!