每个数最多取log次就会编程10000(2),如果是这种数字的话直接可以打一个标记,我们直接乘2,这样不必每个数都加lowbit
传送门

/** @Author: 0iq_love_zy* @LastEditTime: 2021-06-16 17:55:19* @CSDN blog: https://blog.csdn.net/acm_durante* @E-mail: 1055323152@qq.com* @ProbTitle: */
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define lowbit(x) ((x) & -(x))
const ll mod = 998244353;
ll powmod(ll a, ll b)
{ll res = 1;a %= mod;assert(b >= 0);for (; b; b >>= 1){if (b & 1)res = res * a % mod;a = a * a % mod;}return res;
}
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
template <class T>
inline void read(T &res)
{char c;T flag = 1;while ((c = getchar()) < '0' || c > '9')if (c == '-')flag = -1;res = c - '0';while ((c = getchar()) >= '0' && c <= '9')res = res * 10 + c - '0';res *= flag;
}
const int N = 1e5 + 50;
int n, m;
struct node
{int l, r;ll x, sum;int lazy;int flag;
} tree[N << 2];void push_up(int p)
{tree[p].sum = (tree[p << 1].sum + tree[p << 1 | 1].sum) % mod;tree[p].flag = (tree[p << 1].flag & tree[p << 1 | 1].flag);
}void push_down(int p)
{if (tree[p].lazy == 0)return;tree[p << 1].lazy += tree[p].lazy;tree[p << 1 | 1].lazy += tree[p].lazy;tree[p << 1].sum = (tree[p << 1].sum * powmod(2, tree[p].lazy)) % mod;tree[p << 1 | 1].sum = (tree[p << 1 | 1].sum * powmod(2, tree[p].lazy)) % mod;tree[p].lazy = 0;
}void build_tree(int l, int r, int p)
{tree[p].l = l, tree[p].r = r;tree[p].lazy = tree[p].flag = 0;if (l == r){scanf("%lld", &tree[p].x);tree[p].sum = tree[p].x;if (lowbit(tree[p].x) == tree[p].x)tree[p].flag = 1;return;}int mid = l + r >> 1;build_tree(l, mid, p << 1);build_tree(mid + 1, r, p << 1 | 1);push_up(p);
}void update_tree(int l, int r, int p)
{if (l <= tree[p].l && tree[p].r <= r && tree[p].flag){tree[p].sum = (tree[p].sum * 2) % mod;tree[p].lazy++;return;}if (tree[p].l == tree[p].r){tree[p].x = tree[p].sum = tree[p].sum + lowbit(tree[p].sum);if (lowbit(tree[p].x) == tree[p].x)tree[p].flag = 1;return;}push_down(p);int mid = (tree[p].l + tree[p].r) >> 1;if (l <= mid)update_tree(l, r, p << 1);if (mid < r)update_tree(l, r, p << 1 | 1);push_up(p);
}ll ask_sum(int l, int r, int p)
{if (l <= tree[p].l && tree[p].r <= r){   return tree[p].sum;}ll res = 0;push_down(p);int mid = (tree[p].l + tree[p].r) >> 1;if (l <= mid)res = (res + ask_sum(l, r, p << 1)) % mod;if (mid < r)res = (res + ask_sum(l, r, p << 1 | 1)) % mod;return res;
}
void solve()
{scanf("%d", &n);build_tree(1, n, 1);scanf("%d", &m);int op, l, r;for (int i = 1; i <= m; i++){scanf("%d%d%d", &op, &l, &r);if (op == 1){update_tree(l, r, 1);}else{printf("%lld\n", ask_sum(l, r, 1));}}
}
int main()
{int t;while (~scanf("%d", &t)){while (t--){solve();}}return 0;
}

2021ccpc东北四省D思维线段树相关推荐

  1. P2787 语文1(chin1)- 理理思维(线段树)

    P2787 语文1(chin1)- 理理思维(线段树) 对每个字母开一棵线段树 操作1就是区间查询 操作2就是区间修改 操作3可以看成 先预处理查询出区间对应的每个字母的个数,然后进行区间修改. 然后 ...

  2. 东北四省赛H-Skyscraper-线段树的区间合并优化

    题目描述: At the main street of Byteland, there will be built n skyscrapers, standing sequentially one n ...

  3. duliu——思维+线段树

    题目 [题目描述] 小 `D` 喜欢出毒瘤题毒人.当然,他的毒瘤更多体现在若干个难题组合在同一场比赛时. 小 `D` 脑中有 $n$ 个毒瘤题 idea,第 $i$ 个的毒值为$d_i$.当第 $i$ ...

  4. CodeForces ABBYY Cup 3.0 - Finals B Shave Beaver! (思维+线段树)

    题目链接 题意:给你n个数1~n的序列,随后又q次询问,每次询问有2种操作,操作1:查询从序列中取出数值为x,x+1,...,y-1,y的数的最少需要取多少次(且每取一次只能是一个递增的子序列)    ...

  5. 2021CCPC东北四省赛 D. Lowbit 势能线段树

    传送门 分析 分析一下x+lowbit(x)x + lowbit(x)x+lowbit(x)这个操作 如果多次操作之后,那么xxx中只会有最高位存在一,这个时候再执行一次操作就会使整个数字乘二 所以, ...

  6. AtCoder - arc120_c Swaps 2(思维+线段树+模拟)

    题目链接:点击查看 题目大意:给出一个序列 aaa,问能否经过有限此操作使其变成 bbb,每次操作分为三步: 选择一个 iii,满足 i+1<=ni+1<=ni+1<=n,然后 sw ...

  7. Interesting Array CodeForces - 483D(思维+线段树)

    We'll call an array of n non-negative integers a[1], a[2], -, a[n] interesting, if it meets m constr ...

  8. CodeForces - 1401 F Reverse and Swap(线段树, 区间翻转, 区间交换,清晰易懂)

    CodeForces - 1401 F Reverse and Swap(线段树, 区间翻转, 区间交换)   首先一共有四个操作,第一个和第四个都是线段树的基本操作,直接用线段树实现.      第 ...

  9. 切题 (problem)(线段树+最大流最小割)

    切题 problem description solution code description 在一个神秘的 JOSLFN 上,wzy 和 lqs2015 常年占据着切题榜的 rk1 和 rk2.现 ...

  10. 算法竞赛从入门到进阶pdf_【算法趣谈】线段树 从入门到进阶

        前言:这是一篇笔者两年前所写的博客.如今,在线段树在脑海中即将遗忘之际,这两年前留下的文章,终于将其再次唤醒.这篇文章对于线段树的理解虽谈不上绝对深刻,但是也能详细且简明地解释其流程.因而也收 ...

最新文章

  1. mysql nosql 同步_使用canal和canal_mysql_nosql_sync同步mysql数据
  2. java 8 兼容_甲骨文限制 Java 9 到 Java 8 的向后兼容性
  3. Leetcode每日一题:剑指offer22.lian-biao-zhong-dao-shu-di-kge-jie-dian-lcof(链表中倒数第k个节点)
  4. Bailian3246 展览会【计数+求和】
  5. 大年三十整理的asp.net资料!(不得不收藏)
  6. H5网页实现微信分享,分享朋友圈功能(分享带图片,附源码)
  7. 对于离散行业如何选型MES系统,你知道吗?
  8. 打印没反应/打印耗时长/not accessible
  9. 综合计算增长比例计算机,比如2001-2010这10年GDP年均增长率怎么计算?
  10. 计算机键盘锁不了怎么办,笔记本电脑键盘没反应是哪个键锁了?该怎么办
  11. 通过 TensorFlow 实现 AI 语音降噪提升 QQ 音视频通话质量
  12. 网站选用老域名还是新域名好?
  13. Win10文件夹莫名其妙闪退
  14. 超级简单的 RocketMQ 流量削峰实战
  15. php访问微信云数据库,第三方服务器php获取微信小程序云开发access_token和云数据库...
  16. pwm调速c语言,PWM调速的C语言程序编写
  17. Java“菜单“树递归-合并子树
  18. 21 | 良心中间商:HTTP的代理服务
  19. r语言中残差与回归值的残差图_R语言:多元线性回归和模型检验
  20. 四十三、文件传输协议FTP、电子邮件、万维网

热门文章

  1. 情有独钟,迷情电子三五年(七)
  2. python 探究is_dir函数及其使用案例(读取人脸图片)附整体代码
  3. Oracle特殊符号
  4. linux按行分割文件,按行切割大文件(linux split 命令简版)
  5. 易经六十四卦对照与简单实现卦象操作
  6. “亲爱的程序员,我们不必害怕算法,flutterui库
  7. 第十一周助教工作总结——NWNU李泓毅
  8. git bash粘贴快捷键
  9. VisualStudio Qt开发环境搭建以及Qt moc的讲解
  10. 用iPad开发iPhone App,苹果发布Swift Playgrounds 4